Skip to content

Commit

Permalink
Merge pull request #91 from JayBizzle/develop
Browse files Browse the repository at this point in the history
Add coveralls.io
  • Loading branch information
JayBizzle committed Apr 25, 2016
2 parents f929c49 + 9869829 commit 5fcb280
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage_clover: tests/logs/clover.xml
json_path: tests/logs/coveralls-upload.json
service_name: travis-ci
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ before_script:
- travis_retry composer self-update
- travis_retry composer install --prefer-source --no-interaction --dev

script: phpunit
before_install:
- composer require phpunit/phpunit:4.8.* satooshi/php-coveralls:1.*
- composer install --dev

script:
- ./vendor/bin/phpunit --coverage-clover ./tests/logs/clover.xml

after_script:
- php vendor/bin/coveralls -v
2 changes: 1 addition & 1 deletion src/CrawlerDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function isCrawler($userAgent = null)

$agent = preg_replace('/'.$this->getExclusions().'/i', '', $agent);

if (trim($agent) === false) {
if (strlen(trim($agent)) == 0) {
return false;
} else {
$result = preg_match('/'.$this->getRegex().'/i', trim($agent), $matches);
Expand Down
16 changes: 16 additions & 0 deletions tests/UATests.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ public function testReturnsCorrectMatchedBotName()
$this->assertEquals($this->CrawlerDetect->getMatches(), 'Yahoo Ad monitoring', $matches);
}

public function testEmptyUserAgent()
{
$test = $this->CrawlerDetect->isCrawler(' ');

$this->assertEquals($test, false);
}

public function testCurrentVisitor()
{
$headers = (array) json_decode('{"DOCUMENT_ROOT":"\/home\/test\/public_html","GATEWAY_INTERFACE":"CGI\/1.1","HTTP_ACCEPT":"*\/*","HTTP_ACCEPT_ENCODING":"gzip, deflate","HTTP_CACHE_CONTROL":"no-cache","HTTP_CONNECTION":"Keep-Alive","HTTP_FROM":"bingbot(at)microsoft.com","HTTP_HOST":"www.test.com","HTTP_PRAGMA":"no-cache","HTTP_USER_AGENT":"Mozilla\/5.0 (compatible; bingbot\/2.0; +http:\/\/www.bing.com\/bingbot.htm)","PATH":"\/bin:\/usr\/bin","QUERY_STRING":"order=closingDate","REDIRECT_STATUS":"200","REMOTE_ADDR":"127.0.0.1","REMOTE_PORT":"3360","REQUEST_METHOD":"GET","REQUEST_URI":"\/?test=testing","SCRIPT_FILENAME":"\/home\/test\/public_html\/index.php","SCRIPT_NAME":"\/index.php","SERVER_ADDR":"127.0.0.1","SERVER_ADMIN":"webmaster@test.com","SERVER_NAME":"www.test.com","SERVER_PORT":"80","SERVER_PROTOCOL":"HTTP\/1.1","SERVER_SIGNATURE":"","SERVER_SOFTWARE":"Apache","UNIQUE_ID":"Vx6MENRxerBUSDEQgFLAAAAAS","PHP_SELF":"\/index.php","REQUEST_TIME_FLOAT":1461619728.0705,"REQUEST_TIME":1461619728}');

$cd = new CrawlerDetect($headers);

$this->assertEquals($cd->isCrawler(), true);
}

public function testForRegexCollision()
{
$crawlers = new Crawlers();
Expand Down

0 comments on commit 5fcb280

Please sign in to comment.