Total Complexity | 3 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | final class PresentationModelTest extends TestCase |
||
11 | { |
||
12 | public function testGenericPresentationModelsShouldOnlyAllowStringVariableNames(): void |
||
13 | { |
||
14 | $this->expectException(TypeError::class); |
||
15 | |||
16 | new PresentationModel([ |
||
17 | 0 => 'A non-string key causes a type error to be thrown', |
||
18 | ]); |
||
19 | } |
||
20 | |||
21 | public function testSpecificPresentationModelsShouldOnlySetDefinedVariables(): void |
||
22 | { |
||
23 | $presentationModel = new class ([ |
||
24 | 'name' => 'name', |
||
25 | 'non_existing_variable' => 'non_existing_variable', |
||
26 | ]) extends PresentationModel |
||
27 | { |
||
28 | protected $name = ''; |
||
29 | }; |
||
30 | |||
31 | $variables = $presentationModel->getVariables(); |
||
32 | |||
33 | $this->assertArrayHasKey('name', $variables); |
||
34 | $this->assertArrayNotHasKey('non_existing_variable', $variables); |
||
35 | } |
||
36 | |||
37 | public function testGetVariableShouldReturnValueOfVariable(): void |
||
38 | { |
||
39 | $presentationModel = new PresentationModel([ |
||
40 | 'name' => 'name', |
||
41 | ]); |
||
42 | |||
43 | $this->assertSame('name', $presentationModel->getVariable('name', 'default')); |
||
44 | } |
||
45 | |||
46 | public function testGetVariableShouldReturnDefaultValueIfVariableDoesNotExist(): void |
||
51 | } |
||
52 | } |
||
53 |