Passed
Push — master ( 1b6475...610123 )
by Petr
10:18
created

ResponseTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 63
dl 0
loc 122
rs 10
c 1
b 0
f 0
wmc 12
1
<?php
2
3
namespace BasicTests;
4
5
6
use CommonTestClass;
7
use kalanis\UploadPerPartes\Response;
8
use kalanis\UploadPerPartes\Exceptions;
9
10
11
class ResponseTest extends CommonTestClass
12
{
13
    public function testInitBegin(): void
14
    {
15
        $lib = Response\InitResponse::initOk($this->mockSharedKey(), $this->mockData());
16
17
        $this->assertEquals($this->mockSharedKey(), $lib->jsonSerialize()['sharedKey']);
18
        $this->assertEquals('abcdef', $lib->jsonSerialize()['name']);
19
        $this->assertEquals(Response\InitResponse::STATUS_OK, $lib->jsonSerialize()['status']);
20
        $this->assertEquals(12, $lib->jsonSerialize()['totalParts']);
21
        $this->assertEquals(64, $lib->jsonSerialize()['partSize']);
22
        $this->assertEquals(7, $lib->jsonSerialize()['lastKnownPart']);
23
    }
24
25
    public function testInitError(): void
26
    {
27
        $ex = new Exceptions\UploadException('Testing one');
28
        $lib = Response\InitResponse::initError($this->mockData(), $ex);
29
30
        $this->assertEquals('abcdef', $lib->jsonSerialize()['name']);
31
        $this->assertEquals(Response\InitResponse::STATUS_FAIL, $lib->jsonSerialize()['status']);
32
        $this->assertEquals('Testing one', $lib->jsonSerialize()['errorMessage']);
33
    }
34
35
    public function testCheckOk(): void
36
    {
37
        $lib = Response\CheckResponse::initOk($this->mockSharedKey(), '123abc456def789');
38
39
        $this->assertEquals($this->mockSharedKey(), $lib->jsonSerialize()['sharedKey']);
40
        $this->assertEquals('123abc456def789', $lib->jsonSerialize()['checksum']);
41
        $this->assertEquals(Response\CheckResponse::STATUS_OK, $lib->jsonSerialize()['status']);
42
    }
43
44
    public function testCheckError(): void
45
    {
46
        $ex = new Exceptions\UploadException('Testing one');
47
        $lib = Response\CheckResponse::initError($this->mockSharedKey(), $ex);
48
49
        $this->assertEquals($this->mockSharedKey(), $lib->jsonSerialize()['sharedKey']);
50
        $this->assertEquals('', $lib->jsonSerialize()['checksum']);
51
        $this->assertEquals(Response\CheckResponse::STATUS_FAIL, $lib->jsonSerialize()['status']);
52
        $this->assertEquals('Testing one', $lib->jsonSerialize()['errorMessage']);
53
    }
54
55
    public function testTruncateOk(): void
56
    {
57
        $lib = Response\TruncateResponse::initOk($this->mockSharedKey(), $this->mockData());
58
59
        $this->assertEquals($this->mockSharedKey(), $lib->jsonSerialize()['sharedKey']);
60
        $this->assertEquals(7, $lib->jsonSerialize()['lastKnownPart']);
61
        $this->assertEquals(Response\TruncateResponse::STATUS_OK, $lib->jsonSerialize()['status']);
62
    }
63
64
    public function testTruncateError(): void
65
    {
66
        $ex = new Exceptions\UploadException('Testing one');
67
        $lib = Response\TruncateResponse::initError($this->mockSharedKey(), $this->mockData(), $ex);
68
69
        $this->assertEquals($this->mockSharedKey(), $lib->jsonSerialize()['sharedKey']);
70
        $this->assertEquals(Response\TruncateResponse::STATUS_FAIL, $lib->jsonSerialize()['status']);
71
        $this->assertEquals('Testing one', $lib->jsonSerialize()['errorMessage']);
72
    }
73
74
    public function testUploadOk(): void
75
    {
76
        $lib = Response\UploadResponse::initOK($this->mockSharedKey(), $this->mockData());
77
78
        $this->assertEquals($this->mockSharedKey(), $lib->jsonSerialize()['sharedKey']);
79
        $this->assertEquals(Response\UploadResponse::STATUS_OK, $lib->jsonSerialize()['status']);
80
        $this->assertEquals(Response\UploadResponse::STATUS_OK, $lib->jsonSerialize()['errorMessage']);
81
    }
82
83
    public function testUploadFail(): void
84
    {
85
        $ex = new Exceptions\UploadException('Testing one');
86
        $lib = Response\UploadResponse::initError($this->mockSharedKey(), $this->mockData(), $ex);
87
88
        $this->assertEquals($this->mockSharedKey(), $lib->jsonSerialize()['sharedKey']);
89
        $this->assertEquals(Response\UploadResponse::STATUS_FAIL, $lib->jsonSerialize()['status']);
90
        $this->assertEquals('Testing one', $lib->jsonSerialize()['errorMessage']);
91
    }
92
93
    public function testDoneComplete(): void
94
    {
95
        $data = $this->mockData();
96
        $lib = Response\DoneResponse::initDone($this->mockSharedKey(), $data);
97
98
        $this->assertEquals($this->getTestDir() . $data->fileName, $lib->getTemporaryLocation());
99
        $this->assertEquals('abcdef', $lib->getFileName());
100
        $this->assertEquals(123456, $lib->getSize());
101
        $this->assertEquals($this->mockSharedKey(), $lib->jsonSerialize()['sharedKey']);
102
        $this->assertEquals(Response\UploadResponse::STATUS_OK, $lib->jsonSerialize()['status']);
103
        $this->assertEquals(Response\UploadResponse::STATUS_OK, $lib->jsonSerialize()['errorMessage']);
104
    }
105
106
    public function testDoneFail(): void
107
    {
108
        $data = $this->mockData();
109
        $ex = new Exceptions\UploadException('Testing one');
110
        $lib = Response\DoneResponse::initError($this->mockSharedKey(), $data, $ex);
111
112
        $this->assertEquals($this->mockSharedKey(), $lib->jsonSerialize()['sharedKey']);
113
        $this->assertEquals(Response\UploadResponse::STATUS_FAIL, $lib->jsonSerialize()['status']);
114
        $this->assertEquals('Testing one', $lib->jsonSerialize()['errorMessage']);
115
    }
116
117
    public function testCancelOk(): void
118
    {
119
        $lib = Response\CancelResponse::initCancel($this->mockSharedKey());
120
121
        $this->assertEquals($this->mockSharedKey(), $lib->jsonSerialize()['sharedKey']);
122
        $this->assertEquals(Response\CancelResponse::STATUS_OK, $lib->jsonSerialize()['status']);
123
    }
124
125
    public function testCancelError(): void
126
    {
127
        $ex = new Exceptions\UploadException('Testing one');
128
        $lib = Response\CancelResponse::initError($this->mockSharedKey(), $ex);
129
130
        $this->assertEquals($this->mockSharedKey(), $lib->jsonSerialize()['sharedKey']);
131
        $this->assertEquals(Response\CancelResponse::STATUS_FAIL, $lib->jsonSerialize()['status']);
132
        $this->assertEquals('Testing one', $lib->jsonSerialize()['errorMessage']);
133
    }
134
}