Passed
Branch develop (84afed)
by Paulius
02:35
created

UploadTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 33
dl 0
loc 77
rs 10
c 0
b 0
f 0

8 Methods

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