|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Website\Service\RepoGrid; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Databases\Queries\FoundRows; |
|
8
|
|
|
use AbterPhp\Framework\Grid\IGrid; |
|
9
|
|
|
use AbterPhp\Website\Grid\Factory\Page as GridFactory; |
|
10
|
|
|
use AbterPhp\Website\Orm\PageRepo as Repo; |
|
11
|
|
|
use Casbin\Enforcer; |
|
12
|
|
|
use Opulence\Http\Collection; |
|
13
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
class PageTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var Page - System Under Test */ |
|
19
|
|
|
protected $sut; |
|
20
|
|
|
|
|
21
|
|
|
/** @var Enforcer|MockObject */ |
|
22
|
|
|
protected $enforcerMock; |
|
23
|
|
|
|
|
24
|
|
|
/** @var Repo|MockObject */ |
|
25
|
|
|
protected $repoMock; |
|
26
|
|
|
|
|
27
|
|
|
/** @var FoundRows|MockObject */ |
|
28
|
|
|
protected $foundRowsMock; |
|
29
|
|
|
|
|
30
|
|
|
/** @var GridFactory|MockObject */ |
|
31
|
|
|
protected $gridFactoryMock; |
|
32
|
|
|
|
|
33
|
|
|
public function setUp(): void |
|
34
|
|
|
{ |
|
35
|
|
|
parent::setUp(); |
|
36
|
|
|
|
|
37
|
|
|
$this->enforcerMock = $this->createMock(Enforcer::class); |
|
38
|
|
|
$this->repoMock = $this->createMock(Repo::class); |
|
39
|
|
|
$this->foundRowsMock = $this->createMock(FoundRows::class); |
|
40
|
|
|
$this->gridFactoryMock = $this->createMock(GridFactory::class); |
|
41
|
|
|
|
|
42
|
|
|
$this->sut = new Page( |
|
43
|
|
|
$this->enforcerMock, |
|
44
|
|
|
$this->repoMock, |
|
45
|
|
|
$this->foundRowsMock, |
|
46
|
|
|
$this->gridFactoryMock |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testCreateAndPopulate() |
|
51
|
|
|
{ |
|
52
|
|
|
$baseUrl = '/foo'; |
|
53
|
|
|
|
|
54
|
|
|
/** @var Collection|MockObject $query */ |
|
55
|
|
|
$queryStub = $this->createMock(Collection::class); |
|
56
|
|
|
|
|
57
|
|
|
/** @var IGrid|MockObject $query */ |
|
58
|
|
|
$gridStub = $this->createMock(IGrid::class); |
|
59
|
|
|
|
|
60
|
|
|
$this->gridFactoryMock |
|
61
|
|
|
->expects($this->any()) |
|
62
|
|
|
->method('createGrid') |
|
63
|
|
|
->willReturn($gridStub); |
|
64
|
|
|
|
|
65
|
|
|
$actualResult = $this->sut->createAndPopulate($queryStub, $baseUrl); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertSame($gridStub, $actualResult); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|