FormTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A testCreate() 0 29 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Contact\Form\Factory;
6
7
use AbterPhp\Framework\I18n\ITranslator;
8
use AbterPhp\Contact\Domain\Entities\Form as Entity;
9
use Opulence\Http\Requests\RequestMethods;
10
use Opulence\Sessions\ISession;
11
use Opulence\Sessions\Session;
12
use PHPUnit\Framework\MockObject\MockObject;
13
use PHPUnit\Framework\TestCase;
14
15
class FormTest extends TestCase
16
{
17
    /** @var Form - System Under Test */
18
    protected $sut;
19
20
    /** @var ISession|MockObject */
21
    protected $sessionMock;
22
23
    /** @var ITranslator|MockObject */
24
    protected $translatorMock;
25
26
    public function setUp(): void
27
    {
28
        parent::setUp();
29
30
        $this->sessionMock = $this->createMock(Session::class);
31
        $this->sessionMock->expects($this->any())->method('get')->willReturnArgument(0);
32
33
        $this->translatorMock = $this->createMock(ITranslator::class);
34
        $this->translatorMock->expects($this->any())->method('translate')->willReturnArgument(0);
35
36
        $this->sut = new Form($this->sessionMock, $this->translatorMock);
37
    }
38
39
    public function testCreate()
40
    {
41
        $action     = 'foo';
42
        $method     = RequestMethods::POST;
43
        $showUrl    = 'bar';
44
        $entityId   = '97450fee-7c17-4416-8cec-084648b5dfe3';
45
        $identifier = 'blah';
46
        $body       = 'mah';
47
48
        /** @var Entity|MockObject $entityMock */
49
        $entityMock = $this->createMock(Entity::class);
50
51
        $entityMock->expects($this->any())->method('getId')->willReturn($entityId);
52
        $entityMock->expects($this->any())->method('getIdentifier')->willReturn($identifier);
53
        $entityMock->expects($this->any())->method('getName')->willReturn($body);
54
55
        $form = (string)$this->sut->create($action, $method, $showUrl, $entityMock);
56
57
        $this->assertStringContainsString($action, $form);
58
        $this->assertStringContainsString($showUrl, $form);
59
        $this->assertStringContainsString('CSRF', $form);
60
        $this->assertStringContainsString('POST', $form);
61
        $this->assertStringContainsString('identifier', $form);
62
        $this->assertStringContainsString('to_name', $form);
63
        $this->assertStringContainsString('to_email', $form);
64
        $this->assertStringContainsString('success_url', $form);
65
        $this->assertStringContainsString('failure_url', $form);
66
        $this->assertStringContainsString('max_body_length', $form);
67
        $this->assertStringContainsString('button', $form);
68
    }
69
}
70