PageCategoryTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 40
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreate() 0 38 1
A setUp() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Form\Factory;
6
7
use AbterPhp\Admin\Domain\Entities\UserGroup;
8
use AbterPhp\Admin\Orm\UserGroupRepo;
9
use AbterPhp\Framework\I18n\ITranslator;
10
use AbterPhp\Website\Domain\Entities\PageCategory as Entity;
11
use Opulence\Http\Requests\RequestMethods;
12
use Opulence\Sessions\ISession;
13
use Opulence\Sessions\Session;
14
use PHPUnit\Framework\MockObject\MockObject;
15
use PHPUnit\Framework\TestCase;
16
17
class PageCategoryTest extends TestCase
18
{
19
    /** @var PageCategory - System Under Test */
20
    protected $sut;
21
22
    /** @var ISession|MockObject */
23
    protected $sessionMock;
24
25
    /** @var ITranslator|MockObject */
26
    protected $translatorMock;
27
28
    /** @var UserGroupRepo|MockObject */
29
    protected $userGroupRepoMock;
30
31
    public function setUp(): void
32
    {
33
        parent::setUp();
34
35
        $this->sessionMock = $this->createMock(Session::class);
36
        $this->sessionMock->expects($this->any())->method('get')->willReturnArgument(0);
37
38
        $this->translatorMock = $this->createMock(ITranslator::class);
39
        $this->translatorMock->expects($this->any())->method('translate')->willReturnArgument(0);
40
41
        $this->userGroupRepoMock = $this->createMock(UserGroupRepo::class);
42
43
        $this->sut = new PageCategory($this->sessionMock, $this->translatorMock, $this->userGroupRepoMock);
44
    }
45
46
    public function testCreate()
47
    {
48
        $action     = 'foo';
49
        $method     = RequestMethods::POST;
50
        $showUrl    = 'bar';
51
        $entityId   = 'c5098ee4-ab53-4d96-9d23-bde122f8f09b';
52
        $identifier = 'blah';
53
        $name       = 'mah';
54
        $allUserGroups = [
55
            new UserGroup('c6f1db1f-7f6c-408a-b8ba-4ad6ea0b08e1', 'ug-22', 'UG 22', []),
56
            new UserGroup('a26bee22-4b9e-4db6-be61-e3b3434218b7', 'ug-73', 'UG 73', []),
57
            new UserGroup('31bc7d78-834d-4cb9-9d94-263ce5e2bfc0', 'ug-112', 'UG 112', []),
58
            new UserGroup('221fef6e-ebf6-4531-9029-178c024b4bb2', 'ug-432', 'UG 432', []),
59
        ];
60
        $userGroups    = [
61
            new UserGroup('a26bee22-4b9e-4db6-be61-e3b3434218b7', 'ug-73', 'UG 73', []),
62
            new UserGroup('31bc7d78-834d-4cb9-9d94-263ce5e2bfc0', 'ug-112', 'UG 112', []),
63
        ];
64
65
        $this->userGroupRepoMock->expects($this->any())->method('getAll')->willReturn($allUserGroups);
66
67
        /** @var Entity|MockObject $entityMock */
68
        $entityMock = $this->createMock(Entity::class);
69
70
        $entityMock->expects($this->any())->method('getId')->willReturn($entityId);
71
        $entityMock->expects($this->any())->method('getIdentifier')->willReturn($identifier);
72
        $entityMock->expects($this->any())->method('getName')->willReturn($name);
73
        $entityMock->expects($this->any())->method('getUserGroups')->willReturn($userGroups);
74
75
        $form = (string)$this->sut->create($action, $method, $showUrl, $entityMock);
76
77
        $this->assertStringContainsString($action, $form);
78
        $this->assertStringContainsString($showUrl, $form);
79
        $this->assertStringContainsString('CSRF', $form);
80
        $this->assertStringContainsString('POST', $form);
81
        $this->assertStringContainsString('identifier', $form);
82
        $this->assertStringContainsString('name', $form);
83
        $this->assertStringContainsString('button', $form);
84
    }
85
}
86