1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\AdminBundle\Tests\Helper\FormWidgets; |
4
|
|
|
|
5
|
|
|
use ArrayIterator; |
6
|
|
|
use Doctrine\ORM\EntityManager; |
7
|
|
|
use Kunstmaan\AdminBundle\Helper\FormWidgets\FormWidget; |
8
|
|
|
use Kunstmaan\AdminBundle\Helper\FormWidgets\ListWidget; |
9
|
|
|
use Kunstmaan\AdminBundle\Tests\unit\Helper\FormWidgets\FakeView; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
use Symfony\Component\Form\FormBuilder; |
12
|
|
|
use Symfony\Component\Form\FormError; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class FormWidgetTest |
17
|
|
|
*/ |
18
|
|
|
class ListWidgetTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
public function testWidget() |
21
|
|
|
{ |
22
|
|
|
$views = new ArrayIterator(); |
23
|
|
|
$views->vars = ['errors' => [new FormError('bang')]]; |
|
|
|
|
24
|
|
|
$view = new FakeView(); |
25
|
|
|
$view->offsetSet('a', $views); |
26
|
|
|
|
27
|
|
|
$widget = $this->createMock(FormWidget::class); |
28
|
|
|
$builder = $this->createMock(FormBuilder::class); |
29
|
|
|
$em = $this->createMock(EntityManager::class); |
30
|
|
|
|
31
|
|
|
$widget->expects($this->exactly(2))->method('bindRequest')->willReturn(true); |
32
|
|
|
$widget->expects($this->exactly(2))->method('persist')->willReturn(true); |
33
|
|
|
$widget->expects($this->exactly(2))->method('getFormErrors')->willReturn(['error' => 'argh']); |
34
|
|
|
$widget->expects($this->exactly(2))->method('getExtraParams')->willReturn(['x' => 'y']); |
35
|
|
|
$widget->expects($this->exactly(2))->method('buildForm')->willReturn(true); |
36
|
|
|
|
37
|
|
|
$listWidget = new ListWidget([$widget, clone $widget]); |
38
|
|
|
$this->assertCount(2, $listWidget->getWidgets()); |
39
|
|
|
$this->assertInstanceOf(FormWidget::class, $listWidget->getWidgets()[0]); |
40
|
|
|
$this->assertInstanceOf(FormWidget::class, $listWidget->getWidgets()[1]); |
41
|
|
|
|
42
|
|
|
$listWidget->bindRequest(new Request()); |
43
|
|
|
$listWidget->buildForm($builder); |
44
|
|
|
$listWidget->persist($em); |
45
|
|
|
|
46
|
|
|
$this->assertCount(1, $listWidget->getFormErrors($view)); |
47
|
|
|
$this->assertEquals('@KunstmaanAdmin/FormWidgets/ListWidget/widget.html.twig', $listWidget->getTemplate()); |
48
|
|
|
$this->assertCount(1, $listWidget->getExtraParams(new Request())); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.