Skip to content

Commit

Permalink
Merge pull request #4 from peter-gribanov/build
Browse files Browse the repository at this point in the history
Correct test build with Travic CI
  • Loading branch information
peter-gribanov committed Aug 15, 2019
2 parents 2948de0 + 8b82abd commit 210262c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 107 deletions.
21 changes: 10 additions & 11 deletions .travis.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/GpsLabDomainEventExtension.php
Expand Up @@ -20,7 +20,7 @@
class GpsLabDomainEventExtension extends Extension
{
/**
* @param array $configs
* @param array $configs
* @param ContainerBuilder $container
*/
public function load(array $configs, ContainerBuilder $container)
Expand Down
1 change: 0 additions & 1 deletion src/GpsLabDomainEventBundle.php
Expand Up @@ -21,7 +21,6 @@ class GpsLabDomainEventBundle extends Bundle
*/
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new EventListenerPass());
}

Expand Down
4 changes: 4 additions & 0 deletions tests/DependencyInjection/Compiler/EventListenerPassTest.php
Expand Up @@ -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 [
Expand Down
103 changes: 23 additions & 80 deletions tests/DependencyInjection/GpsLabDomainEventExtensionTest.php
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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()
Expand Down
26 changes: 12 additions & 14 deletions tests/GpsLabDomainEventBundleTest.php
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 210262c

Please sign in to comment.