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

SyncCommandTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 74
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testExecute() 0 21 1
B getDirTree() 0 43 1
1
<?php
2
namespace Tests\AppBundle\Command;
3
4
use AppBundle\Command\SyncCommand;
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
use Symfony\Bundle\FrameworkBundle\Console\Application;
7
use Symfony\Component\Console\Tester\CommandTester;
8
use org\bovigo\vfs\vfsStream;
9
10
/**
11
 * Sync Command tests
12
 *
13
 * @author Sergey Sadovoi <[email protected]>
14
 */
15
class SyncCommandTest extends WebTestCase
16
{
17
    public function setUp()
18
    {
19
        static::$kernel = static::createKernel();
20
        static::$kernel->boot();
21
    }
22
23
    public function testExecute()
24
    {
25
        // Set up virtual FS
26
        $fs = vfsStream::setup('root', null, $this->getDirTree());
27
28
        $app = new Application(static::$kernel);
29
        $command = new SyncCommand();
30
        $command->setApplication($app);
31
32
        $tester  = new CommandTester($command);
33
        $tester->execute(['command' => $command->getName()]);
34
35
        // Check result directory
36
        $this->assertTrue($fs->hasChild('dest/TEST/TEST00113.mov'));
37
        $this->assertTrue($fs->hasChild('dest/TEST/TEST00213.mov'));
38
        $this->assertTrue($fs->hasChild('dest/TEST/TEST00313.mov'));
39
        $this->assertFalse($fs->hasChild('dest/TEST/TEST00413.mov'));
40
        $this->assertFalse($fs->hasChild('dest/TEST/TEST00513.mov'));
41
        $this->assertTrue($fs->hasChild('dest/ZZZZ/ZZZZ00113.mov'));
42
        $this->assertFalse($fs->hasChild('dest/QQQQ/QQQQ00113.mov'));
43
    }
44
45
    protected function getDirTree()
46
    {
47
        return [
48
            'source' => [
49
                'TEST' => [
50
                    'stream' => [
51
                        'TEST00113.mov' => 'test stream content',
52
                        'TEST00213.mov' => 'test stream content',
53
                        'TEST00313.mov' => 'test stream content',
54
                        'TEST00513.mov' => 'test stream content',
55
                    ],
56
                    'source' => [
57
                        'TEST00213.mov' => 'test source content',
58
                    ],
59
                ],
60
                'ZZZZ' => [
61
                    'stream' => [
62
                        'ZZZZ00113.mov' => 'test stream content',
63
                    ],
64
                    'source' => [
65
                        'ZZZZ00313.mov' => 'test source content',
66
                    ],
67
                ],
68
                'QQQQ' => [
69
                    'stream' => [
70
                        'QQQQ00113.mov' => 'test stream content',
71
                    ],
72
                    'source' => [
73
                        'QQQQ00313.mov' => 'test source content',
74
                    ],
75
                ],
76
            ],
77
            'dest' => [
78
                'TEST' => [
79
                    'TEST00213.mov' => 'test stream content',
80
                    'TEST00313.mov' => 'test stream content 2',
81
                    'TEST00413.mov' => 'test stream content 2',
82
                ],
83
            ],
84
            'exclude-episodes.json' => '["TEST00513.mov"]',
85
            'exclude-shows.json'    => '["QQQQ"]',
86
        ];
87
    }
88
}
89