diff --git a/tests/cases/CLI/TestCLI.php b/tests/cases/CLI/TestCLI.php index 108e328..52e6cd0 100644 --- a/tests/cases/CLI/TestCLI.php +++ b/tests/cases/CLI/TestCLI.php @@ -115,7 +115,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { /** @dataProvider provideUserList */ public function testListUsers(string $cmd, array $list, int $exitStatus, string $output) { - // Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead + // FIXME: Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead Arsse::$user = $this->createMock(User::class); Arsse::$user->method("list")->willReturn($list); $this->assertConsole(new CLI, $cmd, $exitStatus, $output); @@ -134,7 +134,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { /** @dataProvider provideUserAdditions */ public function testAddAUser(string $cmd, int $exitStatus, string $output) { - // Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead + // FIXME: Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead Arsse::$user = $this->createMock(User::class); Arsse::$user->method("add")->will($this->returnCallback(function($user, $pass = null) { switch ($user) { @@ -157,7 +157,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { /** @dataProvider provideUserAuthentication */ public function testAuthenticateAUser(string $cmd, int $exitStatus, string $output) { - // Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead + // FIXME: Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead Arsse::$user = $this->createMock(User::class); Arsse::$user->method("auth")->will($this->returnCallback(function($user, $pass) { return ( @@ -180,7 +180,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { /** @dataProvider provideUserRemovals */ public function testRemoveAUser(string $cmd, int $exitStatus, string $output) { - // Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead + // FIXME: Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead Arsse::$user = $this->createMock(User::class); Arsse::$user->method("remove")->will($this->returnCallback(function($user) { if ($user == "john.doe@example.com") { @@ -200,7 +200,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest { /** @dataProvider provideUserPasswordChanges */ public function testChangeAUserPassword(string $cmd, int $exitStatus, string $output) { - // Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead + // FIXME: Phake is somehow unable to mock the User class correctly, so we use PHPUnit's mocks instead Arsse::$user = $this->createMock(User::class); Arsse::$user->method("passwordSet")->will($this->returnCallback(function($user, $pass = null) { switch ($user) { diff --git a/tests/cases/Misc/TestValueInfo.php b/tests/cases/Misc/TestValueInfo.php index e6dbdf4..b363dfa 100644 --- a/tests/cases/Misc/TestValueInfo.php +++ b/tests/cases/Misc/TestValueInfo.php @@ -411,26 +411,36 @@ class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest { [I::T_STRING, "String", ], [I::T_ARRAY, "Array", ], ]; + $assert = function($exp, $act, string $msg) { + if (is_null($exp)) { + $this->assertNull($act, $msg); + } elseif (is_float($exp) && is_nan($exp)) { + $this->assertNan($act, $msg); + } elseif (is_scalar($exp)) { + $this->assertSame($exp, $act, $msg); + } else { + $this->assertEquals($exp, $act, $msg); + } + }; foreach ($params as $index => $param) { list($type, $name) = $param; - $this->assertNull(I::normalize(null, $type | I::M_STRICT | I::M_NULL), $name." null-passthrough test failed"); + $assert(null, I::normalize(null, $type | I::M_STRICT | I::M_NULL), $name." null-passthrough test failed"); foreach ($tests as $test) { list($exp, $pass) = $index ? $test[$index] : [$test[$index], true]; $value = $test[0]; - $assert = (is_float($exp) && is_nan($exp) ? "assertNan" : (is_scalar($exp) ? "assertSame" : "assertEquals")); - $this->$assert($exp, I::normalize($value, $type), $name." test failed for value: ".var_export($value, true)); + $assert($exp, I::normalize($value, $type), $name." test failed for value: ".var_export($value, true)); if ($pass) { - $this->$assert($exp, I::normalize($value, $type | I::M_DROP), $name." drop test failed for value: ".var_export($value, true)); - $this->$assert($exp, I::normalize($value, $type | I::M_STRICT), $name." error test failed for value: ".var_export($value, true)); + $assert($exp, I::normalize($value, $type | I::M_DROP), $name." drop test failed for value: ".var_export($value, true)); + $assert($exp, I::normalize($value, $type | I::M_STRICT), $name." error test failed for value: ".var_export($value, true)); } else { - $this->assertNull(I::normalize($value, $type | I::M_DROP), $name." drop test failed for value: ".var_export($value, true)); + $assert(null, I::normalize($value, $type | I::M_DROP), $name." drop test failed for value: ".var_export($value, true)); $exc = new ExceptionType("strictFailure", $type); try { $act = I::normalize($value, $type | I::M_STRICT); } catch (ExceptionType $e) { $act = $e; } finally { - $this->assertEquals($exc, $act, $name." error test failed for value: ".var_export($value, true)); + $assert($exc, $act, $name." error test failed for value: ".var_export($value, true)); } } } diff --git a/tests/lib/AbstractTest.php b/tests/lib/AbstractTest.php index a75c339..6903dc0 100644 --- a/tests/lib/AbstractTest.php +++ b/tests/lib/AbstractTest.php @@ -61,7 +61,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { } } - protected function assertMessage(MessageInterface $exp, MessageInterface $act, string $text = null) { + protected function assertMessage(MessageInterface $exp, MessageInterface $act, string $text = '') { if ($exp instanceof ResponseInterface) { $this->assertInstanceOf(ResponseInterface::class, $act, $text); $this->assertEquals($exp->getStatusCode(), $act->getStatusCode(), $text); @@ -83,7 +83,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { $this->assertEquals($exp->getHeaders(), $act->getHeaders(), $text); } - public function assertTime($exp, $test, string $msg = null) { + public function assertTime($exp, $test, string $msg = '') { $test = $this->approximateTime($exp, $test); $exp = Date::transform($exp, "iso8601"); $test = Date::transform($test, "iso8601"); diff --git a/tests/lib/Database/Setup.php b/tests/lib/Database/Setup.php index 0a98edf..cc2b4bc 100644 --- a/tests/lib/Database/Setup.php +++ b/tests/lib/Database/Setup.php @@ -169,7 +169,7 @@ trait Setup { $found = array_search($row, $expected); unset($expected[$found]); } - $this->assertArraySubset($expected, [], "Expectations not in result set."); + $this->assertArraySubset($expected, [], false, "Expectations not in result set."); } } } diff --git a/tests/phpunit.xml b/tests/phpunit.xml index f2a4967..c8cbc94 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -7,7 +7,6 @@ convertWarningsToExceptions="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" - beStrictAboutTestSize="true" stopOnError="true">