diff --git a/src/Symfony/Component/Form/FormView.php b/src/Symfony/Component/Form/FormView.php index 401288cf83d91..e32b37d33e00c 100644 --- a/src/Symfony/Component/Form/FormView.php +++ b/src/Symfony/Component/Form/FormView.php @@ -31,7 +31,7 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable /** * The parent view. * - * @var FormView + * @var FormView|null */ public $parent; @@ -153,4 +153,14 @@ public function count() { return count($this->children); } + + /** + * Has the view a parent? + * + * @return bool + */ + public function hasParent() + { + return $this->parent !== null; + } } diff --git a/src/Symfony/Component/Form/Tests/FormViewTest.php b/src/Symfony/Component/Form/Tests/FormViewTest.php new file mode 100644 index 0000000000000..c5c559ae95abb --- /dev/null +++ b/src/Symfony/Component/Form/Tests/FormViewTest.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests; + +use Symfony\Component\Form\FormView; + +/** + * @author Jonatan Männchen + */ +class FormViewTest extends \PHPUnit_Framework_TestCase +{ + public function testHasFormView() + { + $formView = new FormView($this->getMock(FormView::class)); + $this->assertTrue($formView->hasParent()); + } + + public function testNotHasFormView() + { + $formView = new FormView(); + $this->assertFalse($formView->hasParent()); + } +}