Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests, upgrade phpunit up to 4.3 #511

Merged
merged 1 commit into from
Oct 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions Tests/DependencyInjection/Compiler/FiltersCompilerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Liip\ImagineBundle\Tests\DependencyInjection\Compiler;

use Liip\ImagineBundle\DependencyInjection\Compiler\FiltersCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

/**
Expand All @@ -13,21 +14,25 @@ class FiltersCompilerPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$d = new Definition();
$cb = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
$managerDefinition = new Definition();
$loaderDefinition = new Definition();
$loaderDefinition->addTag('liip_imagine.filter.loader', array(
'loader' => 'foo'
));

$cb->expects($this->atLeastOnce())->method('hasDefinition')->with('liip_imagine.filter.manager')->will($this->returnValue(true));
$cb->expects($this->atLeastOnce())->method('getDefinition')->with('liip_imagine.filter.manager')->will($this->returnValue($d));

$cb->expects($this->atLeastOnce())->method('findTaggedServiceIds')->with('liip_imagine.filter.loader')->will($this->returnValue(array(
'a' => array(array('loader'=>'foo'))
)));
$container = new ContainerBuilder;
$container->setDefinition('liip_imagine.filter.manager', $managerDefinition);
$container->setDefinition('a.loader', $loaderDefinition);

$pass = new FiltersCompilerPass();

$pass->process($cb);
//guard
$this->assertCount(0, $managerDefinition->getMethodCalls());

$this->assertCount(1,$d->getMethodCalls());
$pass->process($container);

$this->assertCount(1, $managerDefinition->getMethodCalls());
}
}

23 changes: 14 additions & 9 deletions Tests/DependencyInjection/Compiler/LoadersCompilerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Liip\ImagineBundle\Tests\DependencyInjection\Compiler;

use Liip\ImagineBundle\DependencyInjection\Compiler\LoadersCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

/**
Expand All @@ -13,21 +14,25 @@ class LoadersCompilerPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$d = new Definition();
$cb = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
$managerDefinition = new Definition();
$loaderDefinition = new Definition();
$loaderDefinition->addTag('liip_imagine.binary.loader', array(
'loader' => 'foo'
));

$cb->expects($this->atLeastOnce())->method('hasDefinition')->with('liip_imagine.data.manager')->will($this->returnValue(true));
$cb->expects($this->atLeastOnce())->method('getDefinition')->with('liip_imagine.data.manager')->will($this->returnValue($d));

$cb->expects($this->atLeastOnce())->method('findTaggedServiceIds')->with('liip_imagine.binary.loader')->will($this->returnValue(array(
'a' => array(array('loader'=>'foo'))
)));
$container = new ContainerBuilder;
$container->setDefinition('liip_imagine.data.manager', $managerDefinition);
$container->setDefinition('a.binary.loader', $loaderDefinition);

$pass = new LoadersCompilerPass();

$pass->process($cb);
//guard
$this->assertCount(0, $managerDefinition->getMethodCalls());

$this->assertCount(1,$d->getMethodCalls());
$pass->process($container);

$this->assertCount(1, $managerDefinition->getMethodCalls());
}
}

24 changes: 14 additions & 10 deletions Tests/DependencyInjection/Compiler/ResolversCompilerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Liip\ImagineBundle\Tests\DependencyInjection\Compiler;

use Liip\ImagineBundle\DependencyInjection\Compiler\ResolversCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

/**
Expand All @@ -13,21 +14,24 @@ class ResolversCompilerPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
{
$d = new Definition();
$cb = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
$managerDefinition = new Definition();
$resolverDefinition = new Definition();
$resolverDefinition->addTag('liip_imagine.cache.resolver', array(
'resolver' => 'foo'
));

$cb->expects($this->atLeastOnce())->method('hasDefinition')->with('liip_imagine.cache.manager')->will($this->returnValue(true));
$cb->expects($this->atLeastOnce())->method('getDefinition')->with('liip_imagine.cache.manager')->will($this->returnValue($d));

$cb->expects($this->atLeastOnce())->method('findTaggedServiceIds')->with('liip_imagine.cache.resolver')->will($this->returnValue(array(
'a' => array(array('resolver'=>'foo'))
)));
$container = new ContainerBuilder;
$container->setDefinition('liip_imagine.cache.manager', $managerDefinition);
$container->setDefinition('a.resolver', $resolverDefinition);

$pass = new ResolversCompilerPass();

$pass->process($cb);
//guard
$this->assertCount(0, $managerDefinition->getMethodCalls());

$pass->process($container);

$this->assertCount(1,$d->getMethodCalls());
$this->assertCount(1, $managerDefinition->getMethodCalls());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testComposeSchemaHostAndPathOnResolve()

$resolver = new NoCacheWebPathResolver($context);

$this->assertEquals('theschema://theHost/aPath', $resolver->resolve('aPath', 'aFilter'));
$this->assertEquals('theschema://thehost/aPath', $resolver->resolve('aPath', 'aFilter'));
}

public function testDoNothingOnStore()
Expand Down
24 changes: 12 additions & 12 deletions Tests/Imagine/Cache/Resolver/WebPathResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function testComposeSchemaHostAndFileUrlOnResolve()
{
$requestContext = new RequestContext;
$requestContext->setScheme('theSchema');
$requestContext->setHost('theHost');
$requestContext->setHost('thehost');

$resolver = new WebPathResolver(
$this->createFilesystemMock(),
Expand All @@ -146,7 +146,7 @@ public function testComposeSchemaHostAndFileUrlOnResolve()
);

$this->assertEquals(
'theschema://theHost/aCachePrefix/aFilter/aPath',
'theschema://thehost/aCachePrefix/aFilter/aPath',
$resolver->resolve('aPath', 'aFilter')
);
}
Expand All @@ -155,7 +155,7 @@ public function testComposeSchemaHostAndBasePathWithPhpFileAndFileUrlOnResolve()
{
$requestContext = new RequestContext;
$requestContext->setScheme('theSchema');
$requestContext->setHost('theHost');
$requestContext->setHost('thehost');
$requestContext->setBaseUrl('/theBasePath/app.php');

$resolver = new WebPathResolver(
Expand All @@ -166,7 +166,7 @@ public function testComposeSchemaHostAndBasePathWithPhpFileAndFileUrlOnResolve()
);

$this->assertEquals(
'theschema://theHost/theBasePath/aCachePrefix/aFilter/aPath',
'theschema://thehost/theBasePath/aCachePrefix/aFilter/aPath',
$resolver->resolve('aPath', 'aFilter')
);
}
Expand All @@ -175,7 +175,7 @@ public function testComposeSchemaHostAndBasePathWithDirsOnlyAndFileUrlOnResolve(
{
$requestContext = new RequestContext;
$requestContext->setScheme('theSchema');
$requestContext->setHost('theHost');
$requestContext->setHost('thehost');
$requestContext->setBaseUrl('/theBasePath/theSubBasePath');

$resolver = new WebPathResolver(
Expand All @@ -186,7 +186,7 @@ public function testComposeSchemaHostAndBasePathWithDirsOnlyAndFileUrlOnResolve(
);

$this->assertEquals(
'theschema://theHost/theBasePath/theSubBasePath/aCachePrefix/aFilter/aPath',
'theschema://thehost/theBasePath/theSubBasePath/aCachePrefix/aFilter/aPath',
$resolver->resolve('aPath', 'aFilter')
);
}
Expand All @@ -195,7 +195,7 @@ public function testComposeSchemaHostAndBasePathWithBackSplashOnResolve()
{
$requestContext = new RequestContext;
$requestContext->setScheme('theSchema');
$requestContext->setHost('theHost');
$requestContext->setHost('thehost');
$requestContext->setBaseUrl('\\');

$resolver = new WebPathResolver(
Expand All @@ -206,7 +206,7 @@ public function testComposeSchemaHostAndBasePathWithBackSplashOnResolve()
);

$this->assertEquals(
'theschema://theHost/aCachePrefix/aFilter/aPath',
'theschema://thehost/aCachePrefix/aFilter/aPath',
$resolver->resolve('aPath', 'aFilter')
);
}
Expand All @@ -215,7 +215,7 @@ public function testComposeSchemaHttpAndCustomPortAndFileUrlOnResolve()
{
$requestContext = new RequestContext;
$requestContext->setScheme('http');
$requestContext->setHost('theHost');
$requestContext->setHost('thehost');
$requestContext->setHttpPort(88);

$resolver = new WebPathResolver(
Expand All @@ -226,7 +226,7 @@ public function testComposeSchemaHttpAndCustomPortAndFileUrlOnResolve()
);

$this->assertEquals(
'http://theHost:88/aCachePrefix/aFilter/aPath',
'http://thehost:88/aCachePrefix/aFilter/aPath',
$resolver->resolve('aPath', 'aFilter')
);
}
Expand All @@ -235,7 +235,7 @@ public function testComposeSchemaHttpsAndCustomPortAndFileUrlOnResolve()
{
$requestContext = new RequestContext;
$requestContext->setScheme('https');
$requestContext->setHost('theHost');
$requestContext->setHost('thehost');
$requestContext->setHttpsPort(444);

$resolver = new WebPathResolver(
Expand All @@ -246,7 +246,7 @@ public function testComposeSchemaHttpsAndCustomPortAndFileUrlOnResolve()
);

$this->assertEquals(
'https://theHost:444/aCachePrefix/aFilter/aPath',
'https://thehost:444/aCachePrefix/aFilter/aPath',
$resolver->resolve('aPath', 'aFilter')
);
}
Expand Down
6 changes: 4 additions & 2 deletions Tests/LiipImagineBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Liip\ImagineBundle\Tests;

use Liip\ImagineBundle\LiipImagineBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @covers Liip\ImagineBundle\LiipImagineBundle
Expand All @@ -28,6 +29,8 @@ public function testAddLoadersCompilerPassOnBuild()
->with($this->isInstanceOf('Liip\ImagineBundle\DependencyInjection\Compiler\LoadersCompilerPass'))
;

$container = new ContainerBuilder();

$bundle = new LiipImagineBundle;

$bundle->build($containerMock);
Expand Down Expand Up @@ -174,5 +177,4 @@ protected function createExtensionMock()

return $this->getMock('Liip\ImagineBundle\DependencyInjection\LiipImagineExtension', $methods, array(), '', false);
}

}
}
19 changes: 14 additions & 5 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<?php
if (!$loader = @include __DIR__ . '/../vendor/autoload.php') {
echo <<<EOM
namespace {
if (!$loader = @include __DIR__ . '/../vendor/autoload.php') {
echo <<<EOM
You must set up the project dependencies by running the following commands:

curl -s http://getcomposer.org/installer | php
php composer.phar install
curl -s http://getcomposer.org/installer | php
php composer.phar install

EOM;
exit(1);
}
}

namespace Symfony\Component\ExpressionLanguage {
if (interface_exists('Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface')) {
return;
}

exit(1);
interface ExpressionFunctionProviderInterface {};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there were errors because expression interface not found, something like this:

3) Liip\ImagineBundle\Tests\LiipImagineBundleTest::testAddResolversCompilerPassOnBuild
PHPUnit_Framework_MockObject_RuntimeException: Cannot mock Symfony\Component\DependencyInjection\ContainerBuilder::addExpressionLanguageProvider() because a class or interface used in the signature is not loaded

/home/vagrant/projects/Liip/LiipImagineBundleSandbox/vendor/liip/imagine-bundle/Liip/ImagineBundle/Tests/LiipImagineBundleTest.php:166
/home/vagrant/projects/Liip/LiipImagineBundleSandbox/vendor/liip/imagine-bundle/Liip/ImagineBundle/Tests/LiipImagineBundleTest.php:58

Caused by
ReflectionException: Class Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface does not exist

/home/vagrant/projects/Liip/LiipImagineBundleSandbox/vendor/liip/imagine-bundle/Liip/ImagineBundle/Tests/LiipImagineBundleTest.php:166
/home/vagrant/projects/Liip/LiipImagineBundleSandbox/vendor/liip/imagine-bundle/Liip/ImagineBundle/Tests/LiipImagineBundleTest.php:58

I did a quick fix, still have to find a better solution

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use ContainerBuilder instance, not mock. But I changed that in the compilers tests but it seems to be hard to get compilers from the container. So I cannot apply same for the bundle class tests.

}
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
},

"require-dev": {
"phpunit/phpunit": "~3.7",
"phpunit/phpunit": "~4.3",
"symfony/browser-kit": "~2.3",
"doctrine/orm": "~2.3",
"doctrine/mongodb-odm": "1.0.*",
"symfony/yaml": "~2.3",
"symfony/form": "~2.3",
"twig/twig": "~1.0",
"symfony/console": "~2.3",
"doctrine/orm": "~2.3",
"doctrine/mongodb-odm": "1.0.*",
"doctrine/cache": "~1.1",
"twig/twig": "~1.0",
"aws/aws-sdk-php": "~2.4",
"amazonwebservices/aws-sdk-for-php": "~1.0",
"psr/log": "~1.0",
"ext-gd": "*",
"symfony/console": "~2.3"
"ext-gd": "*"
},

"suggest": {
Expand Down