Преглед изворни кода

[HttpFoundation] added some unit tests

Johannes Schmitt пре 14 година
родитељ
комит
408b94b968
1 измењених фајлова са 35 додато и 0 уклоњено
  1. 35 0
      tests/Symfony/Tests/Component/HttpFoundation/ParameterBagTest.php

+ 35 - 0
tests/Symfony/Tests/Component/HttpFoundation/ParameterBagTest.php

@@ -56,6 +56,41 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase
         $this->assertNull($bag->get('null', 'default'), '->get() returns null if null is set');
     }
 
+    /**
+     * @dataProvider getInvalidPaths
+     * @expectedException \InvalidArgumentException
+     * @covers Symfony\Component\HttpFoundation\ParameterBag::getDeep
+     */
+    public function testGetDeepWithInvalidPaths($path)
+    {
+        $bag = new ParameterBag(array('foo' => array('bar' => 'moo')));
+
+        $bag->getDeep($path);
+    }
+
+    public function getInvalidPaths()
+    {
+        return array(
+            array('foo[['),
+            array('foo[d'),
+            array('foo[bar]]'),
+            array('foo[bar]d'),
+        );
+    }
+
+    /**
+	 * @covers Symfony\Component\HttpFoundation\ParameterBag::getDeep
+     */
+    public function testGetDeep()
+    {
+        $bag = new ParameterBag(array('foo' => array('bar' => array('moo' => 'boo'))));
+
+        $this->assertEquals(array('moo' => 'boo'), $bag->getDeep('foo[bar]'));
+        $this->assertEquals('boo', $bag->getDeep('foo[bar][moo]'));
+        $this->assertEquals('default', $bag->getDeep('foo[bar][foo]', 'default'));
+        $this->assertEquals('default', $bag->getDeep('bar[moo][foo]', 'default'));
+    }
+
     /**
      * @covers Symfony\Component\HttpFoundation\ParameterBag::set
      */