123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <?php
-
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
- namespace Symfony\Tests\Component\DependencyInjection;
-
- use Symfony\Component\DependencyInjection\Definition;
-
- class DefinitionTest extends \PHPUnit_Framework_TestCase
- {
- /**
- * @covers Symfony\Component\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');
- }
-
- public function testSetGetFactoryClass()
- {
- $def = new Definition('stdClass');
- $this->assertNull($def->getFactoryClass());
- $this->assertSame($def, $def->setFactoryClass('stdClass2'), "->setFactoryClass() implements a fluent interface.");
- $this->assertEquals('stdClass2', $def->getFactoryClass(), "->getFactoryClass() returns current class to construct this service.");
- }
-
- public function testSetGetFactoryMethod()
- {
- $def = new Definition('stdClass');
- $this->assertNull($def->getFactoryMethod());
- $this->assertSame($def, $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('foo.bar'), "->setFactoryService() implements a fluent interface.");
- $this->assertEquals('foo.bar', $def->getFactoryService(), "->getFactoryService() returns current service to construct this service.");
- }
-
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::setClass
- * @covers Symfony\Component\DependencyInjection\Definition::getClass
- */
- public function testSetGetClass()
- {
- $def = new Definition('stdClass');
- $this->assertSame($def, $def->setClass('foo'), '->setClass() implements a fluent interface');
- $this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
- }
-
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::setArguments
- * @covers Symfony\Component\DependencyInjection\Definition::getArguments
- * @covers Symfony\Component\DependencyInjection\Definition::addArgument
- */
- public function testArguments()
- {
- $def = new Definition('stdClass');
- $this->assertSame($def, $def->setArguments(array('foo')), '->setArguments() implements a fluent interface');
- $this->assertEquals(array('foo'), $def->getArguments(), '->getArguments() returns the arguments');
- $this->assertSame($def, $def->addArgument('bar'), '->addArgument() implements a fluent interface');
- $this->assertEquals(array('foo', 'bar'), $def->getArguments(), '->addArgument() adds an argument');
- }
-
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::setMethodCalls
- * @covers Symfony\Component\DependencyInjection\Definition::addMethodCall
- * @covers Symfony\Component\DependencyInjection\Definition::hasMethodCall
- * @covers Symfony\Component\DependencyInjection\Definition::removeMethodCall
- */
- public function testMethodCalls()
- {
- $def = new Definition('stdClass');
- $this->assertSame($def, $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->assertSame($def, $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');
- $this->assertTrue($def->hasMethodCall('bar'), '->hasMethodCall() returns true if first argument is a method to call registered');
- $this->assertFalse($def->hasMethodCall('no_registered'), '->hasMethodCall() returns false if first argument is not a method to call registered');
- $this->assertSame($def, $def->removeMethodCall('bar'), '->removeMethodCall() implements a fluent interface');
- $this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->removeMethodCall() removes a method to call');
- }
-
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::setFile
- * @covers Symfony\Component\DependencyInjection\Definition::getFile
- */
- public function testSetGetFile()
- {
- $def = new Definition('stdClass');
- $this->assertSame($def, $def->setFile('foo'), '->setFile() implements a fluent interface');
- $this->assertEquals('foo', $def->getFile(), '->getFile() returns the file to include');
- }
-
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::setScope
- * @covers Symfony\Component\DependencyInjection\Definition::getScope
- */
- public function testSetGetScope()
- {
- $def = new Definition('stdClass');
- $this->assertEquals('container', $def->getScope());
- $this->assertSame($def, $def->setScope('foo'));
- $this->assertEquals('foo', $def->getScope());
- }
-
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::setPublic
- * @covers Symfony\Component\DependencyInjection\Definition::isPublic
- */
- public function testSetIsPublic()
- {
- $def = new Definition('stdClass');
- $this->assertTrue($def->isPublic(), '->isPublic() returns true by default');
- $this->assertSame($def, $def->setPublic(false), '->setPublic() implements a fluent interface');
- $this->assertFalse($def->isPublic(), '->isPublic() returns false if the instance must not be public.');
- }
-
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::setSynthetic
- * @covers Symfony\Component\DependencyInjection\Definition::isSynthetic
- */
- public function testSetIsSynthetic()
- {
- $def = new Definition('stdClass');
- $this->assertFalse($def->isSynthetic(), '->isSynthetic() returns false by default');
- $this->assertSame($def, $def->setSynthetic(true), '->setSynthetic() implements a fluent interface');
- $this->assertTrue($def->isSynthetic(), '->isSynthetic() returns true if the instance must not be public.');
- }
-
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::setAbstract
- * @covers Symfony\Component\DependencyInjection\Definition::isAbstract
- */
- public function testSetIsAbstract()
- {
- $def = new Definition('stdClass');
- $this->assertFalse($def->isAbstract(), '->isAbstract() returns false by default');
- $this->assertSame($def, $def->setAbstract(true), '->setAbstract() implements a fluent interface');
- $this->assertTrue($def->isAbstract(), '->isAbstract() returns true if the instance must not be public.');
- }
-
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::setConfigurator
- * @covers Symfony\Component\DependencyInjection\Definition::getConfigurator
- */
- public function testSetGetConfigurator()
- {
- $def = new Definition('stdClass');
- $this->assertSame($def, $def->setConfigurator('foo'), '->setConfigurator() implements a fluent interface');
- $this->assertEquals('foo', $def->getConfigurator(), '->getConfigurator() returns the configurator');
- }
-
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::clearTags
- */
- public function testClearTags()
- {
- $def = new Definition('stdClass');
- $this->assertSame($def, $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\Component\DependencyInjection\Definition::addTag
- * @covers Symfony\Component\DependencyInjection\Definition::getTag
- * @covers Symfony\Component\DependencyInjection\Definition::getTags
- * @covers Symfony\Component\DependencyInjection\Definition::hasTag
- */
- 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->assertFalse($def->hasTag('foo'));
- $this->assertSame($def, $def->addTag('foo'), '->addTag() implements a fluent interface');
- $this->assertTrue($def->hasTag('foo'));
- $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');
- }
-
- /**
- * @covers Symfony\Component\DependencyInjection\Definition::replaceArgument
- */
- public function testSetArgument()
- {
- $def = new Definition('stdClass');
-
- $def->addArgument('foo');
- $this->assertSame(array('foo'), $def->getArguments());
-
- $this->assertSame($def, $def->replaceArgument(0, 'moo'));
- $this->assertSame(array('moo'), $def->getArguments());
-
- $def->addArgument('moo');
- $def
- ->replaceArgument(0, 'foo')
- ->replaceArgument(1, 'bar')
- ;
- $this->assertSame(array('foo', 'bar'), $def->getArguments());
- }
-
- public function testSetGetProperties()
- {
- $def = new Definition('stdClass');
-
- $this->assertEquals(array(), $def->getProperties());
- $this->assertSame($def, $def->setProperties(array('foo' => 'bar')));
- $this->assertEquals(array('foo' => 'bar'), $def->getProperties());
- }
-
- public function testSetProperty()
- {
- $def = new Definition('stdClass');
-
- $this->assertEquals(array(), $def->getProperties());
- $this->assertSame($def, $def->setProperty('foo', 'bar'));
- $this->assertEquals(array('foo' => 'bar'), $def->getProperties());
- }
- }
|