Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] FormView#hasParent Helper Method #20190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Symfony/Component/Form/FormView.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
/**
* The parent view.
*
* @var FormView
* @var FormView|null
*/
public $parent;

Expand Down Expand Up @@ -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;
}
}
32 changes: 32 additions & 0 deletions src/Symfony/Component/Form/Tests/FormViewTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* 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 <[email protected]>
*/
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());
}
}