This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/tests/Symfony/Tests/Component/DependencyInjection/DefinitionDecoratorTest.php

111 lines
3.1 KiB
PHP
Raw Normal View History

2011-01-26 23:14:31 +00:00
<?php
2011-05-31 09:57:06 +01:00
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
2011-01-26 23:14:31 +00:00
namespace Symfony\Tests\Component\DependencyInjection;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
class DefinitionDecoratorTest extends \PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$def = new DefinitionDecorator('foo');
$this->assertEquals('foo', $def->getParent());
$this->assertEquals(array(), $def->getChanges());
}
/**
* @dataProvider getPropertyTests
*/
public function testSetProperty($property, $changeKey)
{
$def = new DefinitionDecorator('foo');
$getter = 'get'.ucfirst($property);
$setter = 'set'.ucfirst($property);
$this->assertNull($def->$getter());
$this->assertSame($def, $def->$setter('foo'));
$this->assertEquals('foo', $def->$getter());
$this->assertEquals(array($changeKey => true), $def->getChanges());
}
public function getPropertyTests()
{
return array(
array('class', 'class'),
array('factoryClass', 'factory_class'),
2011-01-26 23:14:31 +00:00
array('factoryMethod', 'factory_method'),
array('factoryService', 'factory_service'),
2011-01-26 23:14:31 +00:00
array('configurator', 'configurator'),
array('file', 'file'),
);
}
public function testSetPublic()
{
$def = new DefinitionDecorator('foo');
$this->assertTrue($def->isPublic());
$this->assertSame($def, $def->setPublic(false));
$this->assertFalse($def->isPublic());
$this->assertEquals(array('public' => true), $def->getChanges());
}
public function testSetArgument()
{
$def = new DefinitionDecorator('foo');
$this->assertEquals(array(), $def->getArguments());
$this->assertSame($def, $def->replaceArgument(0, 'foo'));
2011-01-26 23:14:31 +00:00
$this->assertEquals(array('index_0' => 'foo'), $def->getArguments());
}
/**
* @expectedException InvalidArgumentException
*/
public function testReplaceArgumentShouldRequireIntegerIndex()
{
$def = new DefinitionDecorator('foo');
$def->replaceArgument('0', 'foo');
}
public function testReplaceArgument()
{
$def = new DefinitionDecorator('foo');
$def->setArguments(array(0 => 'foo', 1 => 'bar'));
$this->assertEquals('foo', $def->getArgument(0));
$this->assertEquals('bar', $def->getArgument(1));
$this->assertSame($def, $def->replaceArgument(1, 'baz'));
$this->assertEquals('foo', $def->getArgument(0));
$this->assertEquals('baz', $def->getArgument(1));
$this->assertEquals(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments());
}
/**
* @expectedException OutOfBoundsException
*/
public function testGetArgumentShouldCheckBounds()
{
$def = new DefinitionDecorator('foo');
$def->setArguments(array(0 => 'foo'));
$def->replaceArgument(0, 'foo');
$def->getArgument(1);
}
2011-06-08 18:56:59 +01:00
}