浏览代码

[Validator] added some unit tests for previous merge

Fabien Potencier 13 年之前
父节点
当前提交
1c4bfb4c0d
共有 1 个文件被更改,包括 27 次插入0 次删除
  1. 27 0
      tests/Symfony/Tests/Component/Validator/GraphWalkerTest.php

+ 27 - 0
tests/Symfony/Tests/Component/Validator/GraphWalkerTest.php

@@ -54,6 +54,15 @@ class GraphWalkerTest extends \PHPUnit_Framework_TestCase
         $this->metadata = null;
     }
 
+    public function testWalkObjectUpdatesContext()
+    {
+        $this->metadata->addConstraint(new ConstraintA());
+
+        $this->walker->walkObject($this->metadata, new Entity(), 'Default', '');
+
+        $this->assertEquals('Symfony\Tests\Component\Validator\Fixtures\Entity', $this->getContext()->getCurrentClass());
+    }
+
     public function testWalkObjectValidatesConstraints()
     {
         $this->metadata->addConstraint(new ConstraintA());
@@ -203,6 +212,16 @@ class GraphWalkerTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals($violations, $this->walker->getViolations());
     }
 
+    public function testWalkPropertyUpdatesContext()
+    {
+        $this->metadata->addPropertyConstraint('firstName', new ConstraintA());
+
+        $this->walker->walkPropertyValue($this->metadata, 'firstName', 'value', 'Default', '');
+
+        $this->assertEquals('Symfony\Tests\Component\Validator\Fixtures\Entity', $this->getContext()->getCurrentClass());
+        $this->assertEquals('firstName', $this->getContext()->getCurrentProperty());
+    }
+
     public function testWalkPropertyValueValidatesConstraints()
     {
         $this->metadata->addPropertyConstraint('firstName', new ConstraintA());
@@ -438,4 +457,12 @@ class GraphWalkerTest extends \PHPUnit_Framework_TestCase
         $violations = $this->walker->getViolations();
         $this->assertEquals('collection[foo]', $violations[0]->getPropertyPath());
     }
+
+    protected function getContext()
+    {
+        $p = new \ReflectionProperty($this->walker, 'context');
+        $p->setAccessible(true);
+
+        return $p->getValue($this->walker);
+    }
 }