Travis CIで実現するPHPアプリの自動テスト
Transcript of Travis CIで実現するPHPアプリの自動テスト
![Page 1: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/1.jpg)
2014/6/28@yando
Travis CIで実現するPHPアプリの自動テスト
![Page 2: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/2.jpg)
yando
CandyCane / php
![Page 3: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/3.jpg)
書籍
Chef 実践入門 CakePHP2 実践入門 同姓同名
![Page 4: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/4.jpg)
自分小説家
安藤祐介
刀鍛冶
安藤祐介
![Page 5: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/5.jpg)
note.mu/yando
![Page 6: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/6.jpg)
![Page 7: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/7.jpg)
Yak Shaving
![Page 8: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/8.jpg)
![Page 10: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/10.jpg)
業務レベルのPaaS
PHP/Ruby/Node/Java
ご入用の際は是非
![Page 11: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/11.jpg)
![Page 12: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/12.jpg)
本日お話すること
なぜTravis CIなのか?
Travis CIの使い方
Travis CIで出来る様々なテスト
![Page 13: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/13.jpg)
なぜTravis CIなのか
![Page 14: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/14.jpg)
テストしてますか
![Page 15: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/15.jpg)
![Page 17: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/17.jpg)
Jenkins
![Page 18: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/18.jpg)
Jenkinsサーバの
構築・運用はつらい
![Page 19: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/19.jpg)
なぜか
![Page 20: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/20.jpg)
要求は異なる
アプリAの必要なPHP、DB、ソフト
アプリBの必要なPHP、DB、ソフト
アプリCの必要なRuby、DB、ソフト
![Page 21: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/21.jpg)
![Page 22: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/22.jpg)
つらいならやめよう
![Page 23: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/23.jpg)
継続的インテグレーション SaaS
2011年2月に誕生? ベルリン発
Mathias Meyer & Josh Kalderimis
テスト環境がオープンソース
Travis CI
![Page 24: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/24.jpg)
オープン、分散、即時
複数バージョンでの並行テスト
ライブラリ開発者、利用者
Higher Quality Code
Make the world a better place
特長
![Page 25: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/25.jpg)
![Page 26: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/26.jpg)
C C++ Clojure Erlang Go Groovy Haskell Java
JavaScript Objective-C Perl PHP Python Ruby Scala …
超対応
![Page 27: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/27.jpg)
Email IRC Campfire Flowdock
HipChat Sqwiggle Slack Webhook
通知も多彩
![Page 28: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/28.jpg)
オープンソース
無料
プライベート
$129 ~ $489 (並行ジョブ数が異なる)
リポジトリ数は無制限!
料金
![Page 29: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/29.jpg)
Travis CIの使い方
![Page 30: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/30.jpg)
Ubuntu 12.04 LTS Server Edition 64bit
テストごとにまっさらな環境
Chefで構築されている
テスト環境
![Page 31: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/31.jpg)
![Page 32: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/32.jpg)
コードをGitHubに置く
Travis CIからアカウント連携
該当リポジトリのスライダーをON
前提条件
![Page 33: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/33.jpg)
![Page 34: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/34.jpg)
Travis CIにCIの設定を指示
言語、バージョン、事前処理
テストに必要な鍵情報も書ける
文法チェックも可能
.travis.yml
![Page 35: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/35.jpg)
.travis.yml
![Page 36: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/36.jpg)
バージョン
![Page 37: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/37.jpg)
テストは?
賢いデフォルトに合わせると楽
phpunit
composer pyrus pearも使用可能
pecl apt-getもいける
![Page 38: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/38.jpg)
自由に設定
install:
before_install:
script:
![Page 39: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/39.jpg)
![Page 40: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/40.jpg)
![Page 41: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/41.jpg)
ビルドステータス
![Page 42: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/42.jpg)
おどろき
猛烈に簡単
猛烈に便利
![Page 43: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/43.jpg)
Travis CIで出来る
様々なテスト
![Page 44: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/44.jpg)
テストの再実行
ネットワークなどが原因の際
再実行すれば通る
落ち着いてWebのボタンを押す
![Page 45: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/45.jpg)
![Page 46: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/46.jpg)
Selenium Testing
Travis CIにはfirefoxが入っている
xVfbを起動してブラウザを起動
ブラウザを使ったテストを自動化
phpunitから制御
![Page 47: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/47.jpg)
Travis CI VMxVfbfirefox
JavaSelenium
PHP
WebApp
phpunit
![Page 48: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/48.jpg)
![Page 49: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/49.jpg)
![Page 50: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/50.jpg)
![Page 51: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/51.jpg)
暗号化
APIキーなどをそのままコミット?
travis gem でencrypt
.travis.yml に secure: ‘encrypted’
実行時にデコードして解釈
![Page 52: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/52.jpg)
暗号化の例
![Page 53: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/53.jpg)
Engine Yard連携
GitHubへコードをプッシュ
Travis CIがテストを実行
自動でEngine Yardへデプロイ!
![Page 54: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/54.jpg)
![Page 55: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/55.jpg)
iOS / Android
スマホアプリのCIも可能
OSXにXCodeが入ったVM
Android SDKも同様
Simulatorも入っている
![Page 56: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/56.jpg)
![Page 57: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/57.jpg)
![Page 58: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/58.jpg)
それでも自分で作る?
![Page 59: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/59.jpg)
![Page 60: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/60.jpg)
![Page 61: Travis CIで実現するPHPアプリの自動テスト](https://reader034.fdocument.pub/reader034/viewer/2022052214/55660231d8b42a2a4d8b4f8d/html5/thumbnails/61.jpg)
続きはブログで