Tests for every class

This commit is contained in:
Timothy Warren 2019-11-19 17:01:45 -05:00
parent 513b5537a9
commit eb116a5072
6 changed files with 150 additions and 3 deletions

View File

@ -17,8 +17,8 @@
"phpunit/phpunit": "^8"
},
"scripts": {
"coverage": "phpdbg -qrr -- vendor/bin/phpunit tests",
"test": "vendor/bin/phpunit tests"
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c phpunit.xml tests",
"test": "vendor/bin/phpunit -c phpunit.xml tests"
},
"require": {
"ext-ffi": "*"

View File

@ -7,14 +7,18 @@
<filter>
<whitelist>
<directory suffix=".php">src</directory>
<exclude>
<file>src/constants.php</file>
</exclude>
</whitelist>
</filter>
<testsuites>
<testsuite name="PHPKilo">
<directory>tests</directory>
<directory phpVersion="7.4.0" phpVersionOperator=">=">tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="coverage"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true" />
</logging>
</phpunit>

23
tests/EditorTest.php Normal file
View File

@ -0,0 +1,23 @@
<?php declare(strict_types=1);
namespace Aviat\Kilo\Tests\Traits;
use Aviat\Kilo\Editor;
use PHPUnit\Framework\TestCase;
class EditorTest extends TestCase {
protected Editor $editor;
public function setUp(): void
{
parent::setUp();
$this->editor = Editor::new();
}
public function testSanity(): void
{
$this->assertEquals(0, $this->editor->numRows);
$this->assertNull($this->editor->syntax);
}
}

27
tests/RowTest.php Normal file
View File

@ -0,0 +1,27 @@
<?php declare(strict_types=1);
namespace Aviat\Kilo\Tests\Traits;
use Aviat\Kilo\{Editor, Row};
use PHPUnit\Framework\TestCase;
class RowTest extends TestCase {
protected Editor $editor;
protected Row $row;
public function setUp(): void
{
parent::setUp();
$this->editor = Editor::new();
$this->row = Row::new($this->editor, '', 0);
}
public function testSanity(): void
{
$this->assertEquals(0, $this->row->size);
$this->assertEquals(0, $this->row->rsize);
$this->assertEmpty($this->row->chars);
$this->assertEmpty($this->row->render);
}
}

33
tests/TermiosTest.php Normal file
View File

@ -0,0 +1,33 @@
<?php declare(strict_types=1);
namespace Aviat\Kilo\Tests\Traits;
use Aviat\Kilo\{Termios, TermiosException};
use PHPUnit\Framework\TestCase;
class TermiosTest extends TestCase {
public function testEnableRawMode(): void
{
// There will be an exception, due to the way the test suite is run
$this->expectException(TermiosException::class);
$this->assertNotEquals(NULL, Termios::enableRawMode());
}
/**
* @depends testEnableRawMode
*/
public function testEnableRowModeTwice(): void
{
$this->assertNull(Termios::enableRawMode());
}
/**
* @depends testEnableRawMode
*/
public function testDisableRawMode(): void
{
// There will be an exception, due to the way the test suite is run
$this->expectException(TermiosException::class);
$this->assertFalse(Termios::disableRawMode());
}
}

View File

@ -0,0 +1,60 @@
<?php declare(strict_types=1);
namespace Aviat\Kilo\Tests\Traits;
use Aviat\Kilo\Traits\MagicProperties;
use PHPUnit\Framework\TestCase;
class MagicPropertiesTest extends TestCase {
protected object $testClass;
public function __construct($name = NULL, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
$this->testClass = new class {
use MagicProperties;
protected string $foo = 'foo';
protected int $bar = 0x7b;
public function __get(string $name)
{
if ($this->__isset($name))
{
return $this->$name;
}
return NULL;
}
};
}
public function test__get(): void
{
$this->assertEquals('foo', $this->testClass->__get('foo'));
$this->assertNull($this->testClass->__get('fooBar'));
}
/**
* @depends test__get
*/
public function test__isset(): void
{
$this->assertTrue($this->testClass->__isset('foo'));
$this->assertFalse($this->testClass->__isset('fooBar'));
}
/**
* @depends test__get
*/
public function test__set(): void
{
$this->testClass->__set('foo', 'baz');
$this->assertEquals('baz', $this->testClass->__get('foo'));
$this->testClass->__set('baz', []);
$this->assertFalse($this->testClass->__isset('baz'));
$this->assertNull($this->testClass->baz);
}
}