Passed
Push — master ( 8ef4d4...d6939e )
by Victor
46s queued 11s
created

testGetVariableShouldReturnValueOfVariable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Tests;
5
6
use PHPUnit\Framework\TestCase;
7
use Shoot\Shoot\PresentationModel;
8
use Shoot\Shoot\Tests\Fixtures\Item;
9
use TypeError;
10
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()
57
    {
58
        $presentationModel = new PresentationModel();
59
60
        $this->assertSame('default', $presentationModel->getVariable('does_not_exist', 'default'));
61
    }
62
}
63