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

Commit 68e9588

Browse filesBrowse files
hasonnicolas-grekas
authored andcommitted
[DI] Add tests for class named services
1 parent 849f63f commit 68e9588
Copy full SHA for 68e9588

File tree

6 files changed

+74
-0
lines changed
Filter options

6 files changed

+74
-0
lines changed

‎src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
3030
use Symfony\Component\Config\Resource\FileResource;
3131
use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
32+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
3233
use Symfony\Component\ExpressionLanguage\Expression;
3334

3435
class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
@@ -843,6 +844,32 @@ public function testAutowiring()
843844

844845
$this->assertEquals('a', (string) $container->getDefinition('b')->getArgument(0));
845846
}
847+
848+
public function testClassFromId()
849+
{
850+
$container = new ContainerBuilder();
851+
852+
$unknown = $container->register('unknown_class');
853+
$class = $container->register(\stdClass::class);
854+
$autoloadClass = $container->register(CaseSensitiveClass::class);
855+
$container->compile();
856+
857+
$this->assertSame('unknown_class', $unknown->getClass());
858+
$this->assertEquals(\stdClass::class, $class->getClass());
859+
$this->assertEquals(CaseSensitiveClass::class, $autoloadClass->getClass());
860+
}
861+
862+
/**
863+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
864+
* @expectedExceptionMessage The definition for "123_abc" has no class.
865+
*/
866+
public function testNoClassFromNonClassId()
867+
{
868+
$container = new ContainerBuilder();
869+
870+
$definition = $container->register('123_abc');
871+
$container->compile();
872+
}
846873
}
847874

848875
class FooClass
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
class CaseSensitiveClass
15+
{
16+
}
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<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 http://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
<service id="Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass" />
5+
</services>
6+
</container>
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass:
3+
autowire: true

‎src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
2020
use Symfony\Component\Config\Loader\LoaderResolver;
2121
use Symfony\Component\Config\FileLocator;
22+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
2223
use Symfony\Component\ExpressionLanguage\Expression;
2324

2425
class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
@@ -570,6 +571,16 @@ public function testAutowireAttributeAndTag()
570571
$loader->load('services28.xml');
571572
}
572573

574+
public function testClassFromId()
575+
{
576+
$container = new ContainerBuilder();
577+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
578+
$loader->load('class_from_id.xml');
579+
$container->compile();
580+
581+
$this->assertEquals(CaseSensitiveClass::class, $container->getDefinition(CaseSensitiveClass::class)->getClass());
582+
}
583+
573584
/**
574585
* @group legacy
575586
* @expectedDeprecation Using the attribute "class" is deprecated for the service "bar" which is defined as an alias %s.

‎src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
2020
use Symfony\Component\Config\Loader\LoaderResolver;
2121
use Symfony\Component\Config\FileLocator;
22+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
2223
use Symfony\Component\ExpressionLanguage\Expression;
2324

2425
class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
@@ -329,6 +330,16 @@ public function testAutowire()
329330
$this->assertEquals(array('set*', 'bar'), $container->getDefinition('autowire_array')->getAutowiredMethods());
330331
}
331332

333+
public function testClassFromId()
334+
{
335+
$container = new ContainerBuilder();
336+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
337+
$loader->load('class_from_id.yml');
338+
$container->compile();
339+
340+
$this->assertEquals(CaseSensitiveClass::class, $container->getDefinition(CaseSensitiveClass::class)->getClass());
341+
}
342+
332343
/**
333344
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
334345
* @expectedExceptionMessage The value of the "decorates" option for the "bar" service must be the id of the service without the "@" prefix (replace "@foo" with "foo").

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.