57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Sikofitt\Tests\Console\Getch;
|
||
|
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
use Sikofitt\Console\Getch;
|
||
|
|
||
|
class GetchTest extends TestCase
|
||
|
{
|
||
|
private \FFI $ffi;
|
||
|
|
||
|
public function setUp(): void
|
||
|
{
|
||
|
$this->ffi = \FFI::load(__DIR__.'/../test.h');
|
||
|
$stdin = $this->ffi->stdin;
|
||
|
|
||
|
foreach (range('D', 'A') as $character) {
|
||
|
$this->ffi->ungetc(ord($character), $stdin);
|
||
|
}
|
||
|
|
||
|
parent::setUp(); // TODO: Change the autogenerated stub
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @preserveGlobalState disabled
|
||
|
*/
|
||
|
public function testFailureOnInvalidLibrary()
|
||
|
{
|
||
|
$this->expectException(\RuntimeException::class);
|
||
|
\getch(__DIR__.'/library.so');
|
||
|
}
|
||
|
|
||
|
public function testGetchClass()
|
||
|
{
|
||
|
$getch = new Getch();
|
||
|
foreach (range('A', 'D') as $character) {
|
||
|
self::assertSame(\ord($character), $getch->getch());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function testGetchFunction()
|
||
|
{
|
||
|
foreach (range('A', 'D') as $character) {
|
||
|
self::assertSame(\ord($character), getch());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function testUnsupportedOS()
|
||
|
{
|
||
|
if (PHP_OS_FAMILY !== 'Linux' || PHP_OS_FAMILY !== 'Windows') {
|
||
|
self::markTestSkipped('This test only applies to non Linux or Windows systems.');
|
||
|
}
|
||
|
$this->expectException(\RuntimeException::class);
|
||
|
\getch();
|
||
|
}
|
||
|
}
|