Passed
Push — master ( 20ba69...1ea7e6 )
by Victor
47s queued 11s
created

PresentationModelTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 17
dl 0
loc 53
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
testGetVariableShouldReturnDefaultValueIfVariableDoesNotExist() 0 5 ?
A hp$0 ➔ testGetVariableShouldReturnDefaultValueIfVariableDoesNotExist() 0 5 1
A hp$0 ➔ testSpecificPresentationModelsShouldOnlySetDefinedVariables() 0 14 1
testSpecificPresentationModelsShouldOnlySetDefinedVariables() 0 14 ?
A hp$0 ➔ testGetVariableShouldReturnValueOfVariable() 0 7 1
testGetVariableShouldReturnValueOfVariable() 0 7 ?
A testGenericPresentationModelsShouldOnlyAllowStringVariableNames() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Tests\Unit;
5
6
use PHPUnit\Framework\TestCase;
7
use Shoot\Shoot\PresentationModel;
8
use TypeError;
9
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()
59
    {
60
        $presentationModel = new PresentationModel();
61
62
        $this->assertSame('default', $presentationModel->getVariable('does_not_exist', 'default'));
63
    }
64
}
65