2010-03-18 07:48:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2010-04-25 16:06:54 +01:00
|
|
|
* This file is part of the Symfony package.
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-04-07 02:07:59 +01:00
|
|
|
*
|
2010-03-18 07:48:03 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Tests\Component\DependencyInjection;
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\DependencyInjection\Definition;
|
2010-03-18 07:48:03 +00:00
|
|
|
|
|
|
|
class DefinitionTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2010-06-27 17:28:29 +01:00
|
|
|
/**
|
2010-08-20 22:09:55 +01:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::__construct
|
2010-06-27 17:28:29 +01:00
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function testConstructor()
|
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
|
|
|
$this->assertEquals('stdClass', $def->getClass(), '__construct() takes the class name as its first argument');
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
$def = new Definition('stdClass', array('foo'));
|
|
|
|
$this->assertEquals(array('foo'), $def->getArguments(), '__construct() takes an optional array of arguments as its second argument');
|
|
|
|
}
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2011-02-02 17:22:27 +00:00
|
|
|
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()
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
2011-02-02 17:22:27 +00:00
|
|
|
$this->assertNull($def->getFactoryMethod());
|
2010-11-20 01:09:20 +00:00
|
|
|
$this->assertSame($def, $def->setFactoryMethod('foo'), '->setFactoryMethod() implements a fluent interface');
|
2010-07-05 08:47:14 +01:00
|
|
|
$this->assertEquals('foo', $def->getFactoryMethod(), '->getFactoryMethod() returns the factory method name');
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2010-07-03 23:35:39 +01:00
|
|
|
public function testSetGetFactoryService()
|
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
|
|
|
$this->assertNull($def->getFactoryService());
|
2011-02-02 17:22:27 +00:00
|
|
|
$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.");
|
2010-07-03 23:35:39 +01:00
|
|
|
}
|
|
|
|
|
2010-06-27 17:28:29 +01:00
|
|
|
/**
|
2010-08-20 22:09:55 +01:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::setClass
|
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::getClass
|
2010-06-27 17:28:29 +01:00
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function testSetGetClass()
|
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
2010-11-20 01:09:20 +00:00
|
|
|
$this->assertSame($def, $def->setClass('foo'), '->setClass() implements a fluent interface');
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->assertEquals('foo', $def->getClass(), '->getClass() returns the class name');
|
|
|
|
}
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2010-06-27 17:28:29 +01:00
|
|
|
/**
|
2010-08-20 22:09:55 +01:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::setArguments
|
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::getArguments
|
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::addArgument
|
2010-06-27 17:28:29 +01:00
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function testArguments()
|
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
2010-11-20 01:09:20 +00:00
|
|
|
$this->assertSame($def, $def->setArguments(array('foo')), '->setArguments() implements a fluent interface');
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->assertEquals(array('foo'), $def->getArguments(), '->getArguments() returns the arguments');
|
2010-11-20 01:09:20 +00:00
|
|
|
$this->assertSame($def, $def->addArgument('bar'), '->addArgument() implements a fluent interface');
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->assertEquals(array('foo', 'bar'), $def->getArguments(), '->addArgument() adds an argument');
|
|
|
|
}
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2010-06-27 17:28:29 +01:00
|
|
|
/**
|
2010-08-20 22:09:55 +01:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::setMethodCalls
|
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::addMethodCall
|
2010-10-17 15:40:32 +01:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::hasMethodCall
|
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::removeMethodCall
|
2010-06-27 17:28:29 +01:00
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function testMethodCalls()
|
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
2010-11-20 01:09:20 +00:00
|
|
|
$this->assertSame($def, $def->setMethodCalls(array(array('foo', array('foo')))), '->setMethodCalls() implements a fluent interface');
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->getMethodCalls() returns the methods to call');
|
2010-11-20 01:09:20 +00:00
|
|
|
$this->assertSame($def, $def->addMethodCall('bar', array('bar')), '->addMethodCall() implements a fluent interface');
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->assertEquals(array(array('foo', array('foo')), array('bar', array('bar'))), $def->getMethodCalls(), '->addMethodCall() adds a method to call');
|
2010-10-17 15:40:32 +01:00
|
|
|
$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');
|
2010-11-20 01:09:20 +00:00
|
|
|
$this->assertSame($def, $def->removeMethodCall('bar'), '->removeMethodCall() implements a fluent interface');
|
2010-10-17 15:40:32 +01:00
|
|
|
$this->assertEquals(array(array('foo', array('foo'))), $def->getMethodCalls(), '->removeMethodCall() removes a method to call');
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2010-06-27 17:28:29 +01:00
|
|
|
/**
|
2010-08-20 22:09:55 +01:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::setFile
|
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::getFile
|
2010-06-27 17:28:29 +01:00
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function testSetGetFile()
|
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
2010-11-20 01:09:20 +00:00
|
|
|
$this->assertSame($def, $def->setFile('foo'), '->setFile() implements a fluent interface');
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->assertEquals('foo', $def->getFile(), '->getFile() returns the file to include');
|
|
|
|
}
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2010-06-27 17:28:29 +01:00
|
|
|
/**
|
2011-01-17 22:28:59 +00:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::setScope
|
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::getScope
|
2010-06-27 17:28:29 +01:00
|
|
|
*/
|
2011-01-17 22:28:59 +00:00
|
|
|
public function testSetGetScope()
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
2011-01-17 22:28:59 +00:00
|
|
|
$this->assertEquals('container', $def->getScope());
|
|
|
|
$this->assertSame($def, $def->setScope('foo'));
|
|
|
|
$this->assertEquals('foo', $def->getScope());
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2010-12-29 19:12:24 +00:00
|
|
|
/**
|
|
|
|
* @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.');
|
|
|
|
}
|
|
|
|
|
2011-01-23 11:06:23 +00:00
|
|
|
/**
|
|
|
|
* @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.');
|
|
|
|
}
|
|
|
|
|
2011-01-26 23:14:31 +00:00
|
|
|
/**
|
|
|
|
* @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.');
|
|
|
|
}
|
|
|
|
|
2010-06-27 17:28:29 +01:00
|
|
|
/**
|
2010-08-20 22:09:55 +01:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::setConfigurator
|
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::getConfigurator
|
2010-06-27 17:28:29 +01:00
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function testSetGetConfigurator()
|
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
2010-11-20 01:09:20 +00:00
|
|
|
$this->assertSame($def, $def->setConfigurator('foo'), '->setConfigurator() implements a fluent interface');
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->assertEquals('foo', $def->getConfigurator(), '->getConfigurator() returns the configurator');
|
|
|
|
}
|
2010-03-18 07:48:03 +00:00
|
|
|
|
2010-06-27 17:28:29 +01:00
|
|
|
/**
|
2010-08-20 22:09:55 +01:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::clearTags
|
2010-06-27 17:28:29 +01:00
|
|
|
*/
|
2010-08-05 06:34:53 +01:00
|
|
|
public function testClearTags()
|
2010-06-27 17:28:29 +01:00
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
2010-11-20 01:09:20 +00:00
|
|
|
$this->assertSame($def, $def->clearTags(), '->clearTags() implements a fluent interface');
|
2010-08-05 06:34:53 +01:00
|
|
|
$def->addTag('foo', array('foo' => 'bar'));
|
|
|
|
$def->clearTags();
|
|
|
|
$this->assertEquals(array(), $def->getTags(), '->clearTags() removes all current tags');
|
2010-06-27 17:28:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-08-20 22:09:55 +01:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::addTag
|
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::getTag
|
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::getTags
|
2011-01-24 08:23:15 +00:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::hasTag
|
2010-06-27 17:28:29 +01:00
|
|
|
*/
|
2010-08-05 06:34:53 +01:00
|
|
|
public function testTags()
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
2010-08-05 06:34:53 +01:00
|
|
|
$this->assertEquals(array(), $def->getTag('foo'), '->getTag() returns an empty array if the tag is not defined');
|
2011-01-24 08:23:15 +00:00
|
|
|
$this->assertFalse($def->hasTag('foo'));
|
2010-11-20 01:09:20 +00:00
|
|
|
$this->assertSame($def, $def->addTag('foo'), '->addTag() implements a fluent interface');
|
2011-01-24 08:23:15 +00:00
|
|
|
$this->assertTrue($def->hasTag('foo'));
|
2010-08-05 06:34:53 +01:00
|
|
|
$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(
|
2010-05-06 12:25:53 +01:00
|
|
|
'foo' => array(array(), array('foo' => 'bar')),
|
|
|
|
'bar' => array(array('bar' => 'bar')),
|
2010-08-05 06:34:53 +01:00
|
|
|
), '->getTags() returns all tags');
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2011-01-18 17:53:11 +00:00
|
|
|
|
|
|
|
/**
|
2011-04-19 22:29:10 +01:00
|
|
|
* @covers Symfony\Component\DependencyInjection\Definition::replaceArgument
|
2011-01-18 17:53:11 +00:00
|
|
|
*/
|
|
|
|
public function testSetArgument()
|
|
|
|
{
|
|
|
|
$def = new Definition('stdClass');
|
|
|
|
|
|
|
|
$def->addArgument('foo');
|
|
|
|
$this->assertSame(array('foo'), $def->getArguments());
|
|
|
|
|
2011-04-19 22:29:10 +01:00
|
|
|
$this->assertSame($def, $def->replaceArgument(0, 'moo'));
|
2011-01-18 17:53:11 +00:00
|
|
|
$this->assertSame(array('moo'), $def->getArguments());
|
|
|
|
|
|
|
|
$def->addArgument('moo');
|
|
|
|
$def
|
2011-04-19 22:29:10 +01:00
|
|
|
->replaceArgument(0, 'foo')
|
|
|
|
->replaceArgument(1, 'bar')
|
2011-01-18 17:53:11 +00:00
|
|
|
;
|
|
|
|
$this->assertSame(array('foo', 'bar'), $def->getArguments());
|
|
|
|
}
|
2011-03-10 14:31:00 +00:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2010-03-18 07:48:03 +00:00
|
|
|
}
|