1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the jquery-datatables-bundle package. |
||
5 | * |
||
6 | * (c) 2018 WEBEWEB |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace WBW\Bundle\JQuery\DataTablesBundle\Tests\Manager; |
||
13 | |||
14 | use InvalidArgumentException; |
||
15 | use Throwable; |
||
16 | use WBW\Bundle\JQuery\DataTablesBundle\Exception\AlreadyRegisteredDataTablesProviderException; |
||
17 | use WBW\Bundle\JQuery\DataTablesBundle\Exception\UnregisteredDataTablesProviderException; |
||
18 | use WBW\Bundle\JQuery\DataTablesBundle\Manager\DataTablesManager; |
||
19 | use WBW\Bundle\JQuery\DataTablesBundle\Provider\DataTablesProviderInterface; |
||
20 | use WBW\Bundle\JQuery\DataTablesBundle\Tests\AbstractTestCase; |
||
21 | use WBW\Library\Symfony\Provider\ProviderInterface; |
||
22 | |||
23 | /** |
||
24 | * DataTables manager test. |
||
25 | * |
||
26 | * @author webeweb <https://github.com/webeweb> |
||
27 | * @package WBW\Bundle\JQuery\DataTablesBundle\Tests\Manager |
||
28 | */ |
||
29 | class DataTablesManagerTest extends AbstractTestCase { |
||
30 | |||
31 | /** |
||
32 | * DataTables provider. |
||
33 | * |
||
34 | * @var DataTablesProviderInterface |
||
35 | */ |
||
36 | private $dataTablesProvider; |
||
37 | |||
38 | /** |
||
39 | * {@inheritDoc} |
||
40 | */ |
||
41 | protected function setUp(): void { |
||
42 | parent::setUp(); |
||
43 | |||
44 | // Set a DataTables provider mock. |
||
45 | $this->dataTablesProvider = $this->getMockBuilder(DataTablesProviderInterface::class)->getMock(); |
||
0 ignored issues
–
show
|
|||
46 | $this->dataTablesProvider->expects($this->any())->method("getName")->willReturn("name"); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Test addProvider() |
||
51 | * |
||
52 | * @return void |
||
53 | * @throws Throwable Throws an exception if an error occurs. |
||
54 | */ |
||
55 | public function testAddProvider(): void { |
||
56 | |||
57 | $obj = new DataTablesManager(); |
||
58 | |||
59 | $obj->addProvider($this->dataTablesProvider); |
||
60 | $this->assertCount(1, $obj->getProviders()); |
||
61 | $this->assertSame($this->dataTablesProvider, $obj->getProviders()[0]); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Test addProvider() |
||
66 | * |
||
67 | * @return void |
||
68 | * @throws Throwable Throws an exception if an error occurs. |
||
69 | */ |
||
70 | public function testAddProviderWithAlreadyRegisteredDataTablesProviderException(): void { |
||
71 | |||
72 | $obj = new DataTablesManager(); |
||
73 | $obj->addProvider($this->dataTablesProvider); |
||
74 | |||
75 | try { |
||
76 | |||
77 | $obj->addProvider($this->dataTablesProvider); |
||
78 | } catch (Throwable $ex) { |
||
79 | |||
80 | $this->assertInstanceOf(AlreadyRegisteredDataTablesProviderException::class, $ex); |
||
81 | $this->assertEquals('A DataTables provider with name "name" is already registered', $ex->getMessage()); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Test addProvider() |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | public function testAddProviderWithInvalidArgumentException(): void { |
||
91 | |||
92 | // Set a Provider mock. |
||
93 | $provider = $this->getMockBuilder(ProviderInterface::class)->getMock(); |
||
94 | |||
95 | $obj = new DataTablesManager(); |
||
96 | |||
97 | try { |
||
98 | |||
99 | $obj->addProvider($provider); |
||
100 | } catch (Throwable $ex) { |
||
101 | |||
102 | $this->assertInstanceOf(InvalidArgumentException::class, $ex); |
||
103 | $this->assertEquals("The provider must implements " . DataTablesProviderInterface::class, $ex->getMessage()); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Test getProvider() |
||
109 | * |
||
110 | * @return void |
||
111 | * @throws Throwable Throws an exception if an error occurs. |
||
112 | */ |
||
113 | public function testGetProvider(): void { |
||
114 | |||
115 | $obj = new DataTablesManager(); |
||
116 | |||
117 | $obj->addProvider($this->dataTablesProvider); |
||
118 | $this->assertSame($this->dataTablesProvider, $obj->getProvider($this->dataTablesProvider->getName())); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Test getProvider() |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | public function testGetProviderWithUnregisteredDataTablesProviderException(): void { |
||
127 | |||
128 | $obj = new DataTablesManager(); |
||
129 | |||
130 | try { |
||
131 | |||
132 | $obj->getProvider("exception"); |
||
133 | } catch (Throwable $ex) { |
||
134 | |||
135 | $this->assertInstanceOf(UnregisteredDataTablesProviderException::class, $ex); |
||
136 | $this->assertEquals('None DataTables provider registered with name "exception"', $ex->getMessage()); |
||
137 | } |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Test __construct() |
||
142 | * |
||
143 | * @return void |
||
144 | */ |
||
145 | public function test__construct(): void { |
||
146 | |||
147 | $this->assertEquals("wbw.jquery.datatables.manager", DataTablesManager::SERVICE_NAME); |
||
148 | |||
149 | $obj = new DataTablesManager(); |
||
150 | |||
151 | $this->assertEquals([], $obj->getProviders()); |
||
152 | } |
||
153 | } |
||
154 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..