2019-11-19 17:01:45 -05:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
2021-04-14 13:24:13 -04:00
|
|
|
namespace Aviat\Kilo\Tests;
|
2019-11-19 17:01:45 -05:00
|
|
|
|
|
|
|
use Aviat\Kilo\Editor;
|
2021-03-11 17:11:00 -05:00
|
|
|
use Aviat\Kilo\Type\TerminalSize;
|
2019-11-19 17:01:45 -05:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-11-20 15:03:48 -05:00
|
|
|
use Spatie\Snapshots\MatchesSnapshots;
|
2019-12-04 10:54:15 -05:00
|
|
|
|
|
|
|
class MockEditor extends Editor {
|
2021-03-11 17:11:00 -05:00
|
|
|
public static function mock(string $filename = ''): Editor
|
2019-12-04 10:54:15 -05:00
|
|
|
{
|
2021-03-11 17:11:00 -05:00
|
|
|
$self = self::new(2, ['kilo', $filename]);
|
|
|
|
$self->terminalSize = new TerminalSize(23, 80);
|
|
|
|
$self->statusMessage->time = 1234567890;
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __set(string $name, mixed $value): void
|
|
|
|
{
|
|
|
|
if (property_exists($this, $name))
|
2019-12-04 10:54:15 -05:00
|
|
|
{
|
2021-03-11 17:11:00 -05:00
|
|
|
$this->$name = $value;
|
2019-12-04 10:54:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-19 17:01:45 -05:00
|
|
|
|
|
|
|
class EditorTest extends TestCase {
|
2019-11-20 15:03:48 -05:00
|
|
|
use MatchesSnapshots;
|
|
|
|
|
|
|
|
public function test__debugInfo(): void
|
|
|
|
{
|
2021-03-11 17:11:00 -05:00
|
|
|
$editor = MockEditor::mock();
|
|
|
|
|
|
|
|
$state = json_encode($editor->__debugInfo(), JSON_THROW_ON_ERROR);
|
2019-11-20 15:03:48 -05:00
|
|
|
$this->assertMatchesJsonSnapshot($state);
|
|
|
|
}
|
|
|
|
|
2019-12-04 10:54:15 -05:00
|
|
|
public function testOpenPHP(): void
|
2019-11-20 15:03:48 -05:00
|
|
|
{
|
2021-03-11 17:11:00 -05:00
|
|
|
$editor = MockEditor::mock('test.php');
|
2019-12-04 10:54:15 -05:00
|
|
|
|
2021-03-17 15:43:24 -04:00
|
|
|
$state = json_encode($editor->__debugInfo(), JSON_THROW_ON_ERROR);
|
2019-12-04 10:54:15 -05:00
|
|
|
$this->assertMatchesJsonSnapshot($state);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOpen(): void
|
|
|
|
{
|
2021-03-11 17:11:00 -05:00
|
|
|
$editor = MockEditor::mock('src/ffi.h');
|
2019-11-20 15:03:48 -05:00
|
|
|
|
2021-03-17 15:43:24 -04:00
|
|
|
$state = json_encode($editor->__debugInfo(), JSON_THROW_ON_ERROR);
|
2019-11-20 15:03:48 -05:00
|
|
|
$this->assertMatchesJsonSnapshot($state);
|
|
|
|
}
|
2019-11-19 17:01:45 -05:00
|
|
|
}
|