1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Shoot\Shoot\Tests\Unit\Utilities; |
5
|
|
|
|
6
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
9
|
|
|
use Shoot\Shoot\PresentationModel; |
10
|
|
|
use Shoot\Shoot\PresenterInterface; |
11
|
|
|
use Shoot\Shoot\Utilities\HasDataTrait; |
12
|
|
|
|
13
|
|
|
final class HasDataTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** @var PresentationModel */ |
16
|
|
|
private $presentationModel; |
17
|
|
|
|
18
|
|
|
/** @var PresenterInterface */ |
19
|
|
|
private $presenter; |
20
|
|
|
|
21
|
|
|
/** @var ServerRequestInterface|MockObject */ |
22
|
|
|
private $request; |
23
|
|
|
|
24
|
|
|
protected function setUp(): void |
25
|
|
|
{ |
26
|
|
|
$this->presenter = new class implements PresenterInterface |
27
|
|
|
{ |
28
|
|
|
use HasDataTrait; |
29
|
|
|
|
30
|
|
|
public function present( |
31
|
|
|
ServerRequestInterface $request, |
32
|
|
|
PresentationModel $presentationModel |
33
|
|
|
): PresentationModel { |
34
|
|
|
return $presentationModel->withVariables([ |
35
|
|
|
'has_data' => $this->hasData($presentationModel) ? 'has_data' : 'does_not_have_data', |
36
|
|
|
]); |
37
|
|
|
} |
38
|
|
|
}; |
39
|
|
|
|
40
|
|
|
$this->presentationModel = new class extends PresentationModel |
41
|
|
|
{ |
42
|
|
|
protected $has_data = ''; |
43
|
|
|
|
44
|
|
|
protected $variable = ''; |
45
|
|
|
}; |
46
|
|
|
|
47
|
|
|
$this->request = $this->createMock(ServerRequestInterface::class); |
48
|
|
|
|
49
|
|
|
parent::setUp(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testHasDataShouldReturnFalseForEmptyPresentationModels(): void |
53
|
|
|
{ |
54
|
|
|
$presentationModel = $this->presenter->present($this->request, $this->presentationModel); |
55
|
|
|
|
56
|
|
|
$this->assertEquals('does_not_have_data', $presentationModel->getVariable('has_data')); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testHasDataShouldReturnTrueForNonEmptyPresentationModels(): void |
60
|
|
|
{ |
61
|
|
|
$presentationModel = $this->presenter->present( |
62
|
|
|
$this->request, |
63
|
|
|
$this->presentationModel->withVariables(['variable' => 'variable']) |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$this->assertEquals('has_data', $presentationModel->getVariable('has_data')); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|