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