From eb116a507266f7dfeda1b2f05b37bbc1dd4539d4 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Tue, 19 Nov 2019 17:01:45 -0500 Subject: [PATCH] Tests for every class --- composer.json | 4 +- phpunit.xml | 6 ++- tests/EditorTest.php | 23 +++++++++++ tests/RowTest.php | 27 +++++++++++++ tests/TermiosTest.php | 33 +++++++++++++++ tests/Traits/MagicPropertiesTest.php | 60 ++++++++++++++++++++++++++++ 6 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 tests/EditorTest.php create mode 100644 tests/RowTest.php create mode 100644 tests/TermiosTest.php create mode 100644 tests/Traits/MagicPropertiesTest.php diff --git a/composer.json b/composer.json index 0e10641..6c6dcc4 100644 --- a/composer.json +++ b/composer.json @@ -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": "*" diff --git a/phpunit.xml b/phpunit.xml index eefb45a..d7cf015 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,14 +7,18 @@ src + + src/constants.php + - tests + tests + \ No newline at end of file diff --git a/tests/EditorTest.php b/tests/EditorTest.php new file mode 100644 index 0000000..c182967 --- /dev/null +++ b/tests/EditorTest.php @@ -0,0 +1,23 @@ +editor = Editor::new(); + } + + public function testSanity(): void + { + $this->assertEquals(0, $this->editor->numRows); + $this->assertNull($this->editor->syntax); + } +} \ No newline at end of file diff --git a/tests/RowTest.php b/tests/RowTest.php new file mode 100644 index 0000000..ca12c25 --- /dev/null +++ b/tests/RowTest.php @@ -0,0 +1,27 @@ +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); + } +} \ No newline at end of file diff --git a/tests/TermiosTest.php b/tests/TermiosTest.php new file mode 100644 index 0000000..674cf0e --- /dev/null +++ b/tests/TermiosTest.php @@ -0,0 +1,33 @@ +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()); + } +} \ No newline at end of file diff --git a/tests/Traits/MagicPropertiesTest.php b/tests/Traits/MagicPropertiesTest.php new file mode 100644 index 0000000..e0128cf --- /dev/null +++ b/tests/Traits/MagicPropertiesTest.php @@ -0,0 +1,60 @@ +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); + } +} \ No newline at end of file