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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
400
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
160
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
150
OpenSpecのproposalにbrainstormingを持たせてみた
tigertora7571
1
180
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
130
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
520
Android CLI
fornewid
0
200
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
210
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
340
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
300
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
470
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
130
Featured
See All Featured
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
119
120k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
310
The Spectacular Lies of Maps
axbom
PRO
1
880
Writing Fast Ruby
sferik
630
63k
Un-Boring Meetings
codingconduct
0
360
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
The Limits of Empathy - UXLibs8
cassininazir
1
580
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.2k
Music & Morning Musume
bryan
47
7.3k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
380
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 ͷϝιουͷςετॻ͖ͮΒ͍😇
·ͱΊ ᶃ Ϣχοτςετ͕ॻ͖͍͢ઃܭߜΒΕΔ ᶄ ͷॴࡏ͕ڞଘ͍ͯ͠ΔͱɺςετΫϥε͕ཎΉ ᶅ ԿͰΔΫϥεɺςετ͕ͭΒ͍🥺