Tests for every class
This commit is contained in:
parent
513b5537a9
commit
eb116a5072
@ -17,8 +17,8 @@
|
|||||||
"phpunit/phpunit": "^8"
|
"phpunit/phpunit": "^8"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"coverage": "phpdbg -qrr -- vendor/bin/phpunit tests",
|
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c phpunit.xml tests",
|
||||||
"test": "vendor/bin/phpunit tests"
|
"test": "vendor/bin/phpunit -c phpunit.xml tests"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"ext-ffi": "*"
|
"ext-ffi": "*"
|
||||||
|
@ -7,14 +7,18 @@
|
|||||||
<filter>
|
<filter>
|
||||||
<whitelist>
|
<whitelist>
|
||||||
<directory suffix=".php">src</directory>
|
<directory suffix=".php">src</directory>
|
||||||
|
<exclude>
|
||||||
|
<file>src/constants.php</file>
|
||||||
|
</exclude>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="PHPKilo">
|
<testsuite name="PHPKilo">
|
||||||
<directory>tests</directory>
|
<directory phpVersion="7.4.0" phpVersionOperator=">=">tests</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<logging>
|
<logging>
|
||||||
<log type="coverage-html" target="coverage"/>
|
<log type="coverage-html" target="coverage"/>
|
||||||
|
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true" />
|
||||||
</logging>
|
</logging>
|
||||||
</phpunit>
|
</phpunit>
|
23
tests/EditorTest.php
Normal file
23
tests/EditorTest.php
Normal 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
27
tests/RowTest.php
Normal 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
33
tests/TermiosTest.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
60
tests/Traits/MagicPropertiesTest.php
Normal file
60
tests/Traits/MagicPropertiesTest.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user