From bb740b572298571b2c87f5cd383369dd2b09ce50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20M=C3=A4nnchen?= Date: Sun, 9 Oct 2016 14:40:22 +0000 Subject: [PATCH 1/2] [Form] Correct FormView#parent Type Hint --- src/Symfony/Component/Form/FormView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/FormView.php b/src/Symfony/Component/Form/FormView.php index 401288cf83d91..ad4f21befd765 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; From e6b653d9aa80e1228ab9ba24bb8565165b282e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20M=C3=A4nnchen?= Date: Sun, 9 Oct 2016 14:41:29 +0000 Subject: [PATCH 2/2] [Form] FormView#hasParent Helper Method --- src/Symfony/Component/Form/FormView.php | 10 ++++++ .../Component/Form/Tests/FormViewTest.php | 32 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/Symfony/Component/Form/Tests/FormViewTest.php diff --git a/src/Symfony/Component/Form/FormView.php b/src/Symfony/Component/Form/FormView.php index ad4f21befd765..e32b37d33e00c 100644 --- a/src/Symfony/Component/Form/FormView.php +++ b/src/Symfony/Component/Form/FormView.php @@ -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()); + } +}