Laravel Testing Decoded 日本語版
Laravel Testing Decoded 日本語版
待望のLaravel 4ユニットテスト解説本
本書について
(訳者注:この書籍の対象は、Laravel4.0です。 現行の4.2でも考え方の部分は利用できますが、Laravelを含め、紹介しているツール類の更新・進化もあり、本書通り動作しない部分が多くなっています。著者は新しいテストについての書籍を、この秋に出版するとつぶやきましたが、2015年1月に次期バージョンの5.0リリースが予定されており、変更点も多いため、たぶん新しいテスト本は大分遅れると思われます。)
何度も経験しました。アプリケーションが大きくなるにつれ、段々いい加減になり、テストしないソースコードも増えていくんです。そのうち、アプリケーションを手動でテストするのは現実的でなくなってきて、「無理だ!」という話しになります。そんな時こそ、自動テストが本当に必要なんだと、認識し始めるのです。もちろん、皆さんも過去にTDDに関する書籍を読んでいらっしゃるでしょう。しかし状況は多種多様で、突然やってくる素晴らしい幸福な瞬間、「ああ、そうだったのか」と理解できる時を味わうには、実際に試してみる経験が必要なのです。
テストにおける問題は唯一、技巧的に陥ってしまう可能性があることだけです。実際、今皆さんが取り掛かっているソースコードは、テストできない可能性が大きいでしょう! 皆さんがまだ実感していないのは、そうです、テストは自分のコードを期待通りに動かすのに役立ち、パターンに従えばより良い開発者になれることです。過去のプロジェクトではまった、ぐちゃぐちゃで、不安定なスパゲティーコードは、もう現れません。信じてください。すぐにあなたも、新しいコードを目の前にすると、微笑みを浮かべながら、「これはどうやったらテストできるかな」とつぶやき、過去の自分を振り返り、(荒っぽくて古い)カウボーイのようなやり方をしていたことを思い出し笑いだすでしょう。
近代的なソフトウェア開発へようこそ。
テストの原則(とTDD)は、言語に依存するものではありません。実践しようと思えば、様々なツールとテクニックに手が届きます。この本ではアプリケーションをテストするために、Laravelの手法を深く分析しつつ、可能な限りTDDについても紹介していきます。
(以上、Laravel Testing Decoded、日本語版本文より)
Laravel4を使用し、よくテストされた、Webアプリを構築したい開発者のために、PHPUnitを初め、Mockery、Codeceptionを使用し、ユニットテスト、結合(統合)テスト、受け入れテストを実施したい方向けの解説書です。対象は、実際にPHPでテストやTDDをどのように取り入れたら良いか迷っている方、Laravelのテスタビリティーに興味をお持ちの方、既にテスト駆動し開発している方々でLaravelでの適用知識を探していられる方です。
TDDが理想だが、実際に応用できない技術ではなく、行なってみれば楽しく、初めから誤りの少ないシステムを構築するには、必然であることを教えてくれます。
生涯に渡りアップデートは無料です。
購入された代金の10%はLaravelプロジェクト(Taylorさん)に寄付されます。
Table of Contents
-
日本語版前書き
- 日本語翻訳版について
-
ようこそ
- 始まったばかり
- この本はどんな人に役立つの?
- なぜLaravel限定なの?
- 演習
- 誤記
- この本を学び尽くす
- 連絡する
- 可能性に飛び込む
-
第1章 全てをテストする
- あなたは既にテストしている
- TDDから得られる6つのこと
- 何をテストすべきか?
- 不安定なコードの6つのサイン
- テスト関係の専門用語
- リラックス
-
第2章:PHPUnitの紹介
- インストール
- アサーション 110
- まとめ
-
第3章:PHPUnitの設定
- オプション
- XML設定ファイル
- 継続的テスト
- まとめ
-
第4章:PHPUnitのくどさを薄める
- アサーションを関数としてインポートする
- LaravelスタイルをPHPUnitに適用する
-
第5章:ユニットテスト110
- 我が苦闘
- ユニットテスト
- 準備、実行、断言
- 独立させてテストする
- テストは順番に依存してはならない
- テスト駆動開発
- 振る舞い駆動開発
- 関数をテストする
- クラスをテストする
- プロジェクトの完成
- まとめ
-
第6章:モデルをテストする
- 何をテストするのか
- アクセサー(ゲッター)とミューテーター(セッター)
- カスタムメソッド
- シンプルなクエリーテスト
- バリデーション
- ファクトリー
- Laravelテストヘルパー
- まとめ
-
第7章:Mockeryでテストを優しくする
- モックの解説
- インストール
- ジレンマ
- 解決策
- エクスペクティション(Expectation)
- パーシャル(部分的な)モック
- Hamcrest
- まとめ
-
第8章:データベースのテスト
- データベーステスト
- 環境を指定する
- テストからArtisanを呼び出す
- 実践してください
- メモリ上のデータベース
- まとめ
-
第9章:入れ替えましょう
- Mockery
- テスト
- まとめ
-
第10章:コントローラー
- コントローラーは何を行なっているか?
- コントローラーをテストする3ステップ
- コントローラーテストのHello World
- Laravelのヘルパーアサーション
- データベースをモックする
- リダイレクション
- パス
- リポジトリー
- 構造
- DOMクロール
- フォーム
- まとめ
-
第11章:IoCコンテナ
- 依存の注入?
- 解決
- Appバインド
- まとめ
-
第12章:テスト駆動Artisanコマンド演習
- コマンド110
- 演習
- まとめ
-
第13章:APIのテスト
- LaravelのAPI
- APIをテストする
- テストの例
- まとめ
-
第14章:Codeceptionによる受け入れテスト
- アミューズ・ブッシェ(食前のおつまみ)
- テストの気分転換
- インストール
- ブートストラップ
- 受け入れテストの設定
- テストを生成する
- まとめ
-
第15章:Codeceptionを使用した認証の実践
- 機能
- 機能をCodeception向けに変換する
- ルートの登録
- まとめ
-
第16章:Codeceptionでの機能テスト
- Laravel4モジュール
- TestGuyを更新する
- ユーザーを登録する
- まとめ
-
第17章:Travis CIで持続的インテグレーション
- Hello, Travis
- ビルド設定
- まとめ
-
よくある質問(生きているドキュメント)
- 1. グローバル関数はどうやってテストするのでしょうか?
- 2. Codeceptionのテストのため、どうやってSQLダンプを生成するのか?
- 3. Protectedメソッドはどうテストするのか?
- 4. ゲッターやセッターもテストすべきか?
- 5. どうしてPHPUnitは、フィルターを無視するのでしょうか?
- 6. テストしているクラスのメソッドをモックにできますか?
- 7. テスト名に下線を入れるのが好きなんです。それでも良いですか?
-
最後に
- ちょっと待ってください…
-
追補:Mockery
- モックオブジェクト
- 動作要件
- インストール
- 0.8.*へのアップデート
- シンプルなサンプル
- PHPUnit統合
- クイックリファレンス
- 期待値条件の宣言
- 引数のバリデーション
- パーシャルモックを作成する
- モックオブジェクトの検出
- デフォルトモック期待値条件
- パブリックなプロパティーのモック
- public staticメソッドのモック
- インスタンス化時にモックオブジェクトを生成する(インスタンス化モック)
- メソッドの参照渡し引数の動作を妨げる
- デメテルチェーンと流れるようなインターフェイス
- Mockery例外
- モックオブジェクトの記録
- Finalクラス/メソッドの取り扱い
- Mockeryグローバル設定
- 予約メソッド名
- PHPマジックメソッド
- なるほど!(了解事項)
- クイックサンプル
- Mockery ライセンス
- 追記
Authors have earned$9,882,857writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
Leanpubは無条件かつノーリスクで100%の満足を保証します
Leanpubでお買い上げいただいた書籍は、ご購入後45日以内であれば全額返金いたします。払い戻しはわずか2クリックで完了します。払い戻し処理は手作業で行うため、完了まで数日かかる場合があります。詳しくは利用規約をご覧ください。
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), EPUB (for phones and tablets) and MOBI (for 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
Top Books
C++ Best Practices
Jason TurnerLevel up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Functional Design and Architecture
Alexander GraninSoftware Design in Functional Programming, Design Patterns and Practices, Methodologies and Application Architectures. How to build real software in Haskell with less efforts and low risks. The first complete source of knowledge.
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
C++20
Rainer GrimmC++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
I am a Software Engineer and I am in Charge
Alexis Monville and Michael DoyleI am a Software Engineer and I am in Charge is a real-world, practical book that helps you increase your impact and satisfaction at work no matter who you work with.
In the book, we will follow Sandrine, a fictional character who learns to think in a new way enabling her to take a different course of action.
Invest In Digital Health - The Medical Futurist's Guide
Dr. Bertalan MeskoArtificial Intelligence and Digital Health are booming. In this book, we explain why now it's a good time to invest in Digital Health and give recommendations on where to invest by looking at the top 24 technological trends we find the most promising.
Atomic Kotlin
Bruce Eckel and Svetlana IsakovaFor both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
The Hundred-Page Machine Learning Book
Andriy BurkovEverything you really need to know in Machine Learning in a hundred pages.
Mastering STM32
Carmine NovielloWith more than 600 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the first guide around that introduces the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL.
Top Bundles
- #1
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
The Future of Digital Health
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy and how technology giants such as Amazon or Google want to conquer... - #3
Cisco CCNA 200-301 Complet
4 Books
Ce lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301. - #4
CCDE Practical Studies (All labs)
3 Books
CCDE lab - #5
"The C++ Standard Library" and "Concurrency with Modern C++"
2 Books
Get my books "The C++ Standard Library" and "Concurrency with Modern C++" in a bundle. The first book gives you the details you should know about the C++ standard library; the second one dives deeper into concurrency with modern C++. In sum, you get more than 600 pages full of modern C++ and about 250 source files presenting the standard library... - #6
Modern Management Made Easy
3 Books
Read all three Modern Management Made Easy books. Learn to manage yourself, lead and serve others, and lead the organization. - #7
Programming with Ease
3 Books
Alle drei Bände der Serie Programming with Ease in einem Paket. Darin findest du alles, was ich dir zu den wichtigsten Phasen der Softwareentwicklung im Hinblick auf Clean Code Development für langfristig hohe Produktivität sagen kann.Im Band Slicing findest du die Anforderungsanalyse im Rahmen eines iterativ-inkrementellen Vorgehensmodells aus... - #8
Vagrant Ansible
2 Books
Unveil the power of Ansible and Vagrant with this bundle at a special price. You'll have everything you need to get started with Vagrant - learn the basics and how to create your virtual development environments, using Ansible as provisioner! About Vagrant Cookbook Vagrant Cookbook is a complete guide to get started with Vagrant and create your... - #9
Mastering Containers
2 Books
Docker and Kubernetes are taking the world by storm! These books will get you up-to-speed fast! Docker Deep Dive is over 400 pages long, and covers all objectives on the Docker Certified Associate exam.The Kubernetes Book includes everything you need to get up and running with Kubernetes! - #10
Growing Agile: The Complete Coach's Guide
7 Books
Growing Agile: Coach's Guide Series This bundle provides a collection of training and workshop plans for a variety of agile topics. The series is aimed at agile coaches, trainers and ScrumMasters who often find themselves needing to help teams understand agile concepts. Each book in the series provides the plans, slides, handouts and activity...