CommandTestCase   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 44
c 2
b 0
f 0
dl 0
loc 91
rs 10
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A command() 0 23 1
A havingFile() 0 4 1
A havingDir() 0 4 1
A printsError() 0 7 1
A optionsEqual() 0 4 1
A setUp() 0 5 1
A prints() 0 7 1
A printsExactly() 0 4 1
A argsEqual() 0 4 1
A withStdin() 0 3 1
1
<?php namespace Tarsana\Tester;
2
3
use PHPUnit\Framework\TestCase;
4
use Tarsana\Command\Command;
5
use Tarsana\Command\Console\Console;
6
use Tarsana\IO\Filesystem;
7
use Tarsana\IO\Filesystem\Adapters\Memory;
8
use Tarsana\IO\Resource\Buffer;
9
use Tarsana\Tester\Mocks\Transformer;
10
11
abstract class CommandTestCase extends TestCase {
12
13
    protected $fs;
14
    protected $cmd;
15
    protected $stdin;
16
    protected $stdout;
17
    protected $stderr;
18
19
    public function setUp(): void
20
    {
21
        $adapter = new Memory;
22
        $adapter->mkdir('.', 0777, true);
23
        $this->fs = new Filesystem('.', $adapter);
24
    }
25
26
    protected function command(
27
        Command $command, array $args = [],
28
        array $options = [], bool $rawArgs = true
29
    ) {
30
        $stdin = new Buffer;
31
        $stdin->write($this->stdin);
32
        $console = (new Console)
33
            ->stdin($stdin)
34
            ->stdout(new Buffer)
0 ignored issues
show
Bug introduced by
The method stdout() does not exist on Tarsana\IO\Resource\Reader. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
            ->/** @scrutinizer ignore-call */ stdout(new Buffer)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
            ->stderr(new Buffer)
0 ignored issues
show
Bug introduced by
The method stderr() does not exist on Tarsana\IO\Resource\Reader. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
            ->/** @scrutinizer ignore-call */ stderr(new Buffer)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method stderr() does not exist on Tarsana\IO\Resource\Writer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
            ->/** @scrutinizer ignore-call */ stderr(new Buffer)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
            ->outTransformer(new Transformer);
0 ignored issues
show
Bug introduced by
The method outTransformer() does not exist on Tarsana\IO\Resource\Reader. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
            ->/** @scrutinizer ignore-call */ outTransformer(new Transformer);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method outTransformer() does not exist on Tarsana\IO\Resource\Writer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
            ->/** @scrutinizer ignore-call */ outTransformer(new Transformer);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
38
        $this->fs->dir($command->fs()->path(), true);
39
40
        $command->console($console)
0 ignored issues
show
Bug introduced by
It seems like $console can also be of type Tarsana\Command\Console\OutTransformer and Tarsana\IO\Resource\Reader and Tarsana\IO\Resource\Writer; however, parameter $value of Tarsana\Command\Command::console() does only seem to accept Tarsana\Command\Interfac...e\ConsoleInterface|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        $command->console(/** @scrutinizer ignore-type */ $console)
Loading history...
41
                ->fs($this->fs)
42
                ->run($args, $options, $rawArgs);
43
44
        $this->cmd    = $command;
45
        $this->stdout = $console->stdout()->read();
0 ignored issues
show
Bug introduced by
The method stdout() does not exist on Tarsana\Command\Console\OutTransformer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        $this->stdout = $console->/** @scrutinizer ignore-call */ stdout()->read();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method stdout() does not exist on Tarsana\IO\Resource\Writer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        $this->stdout = $console->/** @scrutinizer ignore-call */ stdout()->read();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method read() does not exist on Tarsana\IO\Resource\Writer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        $this->stdout = $console->stdout()->/** @scrutinizer ignore-call */ read();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
        $this->stderr = $console->stderr()->read();
0 ignored issues
show
Bug introduced by
The method stderr() does not exist on Tarsana\Command\Console\OutTransformer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        $this->stderr = $console->/** @scrutinizer ignore-call */ stderr()->read();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
48
        return $this;
49
    }
50
51
    protected function prints(string $text)
52
    {
53
        $this->assertTrue(
54
            false !== strpos($this->stdout, $text),
55
            "Failed asserting that '{$this->stdout}' Contains '{$text}'"
56
        );
57
        return $this;
58
    }
59
60
    protected function printsExactly(string $text)
61
    {
62
        $this->assertEquals($text, $this->stdout);
63
        return $this;
64
    }
65
66
    protected function printsError(string $text)
67
    {
68
        $this->assertTrue(
69
            false !== strpos($this->stderr, $text),
70
            "Failed asserting that '{$this->stderr}' Contains '{$text}'"
71
        );
72
        return $this;
73
    }
74
75
    protected function argsEqual($args)
76
    {
77
        $this->assertEquals($args, $this->cmd->args());
78
        return $this;
79
    }
80
81
    protected function optionsEqual(array $options)
82
    {
83
        $this->assertEquals($options, $this->cmd->options());
84
        return $this;
85
    }
86
87
    protected function withStdin(string $text) {
88
        $this->stdin = $text;
89
        return $this;
90
    }
91
92
    protected function havingFile(string $path, string $content = '')
93
    {
94
        $this->fs->file($path, true)->content($content);
95
        return $this;
96
    }
97
98
    protected function havingDir(string $path)
99
    {
100
        $this->fs->dir($path, true);
101
        return $this;
102
    }
103
104
}
105