diff --git a/.travis.yml b/.travis.yml index f837dac..eb7a842 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,41 +12,40 @@ branches: matrix: fast_finish: true include: + - php: 7.3 - php: 7.2 - php: 7.1 - php: 7.0 - php: 5.6 - php: 5.5 + dist: trusty - php: 5.5 - env: SYMFONY_VERSION=2.7.* - - php: 5.5 + dist: trusty env: SYMFONY_VERSION=2.8.* - php: 5.5 + dist: trusty env: SYMFONY_VERSION=3.4.* - php: 7.1 - env: SYMFONY_VERSION=4.1.* PHPUNIT_VERSION=5.7.* + env: SYMFONY_VERSION=4.2.* PHPUNIT_VERSION=5.7.* + - php: 7.1 + env: SYMFONY_VERSION=4.3.* PHPUNIT_VERSION=5.7.* - php: 5.5 + dist: trusty env: DOCTRINE_VERSION=2.4.* - php: 5.5 + dist: trusty env: DOCTRINE_VERSION=2.5.* - php: 7.2 env: DOCTRINE_VERSION=2.6.* - - php: hhvm - sudo: required - dist: trusty - group: edge - allow_failures: - - php: hhvm before_install: - - if [ "$TRAVIS_PHP_VERSION" = "hhvm" ]; then echo 'xdebug.enable = on' >> /etc/hhvm/php.ini; fi - if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com ${GH_TOKEN}; fi; before_script: - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --dev --no-update; fi; - if [ "$DOCTRINE_VERSION" != "" ]; then composer require "doctrine/orm:${DOCTRINE_VERSION}" --dev --no-update; fi; - if [ "$PHPUNIT_VERSION" != "" ]; then composer require "phpunit/phpunit:${PHPUNIT_VERSION}" --dev --no-update; fi; - - composer install --prefer-dist --no-interaction --no-scripts --no-progress + - COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-dist --no-interaction --no-scripts --no-progress script: - vendor/bin/phpunit --coverage-clover build/coverage-clover.xml diff --git a/src/DependencyInjection/GpsLabDomainEventExtension.php b/src/DependencyInjection/GpsLabDomainEventExtension.php index ab9a527..a6d4f82 100644 --- a/src/DependencyInjection/GpsLabDomainEventExtension.php +++ b/src/DependencyInjection/GpsLabDomainEventExtension.php @@ -20,7 +20,7 @@ class GpsLabDomainEventExtension extends Extension { /** - * @param array $configs + * @param array $configs * @param ContainerBuilder $container */ public function load(array $configs, ContainerBuilder $container) diff --git a/src/GpsLabDomainEventBundle.php b/src/GpsLabDomainEventBundle.php index d5946c2..13f98c6 100644 --- a/src/GpsLabDomainEventBundle.php +++ b/src/GpsLabDomainEventBundle.php @@ -21,7 +21,6 @@ class GpsLabDomainEventBundle extends Bundle */ public function build(ContainerBuilder $container) { - parent::build($container); $container->addCompilerPass(new EventListenerPass()); } diff --git a/tests/DependencyInjection/Compiler/EventListenerPassTest.php b/tests/DependencyInjection/Compiler/EventListenerPassTest.php index 1e86c90..6364aa7 100644 --- a/tests/DependencyInjection/Compiler/EventListenerPassTest.php +++ b/tests/DependencyInjection/Compiler/EventListenerPassTest.php @@ -104,6 +104,10 @@ public function testProcessCustomLocator() */ public function locators() { + if (PHP_VERSION_ID >= 70000) { + $this->markTestSkipped(sprintf('Impossible to mock "%s" on PHP 7', Definition::class)); + } + $locator = $this->getMock(Definition::class); return [ diff --git a/tests/DependencyInjection/GpsLabDomainEventExtensionTest.php b/tests/DependencyInjection/GpsLabDomainEventExtensionTest.php index 1fd94f7..34f3892 100644 --- a/tests/DependencyInjection/GpsLabDomainEventExtensionTest.php +++ b/tests/DependencyInjection/GpsLabDomainEventExtensionTest.php @@ -14,36 +14,24 @@ use GpsLab\Domain\Event\Bus\EventBus; use GpsLab\Domain\Event\Listener\Subscriber; use GpsLab\Domain\Event\Queue\EventQueue; -use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Definition; class GpsLabDomainEventExtensionTest extends \PHPUnit_Framework_TestCase { - /** - * @var \PHPUnit_Framework_MockObject_MockObject|ContainerBuilder - */ - private $container; - /** * @var GpsLabDomainEventExtension */ private $extension; - const CONTAINER_OFFSET = 13; + /** + * @var ContainerBuilder + */ + private $container; protected function setUp() { - if (PHP_VERSION_ID >= 70000) { - $this->markTestSkipped(sprintf('Impossible to mock "%s" on PHP 7', ContainerBuilder::class)); - } - - $this->container = $this - ->getMockBuilder(ContainerBuilder::class) - ->disableOriginalConstructor() - ->getMock() - ; $this->extension = new GpsLabDomainEventExtension(); + $this->container = new ContainerBuilder(); } /** @@ -115,73 +103,28 @@ public function config() */ public function testLoad(array $config, $bus, $queue, $locator, $publish_on_flush) { - $publisher = $this->getMock(Definition::class); - $publisher - ->expects($this->once()) - ->method('replaceArgument') - ->with(2, $publish_on_flush) - ; + $this->extension->load($config, $this->container); - $this->container - ->expects($this->at(self::CONTAINER_OFFSET)) - ->method('setAlias') - ->with('domain_event.bus', $bus) - ; - $this->container - ->expects($this->at(self::CONTAINER_OFFSET + 1)) - ->method('setAlias') - ->with('domain_event.queue', $queue) - ; - $this->container - ->expects($this->at(self::CONTAINER_OFFSET + 2)) - ->method('setAlias') - ->with('domain_event.locator', $locator) - ; - $this->container - ->expects($this->at(self::CONTAINER_OFFSET + 3)) - ->method('setAlias') - ->with(EventBus::class, $bus) - ; - $this->container - ->expects($this->at(self::CONTAINER_OFFSET + 4)) - ->method('setAlias') - ->with(EventQueue::class, $queue) - ; - $this->container - ->expects($this->at(self::CONTAINER_OFFSET + 5)) - ->method('getDefinition') - ->with('domain_event.publisher') - ->will($this->returnValue($publisher)) - ; + $this->assertEquals($bus, $this->container->getAlias('domain_event.bus')); + $this->assertEquals($queue, $this->container->getAlias('domain_event.queue')); + $this->assertEquals($locator, $this->container->getAlias('domain_event.locator')); + $this->assertEquals($bus, $this->container->getAlias(EventBus::class)); + $this->assertEquals($queue, $this->container->getAlias(EventQueue::class)); - if (method_exists($this->container, 'registerForAutoconfiguration')) { - $child = $this - ->getMockBuilder(ChildDefinition::class) - ->disableOriginalConstructor() - ->getMock() - ; - $child - ->expects($this->once()) - ->method('addTag') - ->with('domain_event.subscriber') - ->will($this->returnSelf()) - ; - $child - ->expects($this->once()) - ->method('setAutowired') - ->with(true) - ->will($this->returnSelf()) - ; + $publisher = $this->container->getDefinition('domain_event.publisher'); + $this->assertEquals($publish_on_flush, $publisher->getArgument(2)); - $this->container - ->expects($this->at(self::CONTAINER_OFFSET + 6)) - ->method('registerForAutoconfiguration') - ->with(Subscriber::class) - ->will($this->returnValue($child)) - ; + if (method_exists($this->container, 'registerForAutoconfiguration')) { + $has_subscriber = false; + foreach ($this->container->getAutoconfiguredInstanceof() as $key => $definition) { + if ($key === Subscriber::class) { + $has_subscriber = true; + $this->assertTrue($definition->hasTag('domain_event.subscriber')); + $this->assertTrue($definition->isAutowired()); + } + } + $this->assertTrue($has_subscriber); } - - $this->extension->load($config, $this->container); } public function testAlias() diff --git a/tests/GpsLabDomainEventBundleTest.php b/tests/GpsLabDomainEventBundleTest.php index cd007c8..5547bc1 100644 --- a/tests/GpsLabDomainEventBundleTest.php +++ b/tests/GpsLabDomainEventBundleTest.php @@ -22,9 +22,15 @@ class GpsLabDomainEventBundleTest extends \PHPUnit_Framework_TestCase */ private $bundle; + /** + * @var ContainerBuilder + */ + private $container; + protected function setUp() { $this->bundle = new GpsLabDomainEventBundle(); + $this->container = new ContainerBuilder(); } public function testCorrectBundle() @@ -34,21 +40,13 @@ public function testCorrectBundle() public function testBuild() { - if (PHP_VERSION_ID >= 70000) { - $this->markTestSkipped(sprintf('Impossible to mock "%s" on PHP 7', ContainerBuilder::class)); - } + $this->bundle->build($this->container); - /* @var $container \PHPUnit_Framework_MockObject_MockObject|ContainerBuilder */ - $container = $this - ->getMockBuilder(ContainerBuilder::class) - ->disableOriginalConstructor() - ->getMock(); - $container - ->expects($this->once()) - ->method('addCompilerPass') - ->with($this->isInstanceOf(EventListenerPass::class)); - - $this->bundle->build($container); + $has_event_listener_pass = false; + foreach ($this->container->getCompiler()->getPassConfig()->getBeforeOptimizationPasses() as $pass) { + $has_event_listener_pass = $pass instanceof EventListenerPass ?: $has_event_listener_pass; + } + $this->assertTrue($has_event_listener_pass); } public function testContainerExtension()