tarsana /
command
| 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
|
|||||||||
| 35 | ->stderr(new Buffer) |
||||||||
|
0 ignored issues
–
show
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
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...
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
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
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
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...
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
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
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
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
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
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...
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
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...
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
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
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
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 |
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.