| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * This file is part of graze/console-diff-renderer. |
||||
| 4 | * |
||||
| 5 | * Copyright (c) 2017 Nature Delivered Ltd. <https://www.graze.com> |
||||
| 6 | * |
||||
| 7 | * For the full copyright and license information, please view the LICENSE |
||||
| 8 | * file that was distributed with this source code. |
||||
| 9 | * |
||||
| 10 | * @license https://github.com/graze/console-diff-renderer/blob/master/LICENSE.md |
||||
| 11 | * @link https://github.com/graze/console-diff-renderer |
||||
| 12 | */ |
||||
| 13 | |||||
| 14 | namespace Graze\DiffRenderer\Test\Unit\Terminal; |
||||
| 15 | |||||
| 16 | use Graze\DiffRenderer\Terminal\CursorInterface; |
||||
| 17 | use Graze\DiffRenderer\Terminal\DimensionsInterface; |
||||
| 18 | use Graze\DiffRenderer\Terminal\Terminal; |
||||
| 19 | use Graze\DiffRenderer\Test\TestCase; |
||||
| 20 | use Mockery; |
||||
| 21 | use ReflectionClass; |
||||
| 22 | |||||
| 23 | class TerminalTest extends TestCase |
||||
| 24 | { |
||||
| 25 | public function testTerminalUsesTerminalToGetTerminalSize() |
||||
| 26 | { |
||||
| 27 | $dimensions = Mockery::mock(DimensionsInterface::class); |
||||
| 28 | $dimensions->shouldReceive('getWidth') |
||||
| 29 | ->andReturn(70); |
||||
| 30 | $dimensions->shouldReceive('getHeight') |
||||
| 31 | ->andReturn(40); |
||||
| 32 | |||||
| 33 | $terminal = new Terminal(null, $dimensions); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 34 | |||||
| 35 | $this->assertEquals(70, $terminal->getWidth()); |
||||
| 36 | $this->assertEquals(40, $terminal->getHeight()); |
||||
| 37 | } |
||||
| 38 | |||||
| 39 | public function testTerminalPassesThroughAllCursorMethods() |
||||
| 40 | { |
||||
| 41 | $cursor = Mockery::mock(CursorInterface::class); |
||||
| 42 | $terminal = new Terminal($cursor); |
||||
|
0 ignored issues
–
show
$cursor of type Mockery\MockInterface is incompatible with the type Graze\DiffRenderer\Terminal\CursorInterface|null expected by parameter $cursor of Graze\DiffRenderer\Termi...Terminal::__construct().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 43 | |||||
| 44 | $reflection = new ReflectionClass(CursorInterface::class); |
||||
| 45 | $methods = $reflection->getMethods(); |
||||
| 46 | |||||
| 47 | foreach ($methods as $method) { |
||||
| 48 | if ($method->getNumberOfParameters() > 0) { |
||||
| 49 | $args = array_map(function () { |
||||
| 50 | return rand(0, 100); |
||||
| 51 | }, $method->getParameters()); |
||||
| 52 | $cursor->shouldReceive($method->getName()) |
||||
| 53 | ->withArgs($args) |
||||
| 54 | ->andReturn($method->getName()); |
||||
| 55 | $this->assertEquals($method->getName(), call_user_func_array([$terminal, $method->getName()], $args)); |
||||
| 56 | } else { |
||||
| 57 | $cursor->shouldReceive($method->getName()) |
||||
| 58 | ->andReturn($method->getName()); |
||||
| 59 | $this->assertEquals($method->getName(), call_user_func([$terminal, $method->getName()])); |
||||
| 60 | } |
||||
| 61 | } |
||||
| 62 | } |
||||
| 63 | } |
||||
| 64 |