1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\AdminBundle\Tests\Helper\FormWidgets\Tabs; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
6
|
|
|
use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\Tab; |
7
|
|
|
use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\TabPane; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Symfony\Component\Form\Form; |
10
|
|
|
use Symfony\Component\Form\FormBuilder; |
11
|
|
|
use Symfony\Component\Form\FormFactory; |
12
|
|
|
use Symfony\Component\Form\FormView; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class TabPaneTest |
17
|
|
|
*/ |
18
|
|
|
class TabPaneTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @throws \ReflectionException |
22
|
|
|
*/ |
23
|
|
|
public function testTabPane() |
24
|
|
|
{ |
25
|
|
|
$request = $this->createMock(Request::class); |
26
|
|
|
$request->request = $this->createMock(Request::class); |
|
|
|
|
27
|
|
|
$factory = $this->createMock(FormFactory::class); |
28
|
|
|
$builder = $this->createMock(FormBuilder::class); |
29
|
|
|
$form = $this->createMock(Form::class); |
30
|
|
|
$view = $this->createMock(FormView::class); |
31
|
|
|
$tab = $this->createMock(Tab::class); |
32
|
|
|
$tab2 = clone $tab; |
33
|
|
|
|
34
|
|
|
$request->expects($this->exactly(2))->method('get')->willReturn($tab); |
35
|
|
|
$tab->expects($this->any())->method('getExtraParams')->willReturn([1, 2, 3, 4, 5]); |
36
|
|
|
$tab->expects($this->any())->method('getTitle')->willReturn('Pass!'); |
37
|
|
|
$form->expects($this->any())->method('createView')->willReturn($view); |
38
|
|
|
$form->expects($this->any())->method('isValid')->willReturn(true); |
39
|
|
|
$builder->expects($this->once())->method('getForm')->willReturn($form); |
40
|
|
|
$factory->expects($this->once())->method('createBuilder')->willReturn($builder); |
41
|
|
|
$em = $this->createMock(EntityManager::class); |
42
|
|
|
|
43
|
|
|
$tabPane = new TabPane('Title', $request, $factory); |
44
|
|
|
|
45
|
|
|
$tabPane->addTab($tab); |
46
|
|
|
$tabPane->addTab($tab2, 0); |
47
|
|
|
$tabPane->buildForm(); |
48
|
|
|
$tabPane->bindRequest(new Request()); |
49
|
|
|
$tabPane->persist($em); |
50
|
|
|
$tabPane->removeTab($tab2); |
51
|
|
|
$this->assertCount(5, $tabPane->getExtraParams(new Request())); |
52
|
|
|
$this->assertInstanceOf(Form::class, $tabPane->getForm()); |
53
|
|
|
$this->assertInstanceOf(FormView::class, $tabPane->getFormView()); |
54
|
|
|
$this->assertTrue($tabPane->isValid()); |
55
|
|
|
$this->assertInstanceOf(Tab::class, $tabPane->getActiveTab()); |
56
|
|
|
$this->assertNull($tabPane->getTabByPosition(5)); |
57
|
|
|
$this->assertNotNull($tabPane->getTabByPosition(0)); |
58
|
|
|
$this->assertNull($tabPane->getTabByTitle('Fail!')); |
59
|
|
|
$this->assertNotNull($tabPane->getTabByTitle('Pass!')); |
60
|
|
|
$tabPane->removeTabByTitle('Pass!'); |
61
|
|
|
$tabPane->removeTabByTitle('not here'); |
62
|
|
|
$this->assertEmpty($tabPane->getTabs()); |
63
|
|
|
$tabPane->addTab($tab); |
64
|
|
|
$tabPane->addTab($tab2, 0); |
65
|
|
|
$tabPane->removeTabByPosition(0); |
66
|
|
|
$this->assertCount(1, $tabPane->getTabs()); |
67
|
|
|
|
68
|
|
|
$request->request->expects($this->exactly(2))->method('get')->willReturn($tab); |
|
|
|
|
69
|
|
|
new TabPane('Title', $request, $factory); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: