Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?

テストを書くときにprotected,privateなプロパティを書き換えたいときがあります。 でも、なかなかそらで書けないのです。僕は。 だから、自分への戒めとして書いておきます。 (そもそもアクセスできないテストってどうなの、、、ってのはありますが、、、) リフレクションはこう!こう書く!!覚えろ!自分!! $reflection = new \ReflectionClass($Mailer); $property = $reflection->getProperty('oauth'); $property->setAccessible(true); $property->setValue($Mailer, true); $this->assertTrue($Mailer->getOAuth());
よくあることですが、PHPUnitでテストを書いている場合、テストケースが増えてくると徐々に実行速度が気になってきます。テストの量が増え、完了するまでの時間が単純に増えていくためです。 そんなとき、とにかくテストをさっさと終わらせるためのtipsです。 テストする量を減らす ローカルで開発するときは毎回すべてのテストを実行する必要はないかと思います。そんなときはテストする量自体を減らしましょう。 filter や group オプションを使用し特定のテストだけ実行すると、実行テストの総量が減り完了までの時間は短くなります。 参考: PHPUnit で指定したのテストのみを実行する また、PhpStormなどのエディタの機能を使えば特定のテストを実行することがエディタ上で可能になります。 参考: Testing with PHPUnit カバレッジを計測しない filter や group
何かと理由(時間がない || メンテが面倒)をつけて避けがちなユニット試験。 未だ関わる開発現場で全くユニット試験が書かれていないことも多い。 とは言え、急な仕様変更に伴うデグレ確認や後々の保守開発を考えれば必須かなと。 PHPでユニット試験といえばPHPUnitが有名。 CakePHP3上でコントローラのユニット試験を動かす時にちょっと詰まりました。 その時のメモ書き程度に残しておきます。 動作環境 PHP7.2 CakePHP3.6.9 MySQL5.7 環境構築 composerのパスを通していること. // CakePHP3初期化(プロジェクトが無い人) composer self-update && composer create-project --prefer-dist cakephp/app xxxx // PHPUnitインストール composer require --
About Xdebug is an extension for PHP to assist with debugging and development. It contains a single step debugger to use with IDEs; it upgrades PHP's var_dump() function; it adds stack traces for Notices, Warnings, Errors and Exceptions; it features functionality for recording every function call and variable assignment to disk; it contains a profiler; and it provides code coverage functionality f
» The full documentation » Installation This section describes on how to install Xdebug. » Basic Features Xdebug's basic functions include the display of stack traces on error conditions, maximum nesting level protection and time tracking. » Variable Display Features Xdebug replaces PHP's var_dump() function for displaying variables. Xdebug's version includes different colors for different types a
1. Description This document describes a simple protocol for use with language tools and engines for the purpose of debugging applications. It does not describe user interfaces or interactions with the debugger. The protocol provides a means of communication between a debugger engine (scripting engine, vm, etc.) and a debugger IDE (IDE, etc.). Any references to the debugger IDE UI are recommendati
Xdebug is an extension for PHP, and provides a range of features to improve the PHP development experience. Step Debugging A way to step through your code in your IDE or editor while the script is executing. Improvements to PHP's error reporting An improved var_dump() function, stack traces for Notices, Warnings, Errors and Exceptions to highlight the code path to the error Tracing Writes every fu
こんな「困った」時の話 「異常時に例外を投げる、正常に完了したらvoidとなる」というようなメソッドがあるとします。 こんな時に、PHPUnitでどのように単体テストを書けばいいでしょうか? PHPUnitでは、1つもassertionがないテストを「Risky」としてマークします。これは賢いのですが、しかし「返り値をとれないメソッド」=assertionを置けないテストケースについてRiskyになってしまうのが困る・・・と悩んでいました。 結論: @doesNotPerformAssertions を使えそう テストケースのアノテーションに @doesNotPerformAssertions を入れると、「これはリスキーじゃないぞ」という事を示すことができそうです。 以下、「こうやって対処してきた」「これからは@doesNotPerformAssertionsを使いたいかも」という話をし
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く