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

TargetTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 79
rs 10
c 0
b 0
f 0
wmc 6
1
<?php
2
3
namespace DataStorageTests;
4
5
6
use CommonTestClass;
7
use kalanis\UploadPerPartes\Exceptions\UploadException;
8
use kalanis\UploadPerPartes\Uploader\TargetSearch;
9
use kalanis\UploadPerPartes\Uploader\Translations;
10
use Support;
11
12
13
class TargetTest extends CommonTestClass
14
{
15
    /**
16
     * @throws UploadException
17
     */
18
    public function testFailNoRemote(): void
19
    {
20
        $lang = new Translations();
21
        $lib = new TargetSearch(new Support\InfoRam($lang), new Support\DataRam($lang), $lang);
22
        $this->expectException(UploadException::class);
23
        $lib->process();
24
        $this->expectExceptionMessageMatches('SENT FILE NAME IS EMPTY');
25
    }
26
27
    /**
28
     * @throws UploadException
29
     */
30
    public function testFailNoTarget(): void
31
    {
32
        $lang = new Translations();
33
        $lib = new TargetSearch(new Support\InfoRam($lang), new Support\DataRam($lang), $lang);
34
        $lib->setRemoteFileName('abcdefg');
35
        $this->expectException(UploadException::class);
36
        $lib->process();
37
        $this->expectExceptionMessageMatches('TARGET DIR IS NOT SET');
38
    }
39
40
    /**
41
     * @throws UploadException
42
     */
43
    public function testFailNoBase(): void
44
    {
45
        $lang = new Translations();
46
        $lib = new TargetSearch(new Support\InfoRam($lang), new Support\DataRam($lang), $lang);
47
        $this->expectException(UploadException::class);
48
        $lib->getFinalTargetName();
49
        $this->expectExceptionMessageMatches('UPLOAD FILE NAME IS EMPTY');
50
    }
51
52
    /**
53
     * @throws UploadException
54
     */
55
    public function testProcessClear(): void
56
    {
57
        $lang = new Translations();
58
        $lib = new TargetSearch(new Support\InfoRam($lang), new Support\DataRam($lang), $lang);
59
        $lib->setTargetDir($this->getTestDir())->setRemoteFileName('what can be found$.here')->process();
60
        $this->assertEquals('what_can_be_found.here', $lib->getFinalTargetName());
61
        $this->assertEquals($this->getTestDir() . 'what_can_be_found' . TargetSearch::FILE_DRIVER_SUFF, $lib->getDriverLocation());
62
        $this->assertEquals($this->getTestDir() . 'what_can_be_found.here' . TargetSearch::FILE_UPLOAD_SUFF, $lib->getTemporaryTargetLocation());
63
    }
64
65
    /**
66
     * @throws UploadException
67
     */
68
    public function testProcessNoClear(): void
69
    {
70
        $lang = new Translations();
71
        $lib = new TargetSearch(new Support\InfoRam($lang), new Support\DataRam($lang), $lang, false, false);
72
        $lib->setTargetDir($this->getTestDir())->setRemoteFileName('what el$e can be found')->process();
73
        $this->assertEquals('what el$e can be found', $lib->getFinalTargetName());
74
        $this->assertEquals($this->getTestDir() . 'what el$e can be found' . TargetSearch::FILE_DRIVER_SUFF, $lib->getDriverLocation());
75
        $this->assertEquals($this->getTestDir() . 'what el$e can be found' . TargetSearch::FILE_UPLOAD_SUFF, $lib->getTemporaryTargetLocation());
76
    }
77
78
    /**
79
     * @throws UploadException
80
     */
81
    public function testProcessNameLookup(): void
82
    {
83
        $lang = new Translations();
84
        $dataRam = new Support\DataRam($lang);
85
        $dataRam->addPart($this->getTestDir() . 'dummyFile.tst', 'asdfghjklqwertzuiopyxcvbnm');
86
        $dataRam->addPart($this->getTestDir() . 'dummyFile.0.tst', 'asdfghjklqwertzuiopyxcvbnm');
87
        $dataRam->addPart($this->getTestDir() . 'dummyFile.1.tst', 'asdfghjklqwertzuiopyxcvbnm');
88
        $dataRam->addPart($this->getTestDir() . 'dummyFile.2.tst', 'asdfghjklqwertzuiopyxcvbnm');
89
        $lib = new TargetSearch(new Support\InfoRam($lang), $dataRam, $lang, false, false);
90
        $lib->setTargetDir($this->getTestDir())->setRemoteFileName('dummyFile.tst')->process();
91
        $this->assertEquals($this->getTestDir() . 'dummyFile.3.tst' . TargetSearch::FILE_UPLOAD_SUFF, $lib->getTemporaryTargetLocation());
92
    }
93
}
94