UninstallCommandTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
cbo 4
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 3
A testExecute() 0 11 1
A testExecuteNonexistentPackage() 0 15 1
A tearDown() 0 7 2
1
<?php
2
3
namespace Bowerphp\Test\Command;
4
5
use Bowerphp\Console\Application;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Console\Tester\CommandTester;
8
9
/**
10
 * @group functional
11
 */
12
class UninstallCommandTest extends TestCase
13
{
14
    protected function setUp()
15
    {
16
        $dir = getcwd() . '/bower_components/';
17
        if (!is_dir($dir)) {
18
            mkdir($dir);
19
        }
20
        if (!is_dir($dir . 'test-package')) {
21
            mkdir($dir . 'test-package');
22
        }
23
        touch($dir . 'test-package/.bower.json');
24
        touch($dir . 'test-package/bower.json');
25
        touch($dir . 'test-package/aFile');
26
        touch($dir . 'test-package/anotherFile');
27
    }
28
29
    public function testExecute()
30
    {
31
        $application = new Application();
32
        $commandTester = new CommandTester($command = $application->get('uninstall'));
33
        $commandTester->execute(['command' => $command->getName(), 'package' => 'test-package'], ['decorated' => false]);
34
35
        $this->assertFileNotExists(getcwd() . '/bower_components/test-package/.bower.json');
36
        $this->assertFileNotExists(getcwd() . '/bower_components/test-package/bower.json');
37
        $this->assertFileNotExists(getcwd() . '/bower_components/test-package/aFile');
38
        $this->assertFileNotExists(getcwd() . '/bower_components/test-package/anotherFile');
39
    }
40
41
    public function testExecuteNonexistentPackage()
42
    {
43
        $application = new Application();
44
        $commandTester = new CommandTester($command = $application->get('uninstall'));
45
        $commandTester->execute(['command' => $command->getName(), 'package' => 'nonexistent-package'], ['decorated' => false]);
46
47
        $this->assertRegExp('/Package nonexistent-package is not installed/', $commandTester->getDisplay());
48
49
        $dir = getcwd() . '/bower_components/';
50
        unlink($dir . 'test-package/.bower.json');
51
        unlink($dir . 'test-package/bower.json');
52
        unlink($dir . 'test-package/aFile');
53
        unlink($dir . 'test-package/anotherFile');
54
        rmdir($dir . '/test-package/');
55
    }
56
57
    protected function tearDown()
58
    {
59
        $dir = getcwd() . '/bower_components/';
60
        if (is_dir($dir)) {
61
            rmdir($dir);
62
        }
63
    }
64
}
65