Skip to content

Commit

Permalink
Tests: Actually run them
Browse files Browse the repository at this point in the history
It ends up the psalm warnings were useful in the last commit:

PHPUnit was quiting after the first throw exception.

To do more assertions, I am manually catching and checking.
  • Loading branch information
jarstelfox committed Dec 21, 2022
1 parent 2b33396 commit 5abacf7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
30 changes: 14 additions & 16 deletions tests/EitherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,27 @@ public function testCreateAndCheckExistenceWhen(): void {
$this->assertSame($rightThing4->rightOr(-5), 100);
}

/**
* @psalm-suppress UnevaluatedCode since php unit is catching the throw
* @psalm-suppress UnevaluatedCode since php unit is catching the throw
* @psalm-suppress UnusedMethodCall since php unit is catching the throw
*/
public function testValueOrThrow(): void {
$left = Either::left(1);
$this->assertSame($left->getLeft(), 1);

$this->expectException(MissingValueException::class);
$left->getRight();

$this->expectExceptionMessage("Right is missing.");
$left->getRight();
try {
/** @psalm-suppress UnusedMethodCall since php unit is catching the throw */
$left->getRight();
} catch(Exception $e) {
$this->assertTrue($e instanceof MissingValueException);
$this->assertSame("Right value is missing.", $e->getMessage());
}

$right = Either::right(1);
$this->assertSame($left->getRight(1), 1);

$this->expectException(MissingValueException::class);
$right->getLeft();

$this->expectExceptionMessage("Left is missing.");
$right->getLeft();
try {
/** @psalm-suppress UnusedMethodCall since php unit is catching the throw */
$right->getLeft();
} catch(Exception $e) {
$this->assertTrue($e instanceof MissingValueException);
$this->assertSame("Left value is missing.", $e->getMessage());
}
}

public function testGettingValue(): void {
Expand Down
17 changes: 7 additions & 10 deletions tests/OptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,19 @@ public function testCreateAndCheckExistence(): void {
$this->assertTrue($some->hasValue());
}

/**
* @psalm-suppress UnevaluatedCode since php unit is catching the throw
* @psalm-suppress UnevaluatedCode since php unit is catching the throw
* @psalm-suppress UnusedMethodCall since php unit is catching the throw
*/
public function testValueOrThrow(): void {
$some = Option::some(1);
$this->assertSame($some->value(), 1);

$none = Option::none();

$this->expectException(MissingValueException::class);
$none->value();

$this->expectExceptionMessage("Value is missing.");
$none->value();
try {
/** @psalm-suppress UnusedMethodCall since php unit is catching the throw */
$none->value();
} catch(\Exception $e) {
$this->assertTrue($e instanceof MissingValueException);
$this->assertSame("Value is missing.", $e->getMessage());
}
}

public function testCreateAndCheckExistenceWhen(): void {
Expand Down

0 comments on commit 5abacf7

Please sign in to comment.