Y-KANOH
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    PHPerのための「PHPUnitの新バージョンを語り合う」PHP TechCafe ============================================ # PHPer's NEWS ::: info **[【W3Techs】2023年8月にWebで最も使われている技術はjQuery・Bootstrap・PHP・WordPress](https://qiita.com/rana_kualu/items/e23d728bb9b934069d8c)** ::: ::: info **[Publickeyが関連記事の動的生成をPHPとJavaScriptとMovableTypeで実装した方法とは?](https://www.publickey1.jp/blog/23/publickeyphpjavascriptmovabletype.html)** ::: ::: info **[CVE-2023-36844 And Friends: RCE In Juniper Devices](https://labs.watchtowr.com/cve-2023-36844-and-friends-rce-in-juniper-firewalls/)** ::: ::: info **[PHP Core Roundup #16](https://thephp.foundation/blog/2023/09/01/php-core-roundup-16/)** PDO driver specific sub-classes が、RFCはAcceptされたのに実装が間に合わず8.3に入らないとのこと、残念🥲 ::: ::: info **[We Are Looking for Developers to Join the PHP Foundation](https://thephp.foundation/blog/2023/09/06/application-form-2023/)** ::: ::: info **[PHP標準のアプリケーションサーバー「PHP-FPM」から「NGINX Unit」に乗り換えるだけで約8倍も応答速度が改善したというテスト結果](https://gigazine.net/news/20230913-nginx-unit/)** ::: ::: info **[PHPStanクイックガイド2023](https://zenn.dev/pixiv/articles/7467448592862e)** 今時PHPの開発してるなら静的解析入れたいですよね~ ::: ::: info **[Innovation Graph](https://innovationgraph.github.com/)** ::: ::: info **[AIに「深呼吸しよう」といった人間っぽい言葉をかけると問題の正答率が上昇するという研究結果](https://gigazine.net/news/20230921-ai-model-deep-breath-accuracy-improve/)** 別にオカルト的な藩士ではなく、学習もとデータで正解を導き出す前に使われている単語として認識しているみたい。 ::: ::: info **[PhpStorm Public Roadmap: What’s Coming in 2023.3](https://blog.jetbrains.com/phpstorm/2023/09/phpstorm-public-roadmap-whats-coming-in-2023-3/)** ::: ::: info **[Why does a backslash prefix improve PHP function call performance](https://www.deviaene.eu/articles/2023/why-prefix-php-functions-calls-with-backslash/)** 名前空間のことだとは認識していましたがあまり深く考えたことが無かったです。 ::: ::: info **[PHP and Multithreading: A Lighthearted Look at Concurrency](https://infinitypaul.medium.com/php-and-multithreading-a-lighthearted-look-at-concurrency-dac4540f3726)** Swoole と Fibers は知っていましたが、React PHP, PHP Parallel はあまり聞き馴染みがありませんでした。 ::: ::: info **[4 Ways To Call Python From PHP](https://dev.to/codeboxx/4-ways-to-call-python-from-php-5fa7)** exec() だろうなと思ったら、curl や fetch などもあり、なるほどと思いました。 ::: ::: info **[Support for Bun lands in Laravel Sail and Forge](https://laravel-news.com/laravel-sail-bun)** Laravel Sail や Forge で Bun をサポート。 社内でも「爆速肉まん」と言われていて少し話題になっていたので気になります。 ::: ::: info **[The Magic Behind PHP](https://tech.jotform.com/the-magic-behind-php-cc6ed3a00cf6)** こういう内容、定期的に振り返りたくなります ::: ::: info **[PHP 8.3.0 RC 2 available for testing](https://www.php.net/archive/2023.php#2023-09-14-1)** 引き続きウォッチしていきたいと思います ::: ::: info **[Unorthodox Eloquent](https://muhammedsari.me/unorthodox-eloquent)** あまり読めてませんが、Eloquent が何かと突っつかれている印象なので気になりました。 ::: ::: info **[A look at what's coming to Laravel 11](https://laravel-news.com/laravel-11)** Laracon の基調講演にて Taylor 氏が発表。 ::: ::: info **[PHPカンファレンス沖縄 開幕](https://phpcon.okinawa.jp/)** ::: ::: info **[株式会社サムライズム JetBrains IDEにブラウザ機能を追加するプラグイン – TamaCatを発表](https://samuraism.com/2023/09/26/14675)** PHPカンファレンス沖縄で触れられていたもの。 PhpStormでWebサイト確認ができるプラグイン ::: ::: info **[PHPカンファレンスは10/08開催](https://phpcon.php.gr.jp/2023/)** 加納も現地へ行きます ::: # 特集 ## PHPUnitの概要 [PHPUnitのトップページ](https://phpunit.de/) > PHPUnit は、プログラマ向けの PHP 用テストフレームワークです。ユニットテストフレームワークの xUnit アーキテクチャの一種です。 (原文) > PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. ### できること [ドキュメント](https://docs.phpunit.de/en/10.3/index.html) - 返り値のアサーション - 期待する例外のアサーション - データプロバイダー - 配列の内容を利用してテスト実行してくれる - 出力結果のアサーション - echoやprintなどで出力された結果のアサートができる - 不完全なテストのマーク - テストのスキップ - 属性を利用したテストのスキップ - 依存関係のテスト - 失敗理由の出力 - テストスタブ、モックオブジェクトの作成 ユニットテストフレームワークで実行したいことは一通り ## メンテナー [Sebastian Bergmann](https://sebastian-bergmann.de/) ### 導入手順 #### Composerを使ってPHPUnitをインストールする * `--dev`を忘れずに ``` composer require --dev phpunit/phpunit ``` #### PHP Archive (PHAR) を利用 * こちらが推奨されている * https://docs.phpunit.de/en/10.3/installation.html#php-archive-phar ### Hello World #### 準備 サンプルとしてテスト対象のクラス`Greeter`を作成。 ```php= <?php declare(strict_types=1); final class Greeter { public function greet(string $name): string { return 'Hello, ' . $name . '!'; } } ``` #### テストコードサンプル ```php= <?php declare(strict_types=1); use PHPUnit\Framework\TestCase; final class GreeterTest extends TestCase { public function testGreetsWithName(): void { // `Greeter`クラスの`greet`メソッドのテスト $greeter = new Greeter; $greeting = $greeter->greet('Alice'); // `greet`メソッドの返り値が`'Hello, Alice!'`と同じであることを確認 $this->assertSame('Hello, Alice!', $greeting); } } ``` ### 実行結果 ``` ./tools/phpunit tests/GreeterTest.php PHPUnit 10.3.0 by Sebastian Bergmann and contributors. Runtime: PHP 8.2.10 . 1 / 1 (100%) Time: 00:00, Memory: 22.46 MB OK (1 test, 1 assertion) ``` 1/1の結果で100%成功 [参考サイト](https://docs.phpunit.de/en/10.3/writing-tests-for-phpunit.html#asserting-return-values) # 簡単な使い方 ### テスト実行前後の処理 メソッドの呼び出しのたびに呼び出す処理の定義 * 事前処理:`setUp()`メソッド * 事後処理:`tearDown()`メソッド ##### setUp()メソッド クラスインスタンスの初期化などを必要なテストクラス共通の処理を分離させておきたいときに作成 ```php= class テストクラス名 extends TestCase { protected function setUp(): void { // テストメソッド実行前に行いたい処理 } } ``` ##### tearDown()メソッド リソースの解放(ファイルのクローズやDBとの接続の終了)など共通の処理を分離させたいときに作成 ```php= protected function tearDown(): void { // テストメソッド終了後に行いたい処理 } ``` ### アサーション 値を比較、検査して想定通りの値になっているかを確認するためのメソッド | メソッド | 役割 | 例文 | | ------------------------------- | ---------------------------------------- | -------------------------------------- | | assertSame(\$expected, \$actual) | \$expectedと\$actualが同じ型・同じ値かを検証する 配列は並び順が同じであるかも検証する | \$this->assertSame(100, 100); | | assertEquals(\$expected, \$actual) | \$expectedと\$actualが同じ値かを検証する 配列の並び順については検証しない | \$this->assertEquals(100, "100"); | | assertTrue(\$condition) | \$conditionがtrueかどうかを検証する | \$this->assertTrue(true); | | assertFalse(\$condition) | \$conditionがfalseかどうかを検証する | \$this->assertFalse(false); | | assertNull(\$variable) | \$variableがnullかどうかを検証する | \$this->assertNull(null); | | assertNotNull(\$variable) | \$variableがnullではないかを検証する | \$this->assertNotNull(null); | | assertCount(\$expectedCount, \$haystack) | \$haystack の要素数が \$expectedCount と等しいかを検証する | \$this->assertCount(1, ['aaa']); | | assertGreaterThan(\$expected, \$actual) | \$actual の値が \$expected の値より大きいかを検証する | \$this->assertGreaterThan(10, 100); | ### 例外のテスト 例外が発生したかどうかを判定する場合は`expectException()`メソッドを使用する ```php <?php use PHPUnit\Framework\TestCase; class テストクラス名 extends TestCase { public function テストメソッド() { $this->expectException(発生する例外クラス名::class); // 例外が発生する処理 } } ``` ### データプロバイダメソッド テストメソッドへの引数をまとめて記載することができるメソッドを作成することができる データプロバイダに指定するメソッドには、アノテーション @dataProvider を指定し、配列や反復が可能な値を返すようにする必要がある ```php <?php use PHPUnit\Framework\TestCase; class DataTest extends TestCase { /** * @dataProvider additionProvider */ public function testAdd($a, $b, $expected) { $this->assertEquals($expected, $a + $b); } public function additionProvider() { return [ [0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 3] ]; } } ?> ``` ### アノテーション 各テストメソッドに対するメタ情報 アノテーション自体は PHPDoc にも利用することがあるが、PHPUnit では各テストメソッドの依存関係を定義することなどが可能 ##### サンプル:@depends アノテーションが付与されたテストメソッド側で依存しているテストメソッドの戻り値を引数として受け取れる 記述方法は以下の通り ```php @depends + "テストメソッド名" ``` サンプルコード ```php <?php declare(strict_types=1); use PHPUnit\Framework\TestCase; final class StackTest extends TestCase { public function testEmpty(): array { $stack = []; $this->assertEmpty($stack); return $stack; } /** * @depends testEmpty */ public function testPush(array $stack): array { array_push($stack, 'foo'); $this->assertSame('foo', $stack[count($stack)-1]); $this->assertNotEmpty($stack); return $stack; } /** * @depends testPush */ public function testPop(array $stack): void { $this->assertSame('foo', array_pop($stack)); $this->assertEmpty($stack); } } ``` ### モック テスト時に、実際のオブジェクトの動作をシュミレートしてくれる模造品オブジェクトのこと 依存するオブジェクトが何らかの理由でテスト時に利用できないときに使用する たとえば、 - まだ実装されていない - APIを実行するオブジェクト - オブジェクトの依存関係をテストで使えない サンプルコード: https://phpunit.readthedocs.io/ja/latest/test-doubles.html#test-doubles-mock-objects ## PHPUnit8 [参考](http://blog.a-way-out.net/blog/2020/12/17/major-changes-in-phpunit-6-to-9/) ### [PHPUnit8.0](https://github.com/sebastianbergmann/phpunit/blob/8.0.0/ChangeLog-8.0.md#800---2019-02-01) #### Changed * #3060: Cleanup PHPUnit\Framework\Constraint\Constraint * #3133: 依存関係の解決をデフォルトで有効にする * #3236: Define which parts of PHPUnit are covered by the backward compatibility promise * #3244: デフォルトで結果キャッシュを有効にする * #3288: `php-cs-fixer`の`void_return` fixer が有効になりました * #3439: TestDox 出力の色を改善しました。 * #3444: 重複キーを持つデータを提供するデータプロバイダーは無効とみなすように修正 * #3467: Code location hints for @requires annotations as well as --SKIPIF--, --EXPECT--, --EXPECTF--, --EXPECTREGEX--, and --{SECTION}_EXTERNAL-- sections of PHPT tests * #3481: --help 出力の改善 #### Removed * #2762: **PHP 7.1の非対応化** * #3123: PHPUnit_Framework_MockObject_MockObject を削除 ### [PHPUnit8.1](https://github.com/sebastianbergmann/phpunit/blob/8.1.0/ChangeLog-8.1.md) #### Added * #3528: TestDox の進行状況アニメーションを無効にするオプション追加 * #3556: 構成ファイル経由で TestDox 結果プリンターを構成する * #3558: TestCase::getDependencyInput() * TestDox XML レポート内のテスト グループに関する情報は、テストの子ノードであるグループ要素でレポートされるようになりました。 * @covers および @uses アノテーションからの情報が TestDox XML でレポートされるようになりました * テストで使用されるテストダブルに関する情報が TestDox XML でレポートされるようになりました。 #### Changed * TestDox XML レポートのテスト要素のグループ属性は非推奨になりました ### [PHPUnit8.2](https://github.com/sebastianbergmann/phpunit/blob/8.2.0/ChangeLog-8.2.md) #### Added * #3506: PHP オプションは子プロセスに渡す必要があるようになります * #3586: コードカバレッジレポートの生成に費やした時間を表示します * #3682: phpunit.xml の --order-by オプションおよびexecutionOrder属性でdurationの使用を許可します。 #### Changed * #3122: テストダブルの戻り値の設定が間違っていることによる実行時の型エラーを防ぐ * #3708: 組み込みのアサーションとモック型の定義 ### [PHPUnit8.3](https://github.com/sebastianbergmann/phpunit/blob/8.3.0/ChangeLog-8.3.md) #### Added * #3687: *::setMethods() の代替として MockBuilder::addMethods() と MockBuilder::onlyMethods() を導入 * #3741: メソッド名と同じようにクラス名もフォーマットしてTestDoxに出力する * #3748: @small、@medium、@large からの情報に基づいてテストを並べ替えるオプションを追加 * TestCase::getActualOutput() のラッパーとして TestCase::getActualOutputForAssertion() を追加しました。これは、出力を表示するときにテストが危険としてマークされ、TestCase::expectOutputString() または TestCase::expectOutputRegEx() を使用してその出力が予期されないことを防ぐためです。 #### Changed * #2015: PHAR ディストリビューションにバンドルされているすべてのコードに、ランダム/一意の名前空間をプレフィックスとして付けます。 * #3503: エラー ハンドラーはグローバル状態に依存しないようにリファクタリングされました * #3521: 文書化されておらず、正しく動作しない機能を制御する @errorHandler アノテーションを無効化しました * #3522: Test Case::set UseErrorHandler() メソッドは、文書化されておらず、正しく動作しなかった機能を制御していましたが、廃止され、無効化されました * #3687: MockBuilder::setMethods() が非推奨になりました ### [PHPUnit8.4](https://github.com/sebastianbergmann/phpunit/blob/8.4.0/ChangeLog-8.4.md) #### Added * #3120: TestCase::createMock() の代替として TestCase::createStub() メソッドが用意されました * #3775: PHPのエラー、警告、通知を予期するための明示的な API ができました #### Changed * メソッド ExpectExceptionMessageRegExp() は非推奨になりました。 このバージョンの PHPUnit では動作の変更はありません。 このメソッドを使用すると、PHPUnit 9 で非推奨の警告がトリガーされ、PHPUnit 10 では削除されます。 代わりにexpectExceptionMessageMatches()を使用してください。 ### [PHPUnit8.5](https://github.com/sebastianbergmann/phpunit/blob/8.5.0/ChangeLog-8.5.md) #### Added * #3911: addMethods() とonlyMethods() の併用のサポート * #3949: assert を使用する代わりに、特殊なアサーションassertFileEqualsCanonicalizing()、assertFileEqualsIgnoringCase()、assertStringEqualsFileCanonicalizing()、assertStringEqualsFileIgnoringCase()、assertFileNotEqualsCanonicalizing()、assertFileNotEqualsIgnoringCase()、assertStringNotEqualsFileCanonicalizing()、およびassertStringNotEqualsFileIgnoringCase()を導入します。 FileEquals() など (オプションのパラメータ付き) #### Changed * #3860: クラス名のみを使用した PHPUnit コマンドライン テスト ランナーの呼び出しを非推奨にする * #3950: assertFileEquals() などのオプションのパラメータを非推奨にします。 * #3955: 複数のインターフェースの二重化のサポートを廃止 ## PHPUnit9 * [PHPUnit9](https://github.com/sebastianbergmann/phpunit/tree/9.6.12) * [PHPUnit 9時代のTest Doubleの作り方](https://speakerdeck.com/hgsgtk/deep-dive-into-mockbuilder-of-phpunit-9) ### PHPUnit9.0 #### Added * [#3797](https://github.com/sebastianbergmann/phpunit/pull/3797): Add support for multiple `--whitelist` options * コードカバレッジレポートに出力する対象とするファイルを複数指定できるようにする * これまでは1つのファイルしか設定できなかった * XMLの設定ファイルではこれまでも複数指定することができた * 開発時などに細かくカバレッジを確認したい場合、XMLの設定ファイルを修正するのは手間である * 開発時に修正したXMLの設定ファイルをリモートリポジトリにPUSHしてしまう事故も発生していた * `sebastianbergmann` 氏は複数のXMLファイルを受け付けれるように今後修正する予定であることを示したが上記については同意した模様で取り入れられた #### Removed * [#3334](https://github.com/sebastianbergmann/phpunit/issues/3334): Drop support for PHP 7.2 * **PHP7.2 のサポート終了** * [#3339](https://github.com/sebastianbergmann/phpunit/issues/3339): Remove assertions (and helper methods) that operate on (non-public) attributes * 属性を操作する各種アサーションとヘルパーメソッドを削除 * テストはプライベートな実装の詳細に依存すべきではない。 * このメソッドがあることで悪いテスト手法が蔓延することを防ぎたかった。 * (テスト設計の話になるため、正直あまりわかっていないです・・・) ### PHPUnit9.1 #### Added * [#4100](https://github.com/sebastianbergmann/phpunit/issues/4100): Implement `failOnIncomplete` and `failOnSkipped` configuration options as well as `--fail-on-incomplete` and `--fail-on-skipped` commandline options * テストがすべて成功しているが、不完全であったりスキップされたテストがある場合にエラーとする設定が追加された * テストが成功しているが不完全やスキップってどういう状況・・・? * [#4130](https://github.com/sebastianbergmann/phpunit/pull/4130): Canonicalize JSON values in failure message * JSONで出力されたエラーメッセージをJSONの形式で正しく出力する * 前後比較できていないのですが、[実装](https://github.com/sebastianbergmann/phpunit/pull/4130/files)を見たところ、これまではエラーメッセージのValue値などがJSONになっていなかったものと思われます。 * [#4136](https://github.com/sebastianbergmann/phpunit/pull/4136): Allow loading PHPUnit extensions via command-line options * CLI経由で PHPUnit の拡張を追加できるようにするオプション `--extensions ` が追加になった * [paraunit](https://github.com/facile-it/paraunit/) というPHPUnitのユニットテストを並列実行するためのツール開発者からの質問 * これまではXMLファイルを直接修正する必要があったが、設定ファイルを汚してしまうことのリスクなどからCLI経由でインポートできるようにしたいという要望があった * このPR でも触れられていますが、[Codecove](https://qiita.com/nasum/items/aff9bf09d49b136bbf94) 普通に便利そうですね。ユニットテストのカバレッジ監視にはすごく役立ちそうです。 #### Changed * [#4095](https://github.com/sebastianbergmann/phpunit/pull/4095): Improve performance of `StringContains` constraint * StringContains の高速化 * これまではいかなる文字の Contains もマルチバイト用の関数 [mb_stripos](https://www.php.net/manual/ja/function.mb-stripos.php) を利用していたが、マルチバイト文字の比較を行わない場合は [strpos](https://www.php.net/manual/ja/function.strpos) でよいはず、という指摘。 ### PHPUnit 9.2 #### Added * [#4224](https://github.com/sebastianbergmann/phpunit/issues/4224): Support for Union Types for test double code generation * テストダブルのための Union 型をサポート対象とした ### [9.3.0] - 2020-08-07 #### Added * [#3936](https://github.com/sebastianbergmann/phpunit/pull/3936): Support using `@depends` to depend on classes * `@depends` による依存の対象をクラス単位にできるようになった? * [#4325](https://github.com/sebastianbergmann/phpunit/issues/4325): Support PHP 8 * PHP8.0 をサポート対象に追加 ### [9.4.0] - 2020-10-02 #### Added * [#4462](https://github.com/sebastianbergmann/phpunit/pull/4462): Support for Cobertura XML report format * カバレッジレポートの出力オプション Cobertura をXMLで出力できるようになった。 * これにより、Cobertura のXMLを受けつけている外部ツールと連携しやすくなった模様 * [GitLabの例](https://gitlab-docs.creationline.com/ee/user/project/merge_requests/test_coverage_visualization.html) * [#4467](https://github.com/sebastianbergmann/phpunit/issues/4467): Convenient custom comparison of objects * オブジェクト用のアサーションメソッドが追加になった ### [9.5.0] #### Changed * [#4490](https://github.com/sebastianbergmann/phpunit/issues/4490): Emit Error instead of Warning when test case class cannot be instantiated * [#4491](https://github.com/sebastianbergmann/phpunit/issues/4491): Emit Error instead of Warning when data provider does not work correctly * [#4492](https://github.com/sebastianbergmann/phpunit/issues/4492): Emit Error instead of Warning when test double configuration is invalid * [#4493](https://github.com/sebastianbergmann/phpunit/issues/4493): Emit error when (configured) test directory does not exist * 各種、Warning レベルのものをErrorに引き上げる対応 * うっかりスルーしないようになった ### 9.6 は目立った新機能は無し おそらく、この時期に PHPUnit10 がリリースされたため? * 9.6 * 2023-02-03 * 10.0 * 2023-02-03 ## PHPUnit10 https://github.com/sebastianbergmann/phpunit/blob/10.0.0/ChangeLog-10.0.md#1000---2023-02-03 ### Added - テストイベントシステムの追加 - https://docs.phpunit.de/en/10.3/extending-phpunit.html#extending-the-test-runner 1. 関連するイベントのSubscriberを作成 2. Subscriberを設定するExtensionを作成 3. phpunit.xmlにExtensionを追加 - PHP8で実装されたアトリビュートの対応 - assertStringEqualsStringIgnoringLineEndings() - 行末文字を無視した文字列比較アサーション - OSの違いやGitの設定の違いによる行末文字の違いを無視して比較できる - assertIsList() - 配列のキーが0始まりの連番であるかを検証するアサーション - HTMLコードカバレッジレポートで使用される色を設定可能に - TestDoxのenumサポート - --display-○○オプションの追加 - デフォルトで表示されなくなったdeprecationやnoticeを表示させる - --no-○○オプションの追加 - 経過や結果などを表示しないようにできる ### Changed - キャッシュ - `<phpunit>` ルート要素に cacheDirectory 属性を導入 - PHPUnit テストランナーが使用するキャッシュディレクトリやキャッシュファイルを単一のルートディレクトリで設定できるように。 - PHPUnitではfieldをアトリビュートとずっと呼んでいるのでその呼称をプロパティに変更 - PHP8 で追加されたアトリビュートの影響 - data-providerメソッドの定義が厳格に - publicでないとdeprecated - staticでないとdeprecated - 引数を要求するとdeprecated - テストコードでE_DEPRECATED,E_NOTICE,E_STRICT,E_WARNINGが発生してもテストの実行が継続されるように - bootstrapスクリプトのスコープでグローバルな変数を、テストランナーのスコープでグローバル変数に昇格させなくなる - bootstrapでglobal変数を一覧定義などしている場合は動かなくなる - --stop-on-○○を使用した場合のみ、テストの実行が中断されるようになる - 今までと揃えたいのなら--step-on-defectを使用する ### Removed - 文法誤りや判断のしづらいメソッド名の修正 - 例:assertNotIsReadable() -> assertIsNotReadable() - assertEqualXMLStructure() - XML構造の検証に使用するアサート - deprecatedになり将来的に削除される - これ以外にもXML関係は削除されたものがちょこちょこある(--textdcx--xmlオプションなど) - 差別的用語の削除 - 例:Blacklist, --whitelist - 削除されたが代替手段の無いメソッド - at($index) - モックで使用 - 評価対象メソッドが$index回目に実行された際にマッチするオブジェクトを返す - withConsecutive(...$arguments) - テスト対象の呼び出しに合わせて、引数の配列を渡す - 個々の配列は制約リストになっており、モック対象メソッドのそれぞれの引数に対応する - class・オブジェクトのプロパティに対するアサーションの削除 - 例:assertObjectHasAttribute() - 修正例 ```php - $this->assertObjectHasAttribute('c', $sut->a->b); + $this->assertIsObject($sut->a->b); + $this->assertTrue(property_exists($sut->a->b, 'c')); ``` - expect○○()が一部削除 - 例:expectNotice,expectError - expectExceptionで代用は可能だが... - version10から特定のテストの結果やテスト自体の問題が発生しても例外を投げなくなったのでそもそも検知できない - TestListenerやTestHookの削除 - 新しいテストイベントシステムが追加された影響 - Testcaseの一部プロパティをアトリビュートへ - 例:PHPUnit\Framework\TestCase::$backupGlobalsExcludeList → #[ExcludeGlobalVariableFromBackup('variable')] - オプション削除 - --repeat,--debug,--verbose辺りは使っていた人もそこそこいるのでは - PHPバージョンサポート - 7.3,7.4,8.0を削除 * どのバージョンでどのアサートが増えて消えたか

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully