Completed
Push — master ( ea9d41...184c59 )
by Sergii
08:21
created

ExcludeEpisodesTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 39.24 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 31
loc 79
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testFilter() 7 20 2
A testUnsetPath() 0 5 1
A testMissingFile() 0 7 1
A testInvalidContent() 12 12 1
A testContentNotArray() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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