Completed
Push — develop ( d0e808...84afed )
by
unknown
17s queued 14s
created

ArchiveTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 38
dl 0
loc 82
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetFieldsToken() 0 10 1
A testCreateResult() 0 3 1
A testGetFileFieldsWithNonExistingFile() 0 6 1
A setUp() 0 11 1
A testGetMethod() 0 3 1
A testGetFieldsPath() 0 12 1
A testGetAction() 0 3 1
A testHasValidationConstraints() 0 7 1
1
<?php
2
namespace Dokobit\Gateway\Tests\Query\File;
3
4
use Dokobit\Gateway\Query\File\Archive;
5
use Dokobit\Gateway\Query\QueryInterface;
6
use Dokobit\Gateway\Tests\TestCase;
7
8
class ArchiveTest extends TestCase
9
{
10
    const TYPE = 'pdf';
11
    const NAME = 'document.pdf';
12
    const TOKEN = 'UploadedFileToken';
13
14
    /** @var Archive */
15
    private $query;
16
17
    /** @var Archive */
18
    private $queryToken;
19
20
    protected function setUp(): void
21
    {
22
        $this->query = new Archive(
23
            self::TYPE,
24
            __DIR__ . '/../../data/document.pdf'
25
        );
26
27
        $this->queryToken = new Archive(
28
            self::TYPE,
29
            self::TOKEN,
30
            true
31
        );
32
    }
33
34
    public function testGetFieldsPath()
35
    {
36
        $fields = $this->query->getFields();
37
38
        $this->assertArrayHasKey('type', $fields);
39
        $this->assertArrayHasKey('file', $fields);
40
        $this->assertArrayHasKey('name', $fields['file']);
41
        $this->assertArrayHasKey('digest', $fields['file']);
42
        $this->assertArrayHasKey('content', $fields['file']);
43
44
        $this->assertSame(self::TYPE, $fields['type']);
45
        $this->assertSame(self::NAME, $fields['file']['name']);
46
    }
47
48
    public function testGetFieldsToken()
49
    {
50
        $fields = $this->queryToken->getFields();
51
52
        $this->assertArrayHasKey('type', $fields);
53
        $this->assertArrayHasKey('file', $fields);
54
        $this->assertArrayHasKey('token', $fields['file']);
55
56
        $this->assertSame(self::TYPE, $fields['type']);
57
        $this->assertSame(self::TOKEN, $fields['file']['token']);
58
    }
59
60
    public function testGetFileFieldsWithNonExistingFile()
61
    {
62
        $this->expectException(\RuntimeException::class);
63
        $this->expectExceptionMessage('File "" does not exist');
64
        $method = new Archive(self::TYPE, '');
65
        $method->getFields();
66
    }
67
68
    public function testGetAction()
69
    {
70
        $this->assertSame('archive', $this->query->getAction());
71
    }
72
73
    public function testGetMethod()
74
    {
75
        $this->assertSame(QueryInterface::POST, $this->query->getMethod());
76
    }
77
78
    public function testCreateResult()
79
    {
80
        $this->assertInstanceOf('Dokobit\Gateway\Result\File\ArchiveResult', $this->query->createResult());
81
    }
82
83
    public function testHasValidationConstraints()
84
    {
85
        $collection = $this->query->getValidationConstraints();
86
87
        $this->assertInstanceOf(
88
            'Symfony\Component\Validator\Constraints\Collection',
89
            $collection
90
        );
91
    }
92
}
93