58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) 2020-2024 https://sikofitt.com sikofitt@gmail.com
|
|
*
|
|
* This Source Code Form is subject to the
|
|
* terms of the Mozilla Public License, v. 2.0.
|
|
*
|
|
* If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
namespace Sikofitt\Tests\Console\Ungetch;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Sikofitt\Console\Getch;
|
|
|
|
class UngetchTest extends TestCase
|
|
{
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp(); // TODO: Change the autogenerated stub
|
|
}
|
|
|
|
public function testUngetch()
|
|
{
|
|
$g = new Getch();
|
|
$res = $g->ungetch('A');
|
|
self::assertSame(65, $res);
|
|
$res = $g->getch();
|
|
self::assertSame(65, $res);
|
|
$res = ungetch(65);
|
|
self::assertSame(65, $res);
|
|
$res = $g->getch();
|
|
self::assertSame(65, $res);
|
|
}
|
|
|
|
public function testTypeError()
|
|
{
|
|
$g = new Getch();
|
|
$this->expectException(\TypeError::class);
|
|
$g->ungetch(new \stdClass());
|
|
}
|
|
|
|
public function testForFun()
|
|
{
|
|
foreach (\str_split(\strrev('Hello World!')) as $char) {
|
|
ungetch($char);
|
|
}
|
|
$result = '';
|
|
do {
|
|
$ord = getch();
|
|
$result .= \chr($ord);
|
|
} while ($ord !== ord('!'));
|
|
self::assertSame('Hello World!', $result);
|
|
}
|
|
}
|