Change functions to properties
- Force PHP 8.4
This commit is contained in:
@@ -18,76 +18,76 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
class ResultTest extends TestCase
|
||||
{
|
||||
#[TestDox('GetOK succeeds for OK result')]
|
||||
public function testGetOKSucceedsForOKResult(): void
|
||||
#[TestDox('OK property succeeds for OK result')]
|
||||
public function testOKPropertySucceedsForOKResult(): void
|
||||
{
|
||||
$result = Result::OK('yay');
|
||||
$this->assertEquals('yay', $result->getOK(), 'The OK result should have been returned');
|
||||
$this->assertEquals('yay', $result->ok, 'The OK result should have been returned');
|
||||
}
|
||||
|
||||
#[TestDox('GetOK fails for Error result')]
|
||||
public function testGetOKFailsForErrorResult(): void
|
||||
#[TestDox('OK property fails for Error result')]
|
||||
public function testOKPropertyFailsForErrorResult(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
Result::Error('whoops')->getOK();
|
||||
Result::Error('whoops')->ok;
|
||||
}
|
||||
|
||||
#[TestDox('GetError succeeds for Error result')]
|
||||
public function testGetErrorSucceedsForErrorResult(): void
|
||||
#[TestDox('Error property succeeds for Error result')]
|
||||
public function testErrorPropertySucceedsForErrorResult(): void
|
||||
{
|
||||
$result = Result::Error('boo');
|
||||
$this->assertEquals('boo', $result->getError(), 'The Error result should have been returned');
|
||||
$this->assertEquals('boo', $result->error, 'The Error result should have been returned');
|
||||
}
|
||||
|
||||
#[TestDox('GetError fails for OK result')]
|
||||
public function testGetErrorFailsForOKResult(): void
|
||||
#[TestDox('Error property fails for OK result')]
|
||||
public function testErrorPropertyFailsForOKResult(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
Result::OK('yeah')->getError();
|
||||
Result::OK('yeah')->error;
|
||||
}
|
||||
|
||||
#[TestDox('IsOK succeeds for OK result')]
|
||||
public function testIsOKSucceedsForOKResult(): void
|
||||
{
|
||||
$result = Result::OK('ok');
|
||||
$this->assertTrue($result->isOK(), 'The check for "OK" should have returned true');
|
||||
$this->assertTrue($result->isOK, 'The check for "OK" should have returned true');
|
||||
}
|
||||
|
||||
#[TestDox('IsOK succeeds for Error result')]
|
||||
public function testIsOKSucceedsForErrorResult(): void
|
||||
{
|
||||
$result = Result::Error('error');
|
||||
$this->assertFalse($result->isOK(), 'The check for "OK" should have returned false');
|
||||
$this->assertFalse($result->isOK, 'The check for "OK" should have returned false');
|
||||
}
|
||||
|
||||
#[TestDox('IsError succeeds for Error result')]
|
||||
public function testIsErrorSucceedsForErrorResult(): void
|
||||
{
|
||||
$result = Result::Error('not ok');
|
||||
$this->assertTrue($result->isError(), 'The check for "Error" should have returned true');
|
||||
$this->assertTrue($result->isError, 'The check for "Error" should have returned true');
|
||||
}
|
||||
|
||||
#[TestDox('IsError succeeds for OK result')]
|
||||
public function testIsErrorSucceedsForOKResult(): void
|
||||
{
|
||||
$result = Result::OK('fine');
|
||||
$this->assertFalse($result->isError(), 'The check for "Error" should have returned false');
|
||||
$this->assertFalse($result->isError, 'The check for "Error" should have returned false');
|
||||
}
|
||||
|
||||
#[TestDox('Bind succeeds for OK with OK')]
|
||||
public function testBindSucceedsForOKWithOK(): void
|
||||
{
|
||||
$result = Result::OK('one')->bind(fn($it) => Result::OK("$it two"));
|
||||
$this->assertTrue($result->isOK(), 'The result should have been OK');
|
||||
$this->assertEquals('one two', $result->getOK(), 'The bound function was not called');
|
||||
$this->assertTrue($result->isOK, 'The result should have been OK');
|
||||
$this->assertEquals('one two', $result->ok, 'The bound function was not called');
|
||||
}
|
||||
|
||||
#[TestDox('Bind succeeds for OK with Error')]
|
||||
public function testBindSucceedsForOKWithError(): void
|
||||
{
|
||||
$result = Result::OK('three')->bind(fn($it) => Result::Error('back to two'));
|
||||
$this->assertTrue($result->isError(), 'The result should have been Error');
|
||||
$this->assertEquals('back to two', $result->getError(), 'The bound function was not called');
|
||||
$this->assertTrue($result->isError, 'The result should have been Error');
|
||||
$this->assertEquals('back to two', $result->error, 'The bound function was not called');
|
||||
}
|
||||
|
||||
#[TestDox('Bind succeeds for Error')]
|
||||
@@ -95,7 +95,7 @@ class ResultTest extends TestCase
|
||||
{
|
||||
$original = Result::Error('oops');
|
||||
$result = $original->bind(fn($it) => Result::OK('never mind - it worked!'));
|
||||
$this->assertTrue($result->isError(), 'The result should have been Error');
|
||||
$this->assertTrue($result->isError, 'The result should have been Error');
|
||||
$this->assertSame($original, $result, 'The same Error result should have been returned');
|
||||
}
|
||||
|
||||
@@ -153,8 +153,8 @@ class ResultTest extends TestCase
|
||||
{
|
||||
$ok = Result::OK('yard');
|
||||
$mapped = $ok->map(fn($it) => strrev($it));
|
||||
$this->assertTrue($mapped->isOK(), 'The mapped result should be "OK"');
|
||||
$this->assertEquals('dray', $mapped->getOK(), 'The mapping function was not called correctly');
|
||||
$this->assertTrue($mapped->isOK, 'The mapped result should be "OK"');
|
||||
$this->assertEquals('dray', $mapped->ok, 'The mapping function was not called correctly');
|
||||
}
|
||||
|
||||
#[TestDox('Map fails for OK result when mapping is null')]
|
||||
@@ -174,7 +174,7 @@ class ResultTest extends TestCase
|
||||
$tattle->called = true;
|
||||
return 'hello';
|
||||
});
|
||||
$this->assertTrue($mapped->isError(), 'The mapped result should be "Error"');
|
||||
$this->assertTrue($mapped->isError, 'The mapped result should be "Error"');
|
||||
$this->assertFalse($tattle->called, 'The mapping function should not have been called');
|
||||
$this->assertSame($error, $mapped, 'The same "Error" instance should have been returned');
|
||||
}
|
||||
@@ -189,7 +189,7 @@ class ResultTest extends TestCase
|
||||
$tattle->called = true;
|
||||
return 'hello';
|
||||
});
|
||||
$this->assertTrue($mapped->isOK(), 'The mapped result should be "OK"');
|
||||
$this->assertTrue($mapped->isOK, 'The mapped result should be "OK"');
|
||||
$this->assertFalse($tattle->called, 'The mapping function should not have been called');
|
||||
$this->assertSame($ok, $mapped, 'The same "OK" instance should have been returned');
|
||||
}
|
||||
@@ -199,8 +199,8 @@ class ResultTest extends TestCase
|
||||
{
|
||||
$error = Result::Error('taco');
|
||||
$mapped = $error->mapError(fn($it) => str_repeat('*', strlen($it)));
|
||||
$this->assertTrue($mapped->isError(), 'The mapped result should be "Error"');
|
||||
$this->assertEquals('****', $mapped->getError(), 'The mapping function was not called correctly');
|
||||
$this->assertTrue($mapped->isError, 'The mapped result should be "Error"');
|
||||
$this->assertEquals('****', $mapped->error, 'The mapping function was not called correctly');
|
||||
}
|
||||
|
||||
#[TestDox('MapError fails for Error result when mapping is null')]
|
||||
@@ -246,15 +246,15 @@ class ResultTest extends TestCase
|
||||
public function testToOptionSucceedsForOKResult()
|
||||
{
|
||||
$value = Result::OK(99)->toOption();
|
||||
$this->assertTrue($value->isSome(), 'An "OK" result should map to a "Some" option');
|
||||
$this->assertEquals(99, $value->get(), 'The value is not correct');
|
||||
$this->assertTrue($value->isSome, 'An "OK" result should map to a "Some" option');
|
||||
$this->assertEquals(99, $value->value, 'The value is not correct');
|
||||
}
|
||||
|
||||
#[TestDox('ToOption succeeds for Error result')]
|
||||
public function testToOptionSucceedsForErrorResult()
|
||||
{
|
||||
$value = Result::Error('file not found')->toOption();
|
||||
$this->assertTrue($value->isNone(), 'An "Error" result should map to a "None" option');
|
||||
$this->assertTrue($value->isNone, 'An "Error" result should map to a "None" option');
|
||||
}
|
||||
|
||||
#[TestDox('Tap succeeds for OK result')]
|
||||
@@ -263,7 +263,7 @@ class ResultTest extends TestCase
|
||||
$value = '';
|
||||
$original = Result::OK('working');
|
||||
$tapped = $original->tap(function (Result $it) use (&$value) {
|
||||
$value = $it->isOK() ? 'OK: ' . $it->getOK() : 'Error: ' . $it->getError();
|
||||
$value = $it->isOK ? 'OK: ' . $it->ok : 'Error: ' . $it->error;
|
||||
});
|
||||
$this->assertEquals('OK: working', $value, 'The tapped function was not called');
|
||||
$this->assertSame($original, $tapped, 'The same result should have been returned');
|
||||
@@ -275,7 +275,7 @@ class ResultTest extends TestCase
|
||||
$value = '';
|
||||
$original = Result::Error('failed');
|
||||
$tapped = $original->tap(function (Result $it) use (&$value) {
|
||||
$value = $it->isOK() ? 'OK: ' . $it->getOK() : 'Error: ' . $it->getError();
|
||||
$value = $it->isOK ? 'OK: ' . $it->ok : 'Error: ' . $it->error;
|
||||
});
|
||||
$this->assertEquals('Error: failed', $value, 'The tapped function was not called');
|
||||
$this->assertSame($original, $tapped, 'The same result should have been returned');
|
||||
@@ -285,8 +285,8 @@ class ResultTest extends TestCase
|
||||
public function testOKSucceedsForNonNullResult(): void
|
||||
{
|
||||
$result = Result::OK('something');
|
||||
$this->assertTrue($result->isOK(), 'The result should have been "OK"');
|
||||
$this->assertEquals('something', $result->getOK(), 'The "OK" value was incorrect');
|
||||
$this->assertTrue($result->isOK, 'The result should have been "OK"');
|
||||
$this->assertEquals('something', $result->ok, 'The "OK" value was incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('OK fails for null result')]
|
||||
@@ -300,8 +300,8 @@ class ResultTest extends TestCase
|
||||
public function testErrorSucceedsForNonNullResult(): void
|
||||
{
|
||||
$result = Result::Error('sad trombone');
|
||||
$this->assertTrue($result->isError(), 'The result should have been "Error"');
|
||||
$this->assertEquals('sad trombone', $result->getError(), 'The "Error" value was incorrect');
|
||||
$this->assertTrue($result->isError, 'The result should have been "Error"');
|
||||
$this->assertEquals('sad trombone', $result->error, 'The "Error" value was incorrect');
|
||||
}
|
||||
|
||||
#[TestDox('Error fails for null result')]
|
||||
|
||||
Reference in New Issue
Block a user