Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Tests

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
name: PHP 8.4 Tests

steps:
- uses: actions/checkout@v4

- name: Setup PHP 8.4
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: xdebug
tools: composer:v2

- name: Validate composer.json
run: composer validate --strict

- name: Cache Composer packages
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-8.4-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-8.4-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run tests
run: composer test

- name: Generate coverage report
run: ./vendor/bin/phpunit --coverage-clover coverage.xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false

docker-test:
runs-on: ubuntu-latest
name: Docker Test

steps:
- uses: actions/checkout@v4

- name: Build Docker image
run: docker build -t php-result-test .

- name: Run tests in Docker
run: docker run --rm -v "$(pwd)":/app php-result-test ./vendor/bin/phpunit --testdox
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/composer.lock
/.phpstan/
/.phpunit.cache/
/.phpunit.result.cache
/coverage/
.DS_Store
/.php-cs-fixer.cache
Expand Down
12 changes: 11 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parameters:
level: max
paths:
- src
- tests
tmpDir: .phpstan
treatPhpDocTypesAsCertain: false
reportUnmatchedIgnoredErrors: true
Expand All @@ -13,4 +14,13 @@ parameters:
checkUninitializedProperties: true

# PHP 8.4 features
phpVersion: 80400
phpVersion: 80400

# テストコードで必要なパターンのみ許可(最小限)
ignoreErrors:
# テストでの型の不一致(意図的なテストケース)
-
message: '#Parameter .* expects .*, .* given#'
paths:
- tests/Unit/OkTest.php
- tests/Unit/ErrTest.php
42 changes: 42 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
stopOnFailure="false"
stopOnWarning="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutCoverageMetadata="true"
failOnEmptyTestSuite="true"
failOnIncomplete="false"
failOnRisky="false"
failOnSkipped="false"
failOnWarning="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true">
<testsuites>
<testsuite name="Unit Tests">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="php://stdout"/>
</report>
</coverage>
</phpunit>
9 changes: 5 additions & 4 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Result
* 結果が成功(Ok)の場合に true を返します.
*
* @phpstan-assert-if-true Ok<T> $this
* @phpstan-assert-if-false Err<E> $this
*
* @return bool
*/
Expand All @@ -34,6 +35,7 @@ public function isOkAnd(callable $fn): bool;
* 結果が失敗(Err)の場合に true を返します.
*
* @phpstan-assert-if-true Err<E> $this
* @phpstan-assert-if-false Ok<T> $this
*
* @return bool
*/
Expand All @@ -51,14 +53,14 @@ public function isErrAnd(callable $fn): bool;
/**
* 成功値を返します。失敗の場合は例外を投げます.
*
* @return T
* @return ($this is Ok<T> ? T : never)
*/
public function unwrap(): mixed;

/**
* エラー値を返します。成功の場合は例外を投げます.
*
* @return E
* @return ($this is Err<E> ? E : never)
*/
public function unwrapErr(): mixed;

Expand All @@ -67,7 +69,7 @@ public function unwrapErr(): mixed;
*
* @template U
* @param U $default
* @return T|U
* @return ($this is Ok<T> ? T : U)
*/
public function unwrapOr(mixed $default): mixed;

Expand Down Expand Up @@ -191,7 +193,6 @@ public function orElse(callable $fn): self;

/**
* 成功の場合はok_fnを、失敗の場合はerr_fnを適用します.
* RustのResult型のmatch式に相当する機能です.
*
* @template U
* @template V
Expand Down
Loading
Loading