-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from lennerd/symfony-4
Fix Travis setup and add tests for Symfony 4
- Loading branch information
Showing
15 changed files
with
2,399 additions
and
808 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,39 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5.9 | ||
- 5.6 | ||
- hhvm | ||
- 7 | ||
- 7.1 | ||
- 7.2 | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
|
||
matrix: | ||
allow_failures: | ||
- php: 7 | ||
fast_finish: true | ||
include: | ||
- php: 5.6 | ||
env: DEPENDENCIES="symfony/lts:^2" | ||
- php: 7.1 | ||
env: DEPENDENCIES="symfony/lts:^3" | ||
- php: 7.2 | ||
env: DEPENDENCIES="symfony/lts:^3" | ||
|
||
before_install: | ||
- echo "memory_limit=4G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini | ||
- if [ "$DEPENDENCIES" != "" ]; then composer require --no-update $DEPENDENCIES; fi; | ||
|
||
before_script: | ||
- wget http://getcomposer.org/composer.phar | ||
- php composer.phar install --dev --prefer-source --no-interaction | ||
install: | ||
# Install dependencies | ||
- composer update --prefer-dist --no-interaction | ||
# Install Coveralls | ||
- wget -c -nc --retry-connrefused --tries=0 https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar | ||
- chmod +x coveralls.phar | ||
- php coveralls.phar --version | ||
|
||
script: | ||
- mkdir -p build/logs | ||
- phpunit --coverage-clover build/logs/clover.xml | ||
|
||
after_script: php vendor/bin/coveralls -v | ||
- php vendor/bin/phpunit --coverage-clover build/logs/clover.xml | ||
|
||
notifications: | ||
email: | ||
- [email protected] | ||
after_success: | ||
- travis_retry php vendor/bin/php-coveralls -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the VipxBotDetectBundle package. | ||
* | ||
* (c) Lennart Hildebrandt <http://github.com/lennerd> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Vipx\BotDetectBundle\Tests; | ||
|
||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Vipx\BotDetect\Metadata\Metadata; | ||
use Vipx\BotDetect\Metadata\MetadataCollection; | ||
use Vipx\BotDetect\Metadata\MetadataInterface; | ||
use Vipx\BotDetectBundle\BotDetector; | ||
|
||
class BotDetectorTest extends TestCase | ||
{ | ||
private $loader; | ||
private $metadataCollection; | ||
|
||
public function testDetectBotFromRequest() | ||
{ | ||
$request = new Request(array(), array(), array(), array(), array(), array( | ||
'HTTP_USER_AGENT' => 'Googlebot', | ||
'REMOTE_ADDR' => '127.0.0.1', | ||
)); | ||
|
||
$detector = $this->createDetector(); | ||
|
||
$this->assertInstanceOf( | ||
MetadataInterface::class, | ||
$detector->detectFromRequest($request) | ||
); | ||
} | ||
|
||
private function createDetector() | ||
{ | ||
return new BotDetector($this->getLoader(), '/my/vipx/bot/file.yml'); | ||
} | ||
|
||
private function getLoader() | ||
{ | ||
if (null === $this->loader) { | ||
/** @var LoaderInterface|MockObject $loader */ | ||
$loader = $this->getMockBuilder(LoaderInterface::class) | ||
->getMock(); | ||
|
||
$loader->expects($this->any()) | ||
->method('load') | ||
->will($this->returnValue($this->getMetadataCollection())); | ||
|
||
$this->loader = $loader; | ||
} | ||
|
||
return $this->loader; | ||
} | ||
|
||
private function getMetadataCollection() | ||
{ | ||
if (null === $this->metadataCollection) { | ||
$googleBot = new Metadata('Googlebot', 'Googlebot', '127.0.0.1'); | ||
|
||
$metadatas = array( | ||
$googleBot, | ||
); | ||
|
||
$this->metadataCollection = $this->getMockBuilder(MetadataCollection::class) | ||
->getMock(); | ||
|
||
$this->metadataCollection->expects($this->any()) | ||
->method('getIterator') | ||
->will($this->returnCallback(function() use ($metadatas) { | ||
return new \ArrayIterator($metadatas); | ||
})); | ||
|
||
$this->metadataCollection->expects($this->any()) | ||
->method('getMetadatas') | ||
->willReturn($metadatas); | ||
} | ||
|
||
return $this->metadataCollection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the VipxBotDetectBundle package. | ||
* | ||
* (c) Lennart Hildebrandt <http://github.com/lennerd> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Vipx\BotDetectBundle\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Vipx\BotDetectBundle\DependencyInjection\Compiler\MetadataResolverPass; | ||
use Vipx\BotDetectBundle\VipxBotDetectBundle; | ||
|
||
class VipxBotDetectBundleTest extends TestCase | ||
{ | ||
public function testContainerHasCompilerPass() | ||
{ | ||
$bundle = new VipxBotDetectBundle(); | ||
$container = new ContainerBuilder(); | ||
|
||
$bundle->build($container); | ||
$passes = $container->getCompiler()->getPassConfig()->getBeforeOptimizationPasses(); | ||
|
||
$passAdded = false; | ||
foreach ($passes as $pass) { | ||
if ($pass instanceof MetadataResolverPass) { | ||
$passAdded = true; | ||
} | ||
} | ||
|
||
$this->assertTrue($passAdded, 'Resolver pass has not been added.'); | ||
} | ||
} |
Oops, something went wrong.