{
$def = new Definition('stdClass');
$this->assertEquals('stdClass', $def->getClass(), '__construct() takes the class name as its first argument');
+ $this->assertSame(array('class' => true), $def->getChanges());
$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 testSetGetFactory()
{
- $def = new Definition('stdClass');
+ $def = new Definition();
$this->assertSame($def, $def->setFactory('foo'), '->setFactory() implements a fluent interface');
$this->assertEquals('foo', $def->getFactory(), '->getFactory() returns the factory');
$def->setFactory('Foo::bar');
$this->assertEquals(array('Foo', 'bar'), $def->getFactory(), '->setFactory() converts string static method call to the array');
+ $this->assertSame(array('factory' => true), $def->getChanges());
}
public function testSetGetClass()
{
$def = new Definition('stdClass');
$this->assertFalse($def->isAutowired());
+
$def->setAutowired(true);
$this->assertTrue($def->isAutowired());
+
+ $def->setAutowired(false);
+ $this->assertFalse($def->isAutowired());
+ }
+
+ public function testChangesNoChanges()
+ {
+ $def = new Definition();
+
+ $this->assertSame(array(), $def->getChanges());
+ }
+
+ public function testGetChangesWithChanges()
+ {
+ $def = new Definition('stdClass', array('fooarg'));
+
+ $def->setAbstract(true);
+ $def->setAutowired(true);
+ $def->setConfigurator('configuration_func');
+ $def->setDecoratedService(null);
+ $def->setDeprecated(true);
+ $def->setFactory('factory_func');
+ $def->setFile('foo.php');
+ $def->setLazy(true);
+ $def->setPublic(true);
+ $def->setShared(true);
+ $def->setSynthetic(true);
+ // changes aren't tracked for these, class or arguments
+ $def->setInstanceofConditionals(array());
+ $def->addTag('foo_tag');
+ $def->addMethodCall('methodCall');
+ $def->setProperty('fooprop', true);
+ $def->setAutoconfigured(true);
+
+ $this->assertSame(array(
+ 'class' => true,
+ 'autowired' => true,
+ 'configurator' => true,
+ 'decorated_service' => true,
+ 'deprecated' => true,
+ 'factory' => true,
+ 'file' => true,
+ 'lazy' => true,
+ 'public' => true,
+ 'shared' => true,
+ 'autoconfigured' => true,
+ ), $def->getChanges());
+
+ $def->setChanges(array());
+ $this->assertSame(array(), $def->getChanges());
}
+ /**
+ * @group legacy
+ */
public function testTypes()
{
$def = new Definition('stdClass');
$this->assertSame($def, $def->removeAutowiringType('Foo'));
$this->assertEquals(array('Bar'), $def->getAutowiringTypes());
}
+
+ public function testShouldAutoconfigure()
+ {
+ $def = new Definition('stdClass');
+ $this->assertFalse($def->isAutoconfigured());
+ $def->setAutoconfigured(true);
+ $this->assertTrue($def->isAutoconfigured());
+ }
+
+ public function testAddError()
+ {
+ $def = new Definition('stdClass');
+ $this->assertEmpty($def->getErrors());
+ $def->addError('First error');
+ $def->addError('Second error');
+ $this->assertSame(array('First error', 'Second error'), $def->getErrors());
+ }
}