Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
TDD視点から見る、Laravel・Requestクラスの依存性
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
stwile
February 22, 2021
Programming
150
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
TDD視点から見る、Laravel・Requestクラスの依存性
stwile
February 22, 2021
More Decks by stwile
See All by stwile
Fat Controller は悪か? ~光のFat Controller・闇のガリController~
stwile
2
1.9k
フレームワークが生み出す負債や複雑さに対して、PHPUnitと付き合っていく
stwile
1
2.8k
継続的にLaravelのUnitTestを書く上で 気をつけていること
stwile
1
250
Other Decks in Programming
See All in Programming
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
160
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
650
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
3
240
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
1
2k
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
190
AI時代に学ぶ 好きなルール 嫌いなルール Linter編
shorty5121
0
200
Oxlintはいいぞ(続)
yug1224
1
480
「つくるAI」だけではバグは見つからない ~テストに必要な「見つけるAI」を分離させる戦略~
mfunaki
0
200
Introducing Stack Pull Request in GitHub
kkamegawa
0
110
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.3k
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.8k
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
500
Featured
See All Featured
Six Lessons from altMBA
skipperchong
29
4.5k
The Curious Case for Waylosing
cassininazir
1
480
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
750
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
790
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Embracing the Ebb and Flow
colly
88
5.1k
WCS-LA-2024
lcolladotor
0
810
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Deep Space Network (abreviated)
tonyrice
0
270
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
250
Transcript
!IBOEN 5%%ࢹ͔ΒݟΔɺ 3FRVFTUΫϥεͷґଘੑ
!IBOEN ࣗݾհ hyroky . ઐྖҬɿ ɾόοΫΤϯυ ɾϢχοτςετ झຯɿ ɾಡॻ📓ʢॐɾපݪەɾమʣ ɾےτϨ🦾
LaravelͷϦΫΤετΫϥε͕Ͱ͖Δ͜ͱ • ݖݶνΣοΫ • όϦσʔγϣϯ • HTTPϦΫΤετใͷอ࣋ • HTTPϨεϙϯεॲཧͷ࣮
3FTQPOTF ใͷฦ٫ 3FRVFTU ใͷอ࣋ 7BMJEBUJPO ͷݕূ "VUIFOUJDBUJPO Ϣʔβೝূ LaravelͷRequestΫϥε͕࣋ͯΔ 3FRVFTU
$MBTT
όϦσʔγϣϯͷྫɿ class HogeRequest extends FormRequest { public function authorize(): bool
{ return true; } public function rules(): array { return [ 'name' => 'required|string|max:128', 'content' => 'required|string|max:500', ]; } public function attributes(): array { return ['name' => '໊લ','content' => '༰']; } protected function failedValidation(Validator $validator) { $errors = []; $validateErrors = $validator->errors()->toArray(); foreach ($validateErrors as $e) { $errors[] = $e[0]; } throw new HttpResponseException( response()->json($errors, 422) ); } } FormRequestΛܧঝ Α͋͘ΔFormRequestͷ֦ு • ೝূ • όϦσʔγϣϯϧʔϧͷఆٛ • όϦσʔγϣϯͰམͪͨͱ͖ͷ ڞ௨ॲཧ
͍ͭݟΔFormRequestͷܠ৭
ศརͳ໘… Ϣχοτςετ͕ ॻ͖ͮΒ͍😖
class HogeRequest extends FormRequest { public function authorize(): bool {
return true; } public function rules(): array { return [ 'name' => 'required|string|max:128', 'content' => 'required|string|max:500', ]; } public function attributes(): array { return ['name' => '໊લ','content' => '༰']; } protected function failedValidation(Validator $validator) { $errors = []; $validateErrors = $validator->errors()->toArray(); foreach ($validateErrors as $e) { $errors[] = $e[0]; } throw new HttpResponseException( response()->json($errors, 422) ); } } ιʔείʔυͱςετίʔυͷྫ class HogeRequestTest extends TestCase { /** * @dataProvider dataProvider */ public function test(array $param, array, $expected): void { $request = new Request(); $actual = Validator::make( $params, $request->rules(), $request->messages() ) ->errors() ->all(); parent::assertSame($expected, $actual); } public function dataProvider(): array { return [ 'ඞਢܥ NG' => [ [], ['໊લ͕ඞਢͰ͢ɻ','༰͕ඞਢͰ͢ɻ'], ], ] } } ᶃ ᶄ ᶅ
public function authorize(): bool { return true; } ιʔείʔυͱςετίʔυͷྫ ᶃ
ͷॏෳ ೝূͷͱόϦσʔγϣϯͷ͕ ڞଘ͍ͯ͠Δ ςετΫϥεͷจ຺͕ϒϨΔ → υΩϡϝϯτ📄ͱͯ͠ಡΈͮΒ͍😂 → ॻ͍͍ͯͯҧײ͕ग़Δ
ιʔείʔυͱςετίʔυͷྫ class HogeRequestTest extends TestCase { /** * @dataProvider dataProvider
*/ public function test(array $param, array, $expected): void { $request = new HogeRequest(); $actual = Validator::make( $params, $request->rules(), $request->messages() ) ->errors() ->all(); parent::assertSame($expected, $actual); } public function dataProvider(): array { return [ 'ඞਢܥ NG' => [ [], ['໊લ͕ඞਢͰ͢ɻ','༰͕ඞਢͰ͢ɻ'], ], ] } } ᶄ ෆཁͳґଘ ϧʔϧɾϝοηʔδͱ ࣮ߦͷॴࡏ͕ผΕ͍ͯΔ όϦσʔγϣϯ͚͍ͩͨ͠ͷʹɺ RequestΫϥεΛ ΠϯελϯεԽ͠ͳ͚ΕͳΒͳ͍ → ΩϞνϫϧΠ🤮
class HogeRequest extends FormRequest { protected function failedValidation( Validator $validator
) { $errors = []; $validateErrors = $validator->errors() ->toArray(); foreach ($validateErrors as $e) { $errors[] = $e[0]; } throw new HttpResponseException( response()->json($errors, 422) ); } } ιʔείʔυͱςετίʔυͷྫ ᶅ ϑϨʔϜϫʔΫґଘͷڧ͞ ϝοηʔδΛՃ͢ΔͨΊʹɺ ܧঝݩͷ࣮Λؾʹ͢Δ ϑϨʔϜϫʔΫͷଥڠ → ࣮ͷࣗ༝͕Լ͕Δ protected ͷϝιουͷςετॻ͖ͮΒ͍😇
·ͱΊ ᶃ Ϣχοτςετ͕ॻ͖͍͢ઃܭߜΒΕΔ ᶄ ͷॴࡏ͕ڞଘ͍ͯ͠ΔͱɺςετΫϥε͕ཎΉ ᶅ ԿͰΔΫϥεɺςετ͕ͭΒ͍🥺