1
|
|
|
<?php |
2
|
|
|
namespace Tests\AppBundle\Sync\Entity\Filter; |
3
|
|
|
|
4
|
|
|
use AppBundle\Sync\Entity\File; |
5
|
|
|
use AppBundle\Sync\Entity\Filter\ExcludeEpisodes; |
6
|
|
|
use org\bovigo\vfs\vfsStream; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Exclude filter tests |
10
|
|
|
* |
11
|
|
|
* @author Sergey Sadovoi <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class ExcludeEpisodesTest extends \PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
public function testFilter() |
16
|
|
|
{ |
17
|
|
|
$files = ['TEST00113.mov', 'TEST00213.mov', 'TEST00313.mov']; |
18
|
|
|
$excludes = [$files[0], $files[1]]; |
19
|
|
|
$tree = ['exclude.list' => json_encode($excludes)]; |
20
|
|
|
|
21
|
|
|
// Init virtual FS |
22
|
|
|
vfsStream::setup('root', null, $tree); |
23
|
|
|
|
24
|
|
|
$filter = new ExcludeEpisodes(); |
25
|
|
|
$filter->setPath(vfsStream::url('root/exclude.list')); |
26
|
|
|
|
27
|
|
View Code Duplication |
foreach ($files as $fileName) { |
|
|
|
|
28
|
|
|
$file = new File(); |
29
|
|
|
$file->setUid($fileName); |
30
|
|
|
|
31
|
|
|
$valid = (array_search($fileName, $excludes) === false); |
32
|
|
|
$this->assertEquals($valid, $filter->valid($file)); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @expectedException \AppBundle\Exception\ExcludeFilterException |
38
|
|
|
* @expectedExceptionCode \AppBundle\Exception\ExcludeFilterException::UNDEFINED_PATH |
39
|
|
|
*/ |
40
|
|
|
public function testUnsetPath() |
41
|
|
|
{ |
42
|
|
|
$filter = new ExcludeEpisodes(); |
43
|
|
|
$filter->valid(new File()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @expectedException \AppBundle\Exception\ExcludeFilterException |
48
|
|
|
* @expectedExceptionCode \AppBundle\Exception\ExcludeFilterException::MISSING_FILE |
49
|
|
|
*/ |
50
|
|
|
public function testMissingFile() |
51
|
|
|
{ |
52
|
|
|
$filter = new ExcludeEpisodes(); |
53
|
|
|
$filter->setPath('/missing/path'); |
54
|
|
|
|
55
|
|
|
$filter->valid(new File()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @expectedException \AppBundle\Exception\ExcludeFilterException |
60
|
|
|
* @expectedExceptionCode \AppBundle\Exception\ExcludeFilterException::INVALID_JSON |
61
|
|
|
*/ |
62
|
|
View Code Duplication |
public function testInvalidContent() |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
$tree = ['exclude.list' => 'bad data']; |
65
|
|
|
|
66
|
|
|
// Init virtual FS |
67
|
|
|
vfsStream::setup('root', null, $tree); |
68
|
|
|
|
69
|
|
|
$filter = new ExcludeEpisodes(); |
70
|
|
|
$filter->setPath(vfsStream::url('root/exclude.list')); |
71
|
|
|
|
72
|
|
|
$filter->valid(new File()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @expectedException \AppBundle\Exception\ExcludeFilterException |
77
|
|
|
* @expectedExceptionCode \AppBundle\Exception\ExcludeFilterException::NOT_ARRAY |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function testContentNotArray() |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$tree = ['exclude.list' => '"bad data"']; |
82
|
|
|
|
83
|
|
|
// Init virtual FS |
84
|
|
|
vfsStream::setup('root', null, $tree); |
85
|
|
|
|
86
|
|
|
$filter = new ExcludeEpisodes(); |
87
|
|
|
$filter->setPath(vfsStream::url('root/exclude.list')); |
88
|
|
|
|
89
|
|
|
$filter->valid(new File()); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.