152 lines
7.3 KiB
PHP
152 lines
7.3 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Symfony\Tests\Components\DependencyInjection;
|
|
|
|
use Symfony\Components\DependencyInjection\Definition;
|
|
|
|
class DefinitionTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\Definition::__construct
|
|
*/
|
|
public function testConstructor()
|
|
{
|
|
$def = new Definition('stdClass');
|
|
$this->assertEquals('stdClass', $def->getClass(), '__construct() takes the class name as its first argument');
|
|
|
|
$def = new Definition('stdClass', array('foo'));
|
|
$this->assertEquals(array('foo'), $def->getArguments(), '__construct() takes an optional array of arguments as its second argument');
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\Definition::setFactoryMethod
|
|
* @covers Symfony\Components\DependencyInjection\Definition::getFactoryMethod
|
|
*/
|
|
public function testSetGetConstructor()
|
|
{
|
|
$def = new Definition('stdClass');
|
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setFactoryMethod('foo')), '->setFactoryMethod() implements a fluent interface');
|
|
$this->assertEquals('foo', $def->getFactoryMethod(), '->getFactoryMethod() returns the factory method name');
|
|
}
|
|
|
|
public function testSetGetFactoryService()
|
|
{
|
|
$def = new Definition('stdClass');
|
|
$this->assertNull($def->getFactoryService());
|
|
$this->assertSame($def, $def->setFactoryService('stdClass2'), "->setFactoryService() implements a fluent interface.");
|
|
$this->assertEquals('stdClass2', $def->getFactoryService(), "->getFactoryService() returns current service to construct this service.");
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\Definition::setClass
|
|
* @covers Symfony\Components\DependencyInjection\Definition::getClass
|
|
*/
|
|
public function testSetGetClass()
|
|
{
|
|
$def = new Definition('stdClass');
|
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setClass('foo')), '->setClass() implements a fluent interface');
|
|
$this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\Definition::setArguments
|
|
* @covers Symfony\Components\DependencyInjection\Definition::getArguments
|
|
* @covers Symfony\Components\DependencyInjection\Definition::addArgument
|
|
*/
|
|
public function testArguments()
|
|
{
|
|
$def = new Definition('stdClass');
|
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setArguments(array('foo'))), '->setArguments() implements a fluent interface');
|
|
$this->assertEquals(array('foo'), $def->getArguments(), '->getArguments() returns the arguments');
|
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->addArgument('bar')), '->addArgument() implements a fluent interface');
|
|
$this->assertEquals(array('foo', 'bar'), $def->getArguments(), '->addArgument() adds an argument');
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\Definition::setMethodCalls
|
|
* @covers Symfony\Components\DependencyInjection\Definition::addMethodCall
|
|
*/
|
|
public function testMethodCalls()
|
|
{
|
|
$def = new Definition('stdClass');
|
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setMethodCalls(array(array('foo', array('foo'))))), '->setMethodCalls() implements a fluent interface');
|
|
$this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->getMethodCalls() returns the methods to call');
|
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->addMethodCall('bar', array('bar'))), '->addMethodCall() implements a fluent interface');
|
|
$this->assertEquals(array(array('foo', array('foo')), array('bar', array('bar'))), $def->getMethodCalls(), '->addMethodCall() adds a method to call');
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\Definition::setFile
|
|
* @covers Symfony\Components\DependencyInjection\Definition::getFile
|
|
*/
|
|
public function testSetGetFile()
|
|
{
|
|
$def = new Definition('stdClass');
|
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setFile('foo')), '->setFile() implements a fluent interface');
|
|
$this->assertEquals('foo', $def->getFile(), '->getFile() returns the file to include');
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\Definition::setShared
|
|
* @covers Symfony\Components\DependencyInjection\Definition::isShared
|
|
*/
|
|
public function testSetIsShared()
|
|
{
|
|
$def = new Definition('stdClass');
|
|
$this->assertTrue($def->isShared(), '->isShared() returns true by default');
|
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setShared(false)), '->setShared() implements a fluent interface');
|
|
$this->assertFalse($def->isShared(), '->isShared() returns false if the instance must not be shared');
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\Definition::setConfigurator
|
|
* @covers Symfony\Components\DependencyInjection\Definition::getConfigurator
|
|
*/
|
|
public function testSetGetConfigurator()
|
|
{
|
|
$def = new Definition('stdClass');
|
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->setConfigurator('foo')), '->setConfigurator() implements a fluent interface');
|
|
$this->assertEquals('foo', $def->getConfigurator(), '->getConfigurator() returns the configurator');
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\Definition::clearTags
|
|
*/
|
|
public function testClearTags()
|
|
{
|
|
$def = new Definition('stdClass');
|
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->clearTags()), '->clearTags() implements a fluent interface');
|
|
$def->addTag('foo', array('foo' => 'bar'));
|
|
$def->clearTags();
|
|
$this->assertEquals(array(), $def->getTags(), '->clearTags() removes all current tags');
|
|
}
|
|
|
|
/**
|
|
* @covers Symfony\Components\DependencyInjection\Definition::addTag
|
|
* @covers Symfony\Components\DependencyInjection\Definition::getTag
|
|
* @covers Symfony\Components\DependencyInjection\Definition::getTags
|
|
*/
|
|
public function testTags()
|
|
{
|
|
$def = new Definition('stdClass');
|
|
$this->assertEquals(array(), $def->getTag('foo'), '->getTag() returns an empty array if the tag is not defined');
|
|
$this->assertEquals(spl_object_hash($def), spl_object_hash($def->addTag('foo')), '->addTag() implements a fluent interface');
|
|
$this->assertEquals(array(array()), $def->getTag('foo'), '->getTag() returns attributes for a tag name');
|
|
$def->addTag('foo', array('foo' => 'bar'));
|
|
$this->assertEquals(array(array(), array('foo' => 'bar')), $def->getTag('foo'), '->addTag() can adds the same tag several times');
|
|
$def->addTag('bar', array('bar' => 'bar'));
|
|
$this->assertEquals($def->getTags(), array(
|
|
'foo' => array(array(), array('foo' => 'bar')),
|
|
'bar' => array(array('bar' => 'bar')),
|
|
), '->getTags() returns all tags');
|
|
}
|
|
}
|