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
|
|
|
/** |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->presenter = new class implements PresenterInterface |
30
|
|
|
{ |
31
|
|
|
use HasDataTrait; |
32
|
|
|
|
33
|
|
|
public function present( |
34
|
|
|
ServerRequestInterface $request, |
35
|
|
|
PresentationModel $presentationModel |
36
|
|
|
): PresentationModel { |
37
|
|
|
return $presentationModel->withVariables([ |
38
|
|
|
'has_data' => $this->hasData($presentationModel) ? 'has_data' : 'does_not_have_data', |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
}; |
42
|
|
|
|
43
|
|
|
$this->presentationModel = new class extends PresentationModel |
44
|
|
|
{ |
45
|
|
|
protected $has_data = ''; |
46
|
|
|
|
47
|
|
|
protected $variable = ''; |
48
|
|
|
}; |
49
|
|
|
|
50
|
|
|
$this->request = $this->createMock(ServerRequestInterface::class); |
51
|
|
|
|
52
|
|
|
parent::setUp(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
public function testHasDataShouldReturnFalseForEmptyPresentationModels() |
59
|
|
|
{ |
60
|
|
|
$presentationModel = $this->presenter->present($this->request, $this->presentationModel); |
61
|
|
|
|
62
|
|
|
$this->assertEquals('does_not_have_data', $presentationModel->getVariable('has_data')); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function testHasDataShouldReturnTrueForNonEmptyPresentationModels() |
69
|
|
|
{ |
70
|
|
|
$presentationModel = $this->presenter->present( |
71
|
|
|
$this->request, |
72
|
|
|
$this->presentationModel->withVariables(['variable' => 'variable']) |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$this->assertEquals('has_data', $presentationModel->getVariable('has_data')); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|