1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 09:02:41 +00:00

Fixes for PHPUnit 7

This commit is contained in:
J. King 2018-12-07 13:49:49 -05:00
parent c63d24e125
commit f7b9a2a6cf
5 changed files with 25 additions and 16 deletions

View file

@ -115,7 +115,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
/** @dataProvider provideUserList */ /** @dataProvider provideUserList */
public function testListUsers(string $cmd, array $list, int $exitStatus, string $output) { 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 = $this->createMock(User::class);
Arsse::$user->method("list")->willReturn($list); Arsse::$user->method("list")->willReturn($list);
$this->assertConsole(new CLI, $cmd, $exitStatus, $output); $this->assertConsole(new CLI, $cmd, $exitStatus, $output);
@ -134,7 +134,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
/** @dataProvider provideUserAdditions */ /** @dataProvider provideUserAdditions */
public function testAddAUser(string $cmd, int $exitStatus, string $output) { 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 = $this->createMock(User::class);
Arsse::$user->method("add")->will($this->returnCallback(function($user, $pass = null) { Arsse::$user->method("add")->will($this->returnCallback(function($user, $pass = null) {
switch ($user) { switch ($user) {
@ -157,7 +157,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
/** @dataProvider provideUserAuthentication */ /** @dataProvider provideUserAuthentication */
public function testAuthenticateAUser(string $cmd, int $exitStatus, string $output) { 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 = $this->createMock(User::class);
Arsse::$user->method("auth")->will($this->returnCallback(function($user, $pass) { Arsse::$user->method("auth")->will($this->returnCallback(function($user, $pass) {
return ( return (
@ -180,7 +180,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
/** @dataProvider provideUserRemovals */ /** @dataProvider provideUserRemovals */
public function testRemoveAUser(string $cmd, int $exitStatus, string $output) { 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 = $this->createMock(User::class);
Arsse::$user->method("remove")->will($this->returnCallback(function($user) { Arsse::$user->method("remove")->will($this->returnCallback(function($user) {
if ($user == "john.doe@example.com") { if ($user == "john.doe@example.com") {
@ -200,7 +200,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
/** @dataProvider provideUserPasswordChanges */ /** @dataProvider provideUserPasswordChanges */
public function testChangeAUserPassword(string $cmd, int $exitStatus, string $output) { 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 = $this->createMock(User::class);
Arsse::$user->method("passwordSet")->will($this->returnCallback(function($user, $pass = null) { Arsse::$user->method("passwordSet")->will($this->returnCallback(function($user, $pass = null) {
switch ($user) { switch ($user) {

View file

@ -411,26 +411,36 @@ class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest {
[I::T_STRING, "String", ], [I::T_STRING, "String", ],
[I::T_ARRAY, "Array", ], [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) { foreach ($params as $index => $param) {
list($type, $name) = $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) { foreach ($tests as $test) {
list($exp, $pass) = $index ? $test[$index] : [$test[$index], true]; list($exp, $pass) = $index ? $test[$index] : [$test[$index], true];
$value = $test[0]; $value = $test[0];
$assert = (is_float($exp) && is_nan($exp) ? "assertNan" : (is_scalar($exp) ? "assertSame" : "assertEquals")); $assert($exp, I::normalize($value, $type), $name." test failed for value: ".var_export($value, true));
$this->$assert($exp, I::normalize($value, $type), $name." test failed for value: ".var_export($value, true));
if ($pass) { if ($pass) {
$this->$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_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_STRICT), $name." error test failed for value: ".var_export($value, true));
} else { } 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); $exc = new ExceptionType("strictFailure", $type);
try { try {
$act = I::normalize($value, $type | I::M_STRICT); $act = I::normalize($value, $type | I::M_STRICT);
} catch (ExceptionType $e) { } catch (ExceptionType $e) {
$act = $e; $act = $e;
} finally { } 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));
} }
} }
} }

View file

@ -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) { if ($exp instanceof ResponseInterface) {
$this->assertInstanceOf(ResponseInterface::class, $act, $text); $this->assertInstanceOf(ResponseInterface::class, $act, $text);
$this->assertEquals($exp->getStatusCode(), $act->getStatusCode(), $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); $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); $test = $this->approximateTime($exp, $test);
$exp = Date::transform($exp, "iso8601"); $exp = Date::transform($exp, "iso8601");
$test = Date::transform($test, "iso8601"); $test = Date::transform($test, "iso8601");

View file

@ -169,7 +169,7 @@ trait Setup {
$found = array_search($row, $expected); $found = array_search($row, $expected);
unset($expected[$found]); unset($expected[$found]);
} }
$this->assertArraySubset($expected, [], "Expectations not in result set."); $this->assertArraySubset($expected, [], false, "Expectations not in result set.");
} }
} }
} }

View file

@ -7,7 +7,6 @@
convertWarningsToExceptions="false" convertWarningsToExceptions="false"
beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true" beStrictAboutOutputDuringTests="true"
beStrictAboutTestSize="true"
stopOnError="true"> stopOnError="true">
<filter> <filter>