Skip to content

Commit

Permalink
fix test action
Browse files Browse the repository at this point in the history
  • Loading branch information
mathroc committed Sep 23, 2024
1 parent c598221 commit 04863a4
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.2
FROM php:8.3

COPY dev.sh /tmp/library-scripts/

Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ jobs:
run: composer install --prefer-dist --no-progress

- name: Run the unit tests
run:
- vendor/bin/phpunit --version
- vendor/bin/phpunit --testdox
run: |
vendor/bin/phpunit --version
vendor/bin/phpunit --testdox
- name: Run the doc tests
run:
- vendor/bin/doctest --version
- vendor/bin/doctest
run: |
vendor/bin/doctest --version
vendor/bin/doctest
- name: Run linter
run:
- vendor/bin/phpcs --version
- vendor/bin/phpcs -ps
run: |
vendor/bin/phpcs --version
vendor/bin/phpcs -ps
- name: Run static analysis (PHPStan)
run:
- vendor/bin/phpstan --version
- vendor/bin/phpstan
run: |
vendor/bin/phpstan --version
vendor/bin/phpstan
- name: Run static analysis (Psalm)
run:
- vendor/bin/psalm --version
- vendor/bin/psalm
run: |
vendor/bin/psalm --version
vendor/bin/psalm
1 change: 1 addition & 0 deletions src/Option/None.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function mapOrElse(callable $callback, callable $default): mixed
* @template U
* @param Option<U> $option
* @return $this
* @psalm-suppress ImplementedReturnTypeMismatch
*/
public function zip(Option $option): self
{
Expand Down
1 change: 1 addition & 0 deletions src/Option/Some.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public function zip(Option $option): Option
return Option\some([$this->value, $value]);
}

/** @psalm-suppress InvalidReturnStatement */
return Option\none();
}

Expand Down
2 changes: 2 additions & 0 deletions src/functions/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ function tryOf(
* @template U
* @param Option<Option<U>> $option
* @return Option<U>
* @psalm-suppress InvalidReturnType
*/
function flatten(Option $option): Option
{
/** @psalm-suppress InvalidReturnStatement */
return $option instanceof Option\None
? $option
/** @phpstan-ignore missingType.checkedException */
Expand Down
21 changes: 7 additions & 14 deletions tests/Unit/Result/TrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,18 @@ public function testTrapOk(mixed $value): void
public function testTrapCheckedException(): void
{
Assert::assertEquals(
new \Exception(
"Failed to parse time string (nope) at position 0 (n): The timezone could not be found in the database",
),
new \Exception("Ooops"),
// @phpstan-ignore-next-line
Result\trap(static fn () => new \DateTimeImmutable("nope"))->unwrapErr(),
Result\trap(static fn () => throw new \Exception("Ooops"))->unwrapErr(),
);
}

public function testTrapUncheckedException(): void
{
try {
// @phpstan-ignore-next-line
Result\trap(static fn () => 1 / 0);
Assert::fail("An exception should have been thrown");
} catch (\DivisionByZeroError $ex) {
Assert::assertEquals(
"Division by zero",
$ex->getMessage(),
);
}
$this->expectException(\DivisionByZeroError::class);
$this->expectExceptionMessage("Division by zero");

// @phpstan-ignore-next-line
Result\trap(static fn () => 1 / 0);
}
}
23 changes: 9 additions & 14 deletions tests/type-hinting/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ function test_generic_type(Option $option): int
/** @psalm-suppress RedundantConditionGivenDocblockType 🎯 */
// @phpstan-ignore-next-line 🎯 Call to function is_string() with string will always evaluate to true.
if (\is_string($option->unwrap())) {
/**
* @psalm-suppress RedundantCondition πŸ™ˆ
* @psalm-suppress InvalidReturnStatement 🎯
*/
/** @psalm-suppress InvalidReturnStatement 🎯 */
// @phpstan-ignore-next-line 🎯 Function test_generic_type() should return int but returns string.
return $option->unwrap();
}
Expand All @@ -36,15 +33,12 @@ function test_generic_type(Option $option): int
function test_is_some(Option $option): int
{
if ($option->isSome()) {
/** @psalm-suppress MissingThrowsDocblock,RedundantCondition πŸ™ˆ */
/** @psalm-suppress MissingThrowsDocblock πŸ™ˆ */
// @phpstan-ignore-next-line πŸ™ˆ Function TH\Maybe\Tests\TypeHinting\test_is_some() throws checked exception RuntimeException but it's missing from the PHPDoc @throws tag.
return $option->unwrap();
}

/**
* @psalm-suppress RedundantConditionGivenDocblockType πŸ™ˆ
* @psalm-suppress MissingThrowsDocblock 🎯
*/
/** @psalm-suppress MissingThrowsDocblock 🎯 */
// @phpstan-ignore-next-line 🎯 Dead catch - RuntimeException is never thrown in the try block.
return $option->unwrap();
}
Expand All @@ -57,13 +51,13 @@ function test_is_none(Option $option): int
if ($option->isNone()) {
/**
* @psalm-suppress NoValue πŸ™ˆ
* @psalm-suppress MissingThrowsDocblock,TypeDoesNotContainType 🎯
* @psalm-suppress MissingThrowsDocblock 🎯
*/
// @phpstan-ignore-next-line 🎯 Function test_instanceof_none() throws checked exception RuntimeException but it's missing from the PHPDoc @throws tag.
return $option->unwrap();
}

/** @psalm-suppress MissingThrowsDocblock,RedundantCondition πŸ™ˆ */
/** @psalm-suppress MissingThrowsDocblock πŸ™ˆ */
// @phpstan-ignore-next-line πŸ™ˆ Function TH\Maybe\Tests\TypeHinting\test_is_none() throws checked exception RuntimeException but it's missing from the PHPDoc @throws tag.
return $option->unwrap();
}
Expand All @@ -74,7 +68,7 @@ function test_is_none(Option $option): int
function test_instanceof_some(Option $option): int
{
if ($option instanceof Option\Some) {
/** @psalm-suppress MissingThrowsDocblock,RedundantCondition πŸ™ˆ */
/** @psalm-suppress MissingThrowsDocblock πŸ™ˆ */
// @phpstan-ignore-next-line πŸ™ˆ Function TH\Maybe\Tests\TypeHinting\test_instanceof_some() throws checked exception RuntimeException but it's missing from the PHPDoc @throws tag.
return $option->unwrap();
}
Expand All @@ -90,7 +84,7 @@ function test_instanceof_some(Option $option): int
function test_instanceof_none(Option $option): int
{
if ($option instanceof Option\None) {
/** @psalm-suppress NoValue,MissingThrowsDocblock,TypeDoesNotContainType 🎯 */
/** @psalm-suppress NoValue,MissingThrowsDocblock 🎯 */
// @phpstan-ignore-next-line 🎯 Function test_instanceof_none() throws checked exception RuntimeException but it's missing from the PHPDoc @throws tag.
return $option->unwrap();
}
Expand All @@ -102,14 +96,15 @@ function test_instanceof_none(Option $option): int

function test_call_a_function_with_none(): void
{
/** @psalm-suppress InvalidArgument πŸ™ˆ Argument 1 of TH\Maybe\Tests\TypeHinting\option\test_is_none expects TH\Maybe\Option<int>, but TH\Maybe\Option\None provided */
here\test_is_none(Option\none());
}

function test_call_a_function_with_some(): void
{
here\test_is_none(Option\some(1));

/** @psalm-suppress InvalidArgument 🎯 */
/** @psalm-suppress InvalidScalarArgument 🎯 */
// @phpstan-ignore-next-line 🎯 Parameter #1 $option of function TH\Maybe\Tests\TypeHinting\option\test_is_none expects TH\Maybe\Option<int>, TH\Maybe\Option\Some<string> given.
here\test_is_none(Option\some("1"));
}
2 changes: 1 addition & 1 deletion tests/type-hinting/result.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function test_generic_type(Result $result): int
return $result->unwrap();
}

/** @psalm-suppress NoValue,TypeDoesNotContainType 🎯 This function or method call never returns output */
/** @psalm-suppress NoValue 🎯 This function or method call never returns output */
// @phpstan-ignore-next-line 🎯 Unreachable statement - code above always terminates.
return $result->unwrapErr();
}
Expand Down

0 comments on commit 04863a4

Please sign in to comment.