Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Relax some mocks #22394

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

Merged
merged 1 commit into from
Apr 12, 2017
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
Relax some mocks
  • Loading branch information
nicolas-grekas committed Apr 12, 2017
commit 61be73394e5669536b05e29d81cc9e69b78c8dc4
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,30 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;

class AddCacheWarmerPassTest extends TestCase
{
public function testThatCacheWarmersAreProcessedInPriorityOrder()
{
$services = array(
'my_cache_warmer_service1' => array(0 => array('priority' => 100)),
'my_cache_warmer_service2' => array(0 => array('priority' => 200)),
'my_cache_warmer_service3' => array(0 => array()),
);

$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition', 'hasDefinition'))->getMock();

$container->expects($this->atLeastOnce())
->method('findTaggedServiceIds')
->will($this->returnValue($services));
$container->expects($this->atLeastOnce())
->method('getDefinition')
->with('cache_warmer')
->will($this->returnValue($definition));
$container->expects($this->atLeastOnce())
->method('hasDefinition')
->with('cache_warmer')
->will($this->returnValue(true));
$container = new ContainerBuilder();

$definition->expects($this->once())
->method('replaceArgument')
->with(0, array(
new Reference('my_cache_warmer_service2'),
new Reference('my_cache_warmer_service1'),
new Reference('my_cache_warmer_service3'),
));
$definition = $container->register('cache_warmer')->addArgument(null);
$container->register('my_cache_warmer_service1')->addTag('kernel.cache_warmer', array('priority' => 100));
$container->register('my_cache_warmer_service2')->addTag('kernel.cache_warmer', array('priority' => 200));
$container->register('my_cache_warmer_service3')->addTag('kernel.cache_warmer');

$addCacheWarmerPass = new AddCacheWarmerPass();
$addCacheWarmerPass->process($container);

$expected = array(
new Reference('my_cache_warmer_service2'),
new Reference('my_cache_warmer_service1'),
new Reference('my_cache_warmer_service3'),
);
$this->assertEquals($expected, $definition->getArgument(0));
}

public function testThatCompilerPassIsIgnoredIfThereIsNoCacheWarmerDefinition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,30 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;

class ConfigCachePassTest extends TestCase
{
public function testThatCheckersAreProcessedInPriorityOrder()
{
$services = array(
'checker_2' => array(0 => array('priority' => 100)),
'checker_1' => array(0 => array('priority' => 200)),
'checker_3' => array(0 => array()),
);
$container = new ContainerBuilder();

$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition', 'hasDefinition'))->getMock();

$container->expects($this->atLeastOnce())
->method('findTaggedServiceIds')
->will($this->returnValue($services));
$container->expects($this->atLeastOnce())
->method('getDefinition')
->with('config_cache_factory')
->will($this->returnValue($definition));

$definition->expects($this->once())
->method('replaceArgument')
->with(0, array(
new Reference('checker_1'),
new Reference('checker_2'),
new Reference('checker_3'),
));
$definition = $container->register('config_cache_factory')->addArgument(null);
$container->register('checker_2')->addTag('config_cache.resource_checker', array('priority' => 100));
$container->register('checker_1')->addTag('config_cache.resource_checker', array('priority' => 200));
$container->register('checker_3')->addTag('config_cache.resource_checker');

$pass = new ConfigCachePass();
$pass->process($container);

$expected = array(
new Reference('checker_1'),
new Reference('checker_2'),
new Reference('checker_3'),
);
$this->assertEquals($expected, $definition->getArgument(0));
}

public function testThatCheckersCanBeMissing()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,42 @@

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class PropertyInfoPassTest extends TestCase
{
public function testServicesAreOrderedAccordingToPriority()
/**
* @dataProvider provideTags
*/
public function testServicesAreOrderedAccordingToPriority($index, $tag)
{
$services = array(
'n3' => array(array()),
'n1' => array(array('priority' => 200)),
'n2' => array(array('priority' => 100)),
);
$container = new ContainerBuilder();

$definition = $container->register('property_info')->setArguments(array(null, null, null, null));
$container->register('n2')->addTag($tag, array('priority' => 100));
$container->register('n1')->addTag($tag, array('priority' => 200));
$container->register('n3')->addTag($tag);

$propertyInfoPass = new PropertyInfoPass();
$propertyInfoPass->process($container);

$expected = array(
new Reference('n1'),
new Reference('n2'),
new Reference('n3'),
);
$this->assertEquals($expected, $definition->getArgument($index));
}

$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();

$container
->expects($this->any())
->method('findTaggedServiceIds')
->will($this->returnValue($services));

$propertyInfoPass = new PropertyInfoPass();

$method = new \ReflectionMethod(
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass',
'findAndSortTaggedServices'
public function provideTags()
{
return array(
array(0, 'property_info.list_extractor'),
array(1, 'property_info.type_extractor'),
array(2, 'property_info.description_extractor'),
array(3, 'property_info.access_extractor'),
);
$method->setAccessible(true);

$actual = $method->invoke($propertyInfoPass, 'tag', $container);

$this->assertEquals($expected, $actual);
}

public function testReturningEmptyArrayWhenNoService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;

Expand Down Expand Up @@ -59,7 +60,7 @@ public function testThrowExceptionWhenNoEncoders()
array()
));

$container->expects($this->once())
$container->expects($this->any())
->method('getDefinition')
->will($this->returnValue($definition));

Expand All @@ -71,34 +72,22 @@ public function testThrowExceptionWhenNoEncoders()

public function testServicesAreOrderedAccordingToPriority()
{
$services = array(
'n3' => array(array()),
'n1' => array(array('priority' => 200)),
'n2' => array(array('priority' => 100)),
);

$expected = array(
new Reference('n1'),
new Reference('n2'),
new Reference('n3'),
);

$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
$container = new ContainerBuilder();

$container->expects($this->any())
->method('findTaggedServiceIds')
->will($this->returnValue($services));
$definition = $container->register('serializer')->setArguments(array(null, null));
$container->register('n2')->addTag('serializer.normalizer', array('priority' => 100))->addTag('serializer.encoder', array('priority' => 100));
$container->register('n1')->addTag('serializer.normalizer', array('priority' => 200))->addTag('serializer.encoder', array('priority' => 200));
$container->register('n3')->addTag('serializer.normalizer')->addTag('serializer.encoder');

$serializerPass = new SerializerPass();
$serializerPass->process($container);

$method = new \ReflectionMethod(
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass',
'findAndSortTaggedServices'
$expected = array(
new Reference('n1'),
new Reference('n2'),
new Reference('n3'),
);
$method->setAccessible(true);

$actual = $method->invoke($serializerPass, 'tag', $container);

$this->assertEquals($expected, $actual);
$this->assertEquals($expected, $definition->getArgument(0));
$this->assertEquals($expected, $definition->getArgument(1));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.