Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PHPUnitの限界をPlaywrightで補完するテストアプローチ
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
yuzneri
July 18, 2025
Programming
1.2k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PHPUnitの限界をPlaywrightで補完するテストアプローチ
2025年7月18日
PHPカンファレンス関西2025
yuzneri
July 18, 2025
More Decks by yuzneri
See All by yuzneri
10秒ずつ届く推し
yuzneri
0
53
かわいい娘
yuzneri
0
69
人間の目はかわらない、でも、発表の届き方はかわる
yuzneri
0
92
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
20k
テーブルをDELETEした
yuzneri
0
200
昔つくったIoTデバイス
yuzneri
0
110
サークル参加から学ぶ、小さな事業の回し方
yuzneri
0
390
色を視る
yuzneri
0
590
ゲームと乱数
yuzneri
0
170
Other Decks in Programming
See All in Programming
スマート反転とウェブアクセシビリティ
camiha
0
210
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
500
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3.1k
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
170
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
1
560
Workers Cache を知る
syumai
0
180
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
430
Jetpack Compose メカニズム
skydoves
0
460
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
4
3.3k
FreeBSDでZabbixを動かす
kenkino
0
320
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
130
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
160
Featured
See All Featured
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
250
What's in a price? How to price your products and services
michaelherold
247
13k
Bash Introduction
62gerente
615
220k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
Writing Fast Ruby
sferik
630
63k
The agentic SEO stack - context over prompts
schlessera
0
940
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
Building Applications with DynamoDB
mza
96
7.2k
Transcript
PHPUnitの限界をPlaywright で補完するテストアプローチ 2025年7⽉18⽇ PHPカンファレンス関⻄2025
ゆずねり@yuzneri 2025/7/18 2 •バックエンド、たまにフロント エンドもさわる⼈ •技術同⼈誌の執筆 •ドール、ポーカー、謎解き 𝕏:@yuzneri
会員登録フォームを作りたい 2025/7/18 3 •会員IDのみのシンプル会員登録 •会員IDにはルールがある •→バリデーションを実装
validateメソッドを実装 public function validate(string $memberId) { $errors = []; if
(!$this->isAlphanumeric($memberId)) { $errors[] = '英数字のみ利用できます。'; } // 省略 return $errors; } 2025/7/18 4
PHPUnit •PHPアプリケーションのテストフレームワーク •PHPで書かれたコードを⾃動テスト •ロジックが正しく動くかどうか 2025/7/18 5
PHPUnitテスト public function testInvalidSpecialCharacters() { $controller = new MemberController(); $this->assertContains(
'英数字のみ利用できます。', $controller->validate('user@123') ); } 2025/7/18 6
画⾯を実装したけどテストは…? 2025/7/18 7
⾃動テストの種類 •ユニットテスト(単体テスト) •インテグレーションテスト(結合テスト) •E2Eテスト(End-to-End テスト) 2025/7/18 8
⾃動テストのテスト観点 • ユニットテスト • 単⼀のメソッド • 副作⽤がない • インテグレーションテスト •
複数のメソッドを統合 • 副作⽤はあっても良い 2025/7/18 9 • E2Eテスト • システム全体をユーザー⽬線
⾃動テストの範囲 2025/7/18 10 アカウント View HTML JS CSS DB アカウント
Model 削除メソッド 登録メソッド ユニットテスト アカウント Controller バリデーション メソッド ユニットテスト インテグレーションテスト E2Eテスト
PHPUnitでE2Eテストはできる? •ブラウザの挙動を再現できない •JavaScriptの動的処理 •デザイン •クッキーやローカルストレージを伴った画⾯遷移 2025/7/18 11
Playwright •マイクロソフト社が開発 •Webサイトのテストフレームワーク •Webブラウザを⾃動操作してテスト 2025/7/18 12
Playwrightの特徴 •Chromium、Firefox、WebKitを⾃動操作 •ユーザ⽬線に近い状態でテストできる •Windows、macOS、Linux、Dockerに対応 •Node.jsが⼊っていればすぐに動かせる •CI/CDで⾃動テストがやりやすい 2025/7/18 13
Playwrightテスト例 test('testInvalidSpecialCharacters', async ({ page }) => { await page.goto('http://localhost:8080');
await page.getByRole('textbox', { name: '会員ID' }) .fill('user@123'); await page.getByRole('button', { name: '登録' }).click(); await expect(page.locator('.error')) .toContainText('英数字のみ利用できます。'); }); 2025/7/18 14
URLを開く page.goto('http://localhost:8080') •ブラウザで指定したURLを開く 2025/7/18 15
要素を探す •タグにはロール(役割)が定義されている •例えば<input type="text">だと「textbox」 •PlaywrightのLocatorでロールを指定して要素 を選択する •UIの意味に基づくので壊れにくい 2025/7/18 16
Locaterでボタンを探す <button type="submit">登録</button> 2025/7/18 17 getByRole('button', { name: '登録' })
Locaterでテキストボックスを探す <label for="member_id">会員ID</label> <input type="text" id="member_id" name="member_id"> 2025/7/18 18 getByRole('textbox',
{ name: '会員ID' })
フォーム⼊⼒したりボタンを押したり page.getByRole(...).fill(id) page.getByRole(...).click() •fill()はフォーム⼊⼒ •click()はクリック 2025/7/18 19
テストする expect(page.locator('.error')) .toContainText('英数字のみ利用できます。') •expect()で要素を指定して •toContainText()で要素を確認する 2025/7/18 20
E2Eテストは時間とコストがかかる •テスト時にブラウザが動いている •同じようなテストケースでも時間がかかる • 6ケース実施すると • PHPUnit: 0.017秒 • Playwright:
2.000秒 (Chromiumのみ) •マシンスペックもある程度必要 2025/7/18 21
テストピラミッド 2025/7/18 22 E2Eテスト インテグレーション テスト ユニットテスト 速度 速い 遅い
コスト ⾼い 低い テストケース
PHPUnitの使い所 •ビジネスロジックとアプリケーションルールの テスト •バリデーションロジックを網羅的にテスト •DBにユーザーレコードが作成される 2025/7/18 23
Playwrightの使い所 •ユーザーのインタラクションと体験のテスト •なにかしらのバリデーションエラーメッセージが 表⽰される •会員登録完了画⾯まで表⽰される •デザインがくずれていない •テストがないコードのリファクタリング補助 2025/7/18 24
まとめ •PHPUnitはバックエンドを検証する礎 •Playwrightはユーザ体験の守護神 •お互いの特徴にあわせて適切に使い分けること で、より安⼼して開発できます 2025/7/18 25