Skip to content

Commit

Permalink
Added workaround for undefined services of symfony3 (#145)
Browse files Browse the repository at this point in the history
Brought phpunit in dev dependencies to solve compatibility issues with travis

Added symfony also for the prefer-lowest step
  • Loading branch information
thanosp authored and kbond committed May 5, 2017
1 parent f57d1cf commit 255f7a5
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/Tests/app/cache
/Tests/app/logs
/vendor
composer.lock
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ matrix:
- php: 5.6
env: SYMFONY_VERSION=3.2
- php: 5.4
env: COMPOSER_FLAGS="--prefer-lowest"
env: SYMFONY_VERSION=2.3;COMPOSER_FLAGS="--prefer-lowest"

before_install:
- if [[ $TRAVIS_PHP_VERSION != '7.0' && $TRAVIS_PHP_VERSION != '7.1' && $TRAVIS_PHP_VERSION != 'hhvm' ]]; then phpenv config-rm xdebug.ini; fi
Expand All @@ -39,7 +39,7 @@ before_install:

install: composer update --prefer-source $COMPOSER_FLAGS

script: phpunit --coverage-text
script: vendor/bin/phpunit --coverage-text

notifications:
slack: liip:3QOs1QKt3aCFxpJvRzpJCbVZ
11 changes: 8 additions & 3 deletions Helper/PathHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ class PathHelper
protected $routerHelper;

/**
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->assetsHelper = $container->get('templating.helper.assets');
$this->routerHelper = $container->get('templating.helper.router');
// symfony3 does not define templating.helper.assets unless php templating is included
$this->assetsHelper = $container->has('templating.helper.assets') ?
$container->get('templating.helper.assets') : $container->get('assets.packages');

// symfony3 does not define templating.helper.router unless php templating is included
$this->routerHelper = $container->has('templating.helper.router') ?
$container->get('templating.helper.router') : $container->get('router');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Tests/DependencyInjection/LiipMonitorExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ protected function getContainerExtensions()

protected function compile()
{
$this->container->set('doctrine', $this->getMock('Doctrine\Common\Persistence\ConnectionRegistry'));
$doctrineMock = $this->getMockBuilder('Doctrine\Common\Persistence\ConnectionRegistry')->getMock();
$this->container->set('doctrine', $doctrineMock);
$this->container->addCompilerPass(new AddGroupsCompilerPass());
$this->container->addCompilerPass(new GroupRunnersCompilerPass());
$this->container->addCompilerPass(new CheckTagCompilerPass());
Expand Down
29 changes: 29 additions & 0 deletions Tests/Helper/PathHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
namespace Liip\MonitorBundle\Tests\Helper;

use Liip\MonitorBundle\Helper\PathHelper;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\Kernel;

class PathHelperTest extends WebTestCase
{
public function testGenerateRoutes()
{
if (Kernel::MAJOR_VERSION === '2' && Kernel::MINOR_VERSION === '7') {
$environment = 'symfony27';
} else {
$environment = 'symfony' . Kernel::MAJOR_VERSION;
}

$client = static::createClient(array('environment' => $environment));

$container = $client->getContainer();

$pathHelper = new PathHelper($container);

// test route is defined in Tests/app/routing.yml
$routes = $pathHelper->generateRoutes(['test_route' => []]);

$this->assertEquals(['api.test_route = "/monitor";'], $routes);
}
}
9 changes: 5 additions & 4 deletions Tests/Helper/RunnerManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testGetRunner($group)
->with('liip_monitor.runner_'.($group ?: 'default'))
->willReturn(true);

$expectedResult = $this->getMock('Liip\MonitorBundle\Runner');
$expectedResult = $this->getMockBuilder('Liip\MonitorBundle\Runner')->getMock();

$this->container
->expects($this->any())
Expand Down Expand Up @@ -78,8 +78,9 @@ public function testGetRunners()
->with('liip_monitor.runners')
->willReturn(array('liip_monitor.runner_group_1', 'liip_monitor.runner_group_2'));

$runner1 = $this->getMock('Liip\MonitorBundle\Runner');
$runner2 = $this->getMock('Liip\MonitorBundle\Runner');
$runnerMockBuilder = $this->getMockBuilder('Liip\MonitorBundle\Runner');
$runner1 = $runnerMockBuilder->getMock();
$runner2 = $runnerMockBuilder->getMock();
$this->container
->expects($this->exactly(2))
->method('get')
Expand Down Expand Up @@ -132,7 +133,7 @@ public function testGetDefaultGroup()

protected function setUp()
{
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$this->container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();

$this->runnerManager = new RunnerManager($this->container);
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/RunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function testAdditionalReporters()
*/
private function createMockReporter()
{
return $this->getMock('ZendDiagnostics\Runner\Reporter\ReporterInterface');
return $this->getMockBuilder('ZendDiagnostics\Runner\Reporter\ReporterInterface')->getMock();
}
}
29 changes: 29 additions & 0 deletions Tests/app/AppKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

/**
* Class AppKernel
*/
class AppKernel extends Kernel
{
/**
* @return array
*/
public function registerBundles()
{
return [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
];
}

/**
* {@inheritDoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__ . '/config_' . $this->environment . '.yml');
}
}
11 changes: 11 additions & 0 deletions Tests/app/config_symfony2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# symfony 2 config (requires assets_base_urls for testing)
framework:
router:
resource: "%kernel.root_dir%/routing.yml"
secret: test
templating:
engines: ['twig']
assets_base_urls: { http: ["http://testurl"], ssl: ["http://testurl"] }
test: ~
profiler:
collect: false
10 changes: 10 additions & 0 deletions Tests/app/config_symfony27.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# symfony 2.7 config (no longer allows assets_base_urls)
framework:
router:
resource: "%kernel.root_dir%/routing.yml"
secret: test
templating:
engines: ['twig']
test: ~
profiler:
collect: false
11 changes: 11 additions & 0 deletions Tests/app/config_symfony3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# symfony 3 config (requires assets defined)
framework:
router:
resource: "%kernel.root_dir%/routing.yml"
secret: test
templating:
engines: ['twig']
test: ~
assets: ~
profiler:
collect: false
2 changes: 2 additions & 0 deletions Tests/app/routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test_route:
path: "/monitor"
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
"symfony/expression-language": "~2.3|~3.0",
"swiftmailer/swiftmailer": "~5.4",
"doctrine/migrations": "~1.0",
"doctrine/doctrine-migrations-bundle": "~1.0"
"doctrine/doctrine-migrations-bundle": "~1.0",
"symfony/twig-bundle": "^2.0|^3.0",
"symfony/browser-kit": "^2.0|^3.0",
"symfony/asset": "^2.0|^3.0",
"symfony/templating": "^2.0|^3.0",
"phpunit/phpunit": "^4.8|^5.0",
"symfony/finder": "^2.0|^3.0"
},
"suggest": {
"sensio/distribution-bundle": "To be able to use the composer ScriptHandler",
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
</testsuite>
</testsuites>

<php>
<server name="KERNEL_DIR" value="Tests/app" />
</php>

<filter>
<whitelist>
<directory>./</directory>
Expand Down

0 comments on commit 255f7a5

Please sign in to comment.