743f25a287
Previously, the Definition class was used both for type inference and factory construction (if factoryService was absent). This is fine for cases where classes create instances of themselves (e.g. getInstance() or create()), but leads to ambiguity when we have a separate factory class.
61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Symfony\Tests\Component\DependencyInjection\Compiler;
|
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass;
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
class CheckDefinitionValidityPassTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* @expectedException \RuntimeException
|
|
*/
|
|
public function testProcessDetectsSyntheticNonPublicDefinitions()
|
|
{
|
|
$container = new ContainerBuilder();
|
|
$container->register('a')->setSynthetic(true)->setPublic(false);
|
|
|
|
$this->process($container);
|
|
}
|
|
|
|
/**
|
|
* @expectedException \RuntimeException
|
|
*/
|
|
public function testProcessDetectsSyntheticPrototypeDefinitions()
|
|
{
|
|
$container = new ContainerBuilder();
|
|
$container->register('a')->setSynthetic(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
|
|
|
|
$this->process($container);
|
|
}
|
|
|
|
/**
|
|
* @expectedException \RuntimeException
|
|
*/
|
|
public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
|
|
{
|
|
$container = new ContainerBuilder();
|
|
$container->register('a')->setSynthetic(false)->setAbstract(false);
|
|
|
|
$this->process($container);
|
|
}
|
|
|
|
public function testProcess()
|
|
{
|
|
$container = new ContainerBuilder();
|
|
$container->register('a', 'class');
|
|
$container->register('b', 'class')->setSynthetic(true)->setPublic(true);
|
|
$container->register('c', 'class')->setAbstract(true);
|
|
$container->register('d', 'class')->setSynthetic(true);
|
|
|
|
$this->process($container);
|
|
}
|
|
|
|
protected function process(ContainerBuilder $container)
|
|
{
|
|
$pass = new CheckDefinitionValidityPass();
|
|
$pass->process($container);
|
|
}
|
|
} |