- はじめに
- 謝辞
- まえがき
- 訳者まえがき
-
1. 短気なプログラマのための PHPUnit
- 1.1 インストールと設定
- 1.2 実行可能な最小のテストクラス
- 1.3 テストで何が失敗したのかを分かりやすくするには
- 1.4 実行時オプションの設定
- 1.5 テスト環境の設定
- 1.6 テストコードの分類
-
2. テストダブル
- 2.1 テストダブルが必要な理由
- 2.2 テストダブルのパターン
- 2.3 ダミーオブジェクト
- 2.4 テストスタブ
- 2.5 テストスパイ
- 2.6 オブジェクトテスティングのその他のヒント
-
3. データプロバイダ
- 3.1 データプロバイダを使う理由
- 3.2 すべてのテストを見る
- 3.3 データプロバイダの作成
- 3.4 複雑な例
- 3.5 データプロバイダのトリック
-
4. テストデータの作成
- 4.1 データソースのスナップショット
- 4.2 必要なときはフェイクを作る
-
5. API のテスト
- 5.1 API とやりとりする部分のテスト
- 5.2 API コールのラップ
-
6. データベースのテスト
- 6.1 機能テスト vs ユニットテスト
- 6.2 サンドボックス
- 6.3 DBUnit
- 6.4 最初の DBUnit テスト
- 6.5 データベース接続のモック
- 6.6 モック vs フィクスチャ
-
7. 例外のテスト
- 7.1 アノテーションを使ったテスト
-
7.2
setExpectedExceptionを使ったテスト -
7.3
try-catchを使ったテスト
短気なプログラマのためのPHPUnitクックブック
The Grumpy Programmer's PHPUnit Cookbook
Minimum price
$29.00
$29.00
You pay
$29.00Authors earn
$23.20About
About the Book
「今までテストを書いたことがないから、そろそろテストを書かなくては・・・」という、PHPUnitもテストのこともまだ知らないプログラマにとって、一番最初に欲しいのは「何から始めたらよいのか」を知るためのガイドです。
本書は、PHPUnitを使ったテストの書き方を、短時間で知るための小冊子です。これだけ読めば、PHPUnitでテストを書いていけるようになります。
本書が特徴的なのは、ユニットテストの形式的な書き方だけを単純に説明した本ではないということです。本書では、PHPUnitによるテストを、オブジェクト指向の原則に沿った、良いコードへリファクタリングしていくための道具、と位置づけています。その流れに沿って、必要最低限の基礎知識や、実際にありそうなサンプルコードで使い方が説明されています。モック(テストダブル)を使ったテスト、フィクスチャを使ったテスト、APIのテストといった対象ごとのPHPUnitテストの書き方を、小さめの例で簡潔に説明しています。本書を読めば、どのようにテストを書いて行ったら良いのか、方向性をつかむことができるでしょう。
(以下は英語版紹介文です)
Learning how to use PHPUnit doesn't have to suck
Your code is untested and fixing bugs is tedious
You know you need something better, but time just doesn't seem to be on your side. Making things "right" is costly and you need to deliver working code NOW.
Writing tests is time-consuming and you're not sure how to fit it in
Tests would be great but there are real deadlines to meet. You can't stop development and churn away for hours just to add tests around what you know already works.
PHPUnit is the unit testing framework of choice, but it's intimidating
It looks hard to use and difficult to understand. You have little-to-no experience with it and just figuring out where to start feels daunting. You're left wondering how you use it to test all this stuff you're responsible for.
You don't have time to slow down development
You need to write solid, bug-free code, but your path is filled with manual tests and an application that breaks every time you change it.
You could go home from work, on-time and happy.
Life would be sweet with a solid set of tests
If you already had tests, you'd probably catch bugs faster.
You could refactor your code ruthlessly
Your tests would tell you when a requirements change broke something.
With tests, you'd push code to production with confidence
No longer would you dread the bug reports. You'd happily make changes knowing that your safety net is there. You'd try out new features guiding yourself with tests.
You can make this happen after reading "The Grumpy Programmer's PHPUnit Cookbook"
You'll know exactly how to tackle your existing code.
You'll know how to drive new features with your tests.
You'll write tests that run fast and keep you moving quickly.
Author
About the Authors
Chris Hartjes has been helping teams try and produce fewer bugs in production since 1998 with a recent focus on tools and test automation in PHP and Python.
He lives in the snowy wilds of Lucan, Ontario, Canada,

Episode 68
An Interview with Chris Hartjes
Contents
Table of Contents
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.