浏览代码

[DependencyInjection] Test Definition and DefinitionDecorator exceptions

Jeremy Mikola 13 年之前
父节点
当前提交
4bbb685557

+ 10 - 0
tests/Symfony/Tests/Component/DependencyInjection/DefinitionDecoratorTest.php

@@ -69,4 +69,14 @@ class DefinitionDecoratorTest extends \PHPUnit_Framework_TestCase
         $this->assertSame($def, $def->replaceArgument(0, 'foo'));
         $this->assertEquals(array('index_0' => 'foo'), $def->getArguments());
     }
+
+    /**
+     * @expectedException InvalidArgumentException
+     */
+    public function testReplaceArgumentShouldRequireIntegerIndex()
+    {
+        $def = new DefinitionDecorator('foo');
+
+        $def->replaceArgument('0', 'foo');
+    }
 }

+ 22 - 0
tests/Symfony/Tests/Component/DependencyInjection/DefinitionTest.php

@@ -221,6 +221,28 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
         $this->assertSame(array('foo', 'bar'), $def->getArguments());
     }
 
+    /**
+     * @expectedException OutOfBoundsException
+     */
+    public function testGetArgumentShouldCheckBounds()
+    {
+        $def = new Definition('stdClass');
+
+        $def->addArgument('foo');
+        $def->getArgument(1);
+    }
+
+    /**
+     * @expectedException OutOfBoundsException
+     */
+    public function testReplaceArgumentShouldCheckBounds()
+    {
+        $def = new Definition('stdClass');
+
+        $def->addArgument('foo');
+        $def->replaceArgument(1, 'bar');
+    }
+
     public function testSetGetProperties()
     {
         $def = new Definition('stdClass');