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