Skip to content

Commit

Permalink
Merge branch '4.3' into 4.4
Browse files Browse the repository at this point in the history
* 4.3:
  [FrameworkBundle] Fix wrong returned status code in ConfigDebugCommand
  [AnnotationCacheWarmer] add RedirectController to annotation cache
  [DI] add tests loading calls with returns-clone
  [EventDispatcher] Added tests for aliased events.
  [DI] Add CSV env var processor tests
  • Loading branch information
nicolas-grekas committed Oct 2, 2019
2 parents 4d6fe5c + bf62544 commit 3354bac
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 9 deletions.
Expand Up @@ -109,7 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} catch (LogicException $e) {
$errorIo->error($e->getMessage());

return;
return 1;
}

$io->title(sprintf('Current configuration for "%s.%s"', $extensionAlias, $path));
Expand Down
Expand Up @@ -36,7 +36,7 @@
<service id="annotations.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer">
<argument type="service" id="annotations.reader" />
<argument>%kernel.cache_dir%/annotations.php</argument>
<argument>#^Symfony\\(?:Component\\HttpKernel\\|Bundle\\FrameworkBundle\\Controller\\(?!AbstractController$|Controller$))#</argument>
<argument>#^Symfony\\(?:Component\\HttpKernel\\|Bundle\\FrameworkBundle\\Controller\\(?!.*Controller$))#</argument>
<argument>%kernel.debug%</argument>
</service>

Expand Down
Expand Up @@ -236,7 +236,7 @@ public function getEnv($prefix, $name, \Closure $getEnv)
}

if ('csv' === $prefix) {
return str_getcsv($env);
return str_getcsv($env, ',', '"', \PHP_VERSION_ID >= 70400 ? '' : '\\');
}

if ('trim' === $prefix) {
Expand Down
Expand Up @@ -478,4 +478,37 @@ public function testRequireFile()

$this->assertEquals('foo', $result);
}

/**
* @dataProvider validCsv
*/
public function testGetEnvCsv($value, $processed)
{
$processor = new EnvVarProcessor(new Container());

$result = $processor->getEnv('csv', 'foo', function ($name) use ($value) {
$this->assertSame('foo', $name);

return $value;
});

$this->assertSame($processed, $result);
}

public function validCsv()
{
$complex = <<<'CSV'
,"""","foo""","\""",\,foo\
CSV;

return [
['', [null]],
[',', ['', '']],
['1', ['1']],
['1,2," 3 "', ['1', '2', ' 3 ']],
['\\,\\\\', ['\\', '\\\\']],
[$complex, \PHP_VERSION_ID >= 70400 ? ['', '"', 'foo"', '\\"', '\\', 'foo\\'] : ['', '"', 'foo"', '\\"",\\,foo\\']],
[null, null],
];
}
}
@@ -0,0 +1,11 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="foo">
<call method="bar" returns-clone="true" />
</service>
</services>
</container>
@@ -0,0 +1,5 @@
services:
foo:
calls:
- {method: bar, arguments: [1], returns_clone: true}
- [bar, [2], true]
Expand Up @@ -904,6 +904,15 @@ public function testOverriddenDefaultsBindings()
$this->assertSame('overridden', $container->get('bar')->quz);
}

public function testReturnsClone()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('returns_clone.xml');

$this->assertSame([['bar', [], true]], $container->getDefinition('foo')->getMethodCalls());
}

public function testSinglyImplementedInterfacesInMultipleResources()
{
$container = new ContainerBuilder();
Expand Down
Expand Up @@ -842,6 +842,19 @@ public function testDefaultValueOfTagged()
$this->assertNull($iteratorArgument->getIndexAttribute());
}

public function testReturnsClone()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('returns_clone.yaml');

$expected = [
['bar', [1], true],
['bar', [2], true],
];
$this->assertSame($expected, $container->getDefinition('foo')->getMethodCalls());
}

public function testSinglyImplementedInterfacesInMultipleResources()
{
$container = new ContainerBuilder();
Expand Down
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class RegisterListenersPassTest extends TestCase
{
Expand All @@ -37,10 +38,6 @@ public function testEventSubscriberWithoutInterface()

public function testValidEventSubscriber()
{
$services = [
'my_event_subscriber' => [0 => []],
];

$builder = new ContainerBuilder();
$eventDispatcherDefinition = $builder->register('event_dispatcher');
$builder->register('my_event_subscriber', 'Symfony\Component\EventDispatcher\Tests\DependencyInjection\SubscriberService')
Expand All @@ -62,6 +59,30 @@ public function testValidEventSubscriber()
$this->assertEquals($expectedCalls, $eventDispatcherDefinition->getMethodCalls());
}

public function testAliasedEventSubscriber(): void
{
$builder = new ContainerBuilder();
$builder->setParameter('event_dispatcher.event_aliases', [AliasedEvent::class => 'aliased_event']);
$builder->register('event_dispatcher');
$builder->register('my_event_subscriber', AliasedSubscriber::class)
->addTag('kernel.event_subscriber');

$registerListenersPass = new RegisterListenersPass();
$registerListenersPass->process($builder);

$expectedCalls = [
[
'addListener',
[
'aliased_event',
[new ServiceClosureArgument(new Reference('my_event_subscriber')), 'onAliasedEvent'],
0,
],
],
];
$this->assertEquals($expectedCalls, $builder->getDefinition('event_dispatcher')->getMethodCalls());
}

public function testAbstractEventListener()
{
$this->expectException('InvalidArgumentException');
Expand Down Expand Up @@ -175,9 +196,33 @@ public function testInvokableEventListener()
];
$this->assertEquals($expectedCalls, $definition->getMethodCalls());
}

public function testAliasedEventListener(): void
{
$container = new ContainerBuilder();
$container->setParameter('event_dispatcher.event_aliases', [AliasedEvent::class => 'aliased_event']);
$container->register('foo', InvokableListenerService::class)->addTag('kernel.event_listener', ['event' => AliasedEvent::class, 'method' => 'onEvent']);
$container->register('event_dispatcher');

$registerListenersPass = new RegisterListenersPass();
$registerListenersPass->process($container);

$definition = $container->getDefinition('event_dispatcher');
$expectedCalls = [
[
'addListener',
[
'aliased_event',
[new ServiceClosureArgument(new Reference('foo')), 'onEvent'],
0,
],
],
];
$this->assertEquals($expectedCalls, $definition->getMethodCalls());
}
}

class SubscriberService implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
class SubscriberService implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
Expand All @@ -197,3 +242,17 @@ public function onEvent()
{
}
}

final class AliasedSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
AliasedEvent::class => 'onAliasedEvent',
];
}
}

final class AliasedEvent
{
}
Expand Up @@ -55,7 +55,7 @@ public function testTrueFalseValues()
'true' => '1',
'int_one' => '1',
'string_one' => '1',
], $this->encoder->decode($csv, 'csv'));
], $this->encoder->decode($csv, 'csv', [CsvEncoder::AS_COLLECTION_KEY => false]));
}

/**
Expand Down

0 comments on commit 3354bac

Please sign in to comment.