Passed
Pull Request — master (#11)
by Victor
01:49
created

HasDataTest.php$0 ➔ present()   A

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Tests\Unit\Utilities;
5
6
use PHPUnit\Framework\TestCase;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Shoot\Shoot\PresentationModel;
9
use Shoot\Shoot\PresenterInterface;
10
use Shoot\Shoot\Utilities\HasDataTrait;
11
12
final class HasDataTest extends TestCase
13
{
14
    /** @var PresentationModel */
15
    private $presentationModel;
16
17
    /** @var PresenterInterface */
18
    private $presenter;
19
20
    /** @var ServerRequestInterface */
21
    private $request;
22
23
    /**
24
     * @return void
25
     */
26
    protected function setUp()
27
    {
28
        $this->presenter = new class implements PresenterInterface
29
        {
30
            use HasDataTrait;
31
32
            public function present(
33
                ServerRequestInterface $request,
34
                PresentationModel $presentationModel
35
            ): PresentationModel {
36
                return $presentationModel->withVariables([
37
                    'has_data' => $this->hasData($presentationModel) ? 'has_data' : 'does_not_have_data'
38
                ]);
39
            }
40
        };
41
42
        $this->presentationModel = new class extends PresentationModel {
43
            protected $has_data = '';
44
45
            protected $variable = '';
46
        };
47
48
        $this->request = $this->createMock(ServerRequestInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Psr\Ht...equestInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Psr\Http\Message\ServerRequestInterface of property $request.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
50
        parent::setUp();
51
    }
52
53
    /**
54
     * @return void
55
     */
56
    public function testHasDataShouldReturnFalseForEmptyPresentationModels()
57
    {
58
        $presentationModel = $this->presenter->present($this->request, $this->presentationModel);
59
60
        $this->assertEquals('does_not_have_data', $presentationModel->getVariable('has_data'));
61
    }
62
63
    /**
64
     * @return void
65
     */
66
    public function testHasDataShouldReturnTrueForNonEmptyPresentationModels()
67
    {
68
        $presentationModel = $this->presenter->present(
69
            $this->request,
70
            $this->presentationModel->withVariables(['variable' => 'variable'])
71
        );
72
73
        $this->assertEquals('has_data', $presentationModel->getVariable('has_data'));
74
    }
75
}
76