Slide 1

Slide 1 text

࣮ફ%*ίϯςφ PO-BSBWFM !TPUB 1)1#-5

Slide 2

Slide 2 text

ࣗݾ঺հ w ਿӜᰜଠ 4PUB4VHJVSB w !TPUB w ΃ͪͺʔྺ೥ w גࣜձࣾΞΠελΠϧ೥໨ ʘ'PMMPXNFʗ

Slide 3

Slide 3 text

ΈΜͳʮ%*ศརͩͧʂʯ

Slide 4

Slide 4 text

๻ʮͲ͏͍͏෩ʹʜʁʯ

Slide 5

Slide 5 text

ͯ͜ͱͰ

Slide 6

Slide 6 text

%*ίϯςφͷ࿩Λ͠·͢ ஌ͬͯΔͧͬͯํ͸πΠολʔͯ͠Ͳ͏ͧ Ňŏ﹏ŏ

Slide 7

Slide 7 text

%*ͱ͸ w %*%FQFOEFODZ*OKFDUJPO w ʮґଘੑͷ஫ೖʯͱݴ͏ͱ͔ݴΘͳ͍ͱ͔ w ৄ͍͠આ໌͸࣌ؒͷ౎߹্Χοτ ứʆ

Slide 8

Slide 8 text

%*ίϯςφͱ͸ w %*ύλʔϯͰґଘղܾ͞ΕͨΠϯελϯεΛฦ ͯ͘͠ΕΔγϩϞϊ w ༷ʑͳ࣮૷͕͋Δ͕ɺ͜͜Ͱ͸-BSBWFMΛྫʹ

Slide 9

Slide 9 text

-BSBWFMʹ͓͚Δ %*ίϯςφ

Slide 10

Slide 10 text

%*$POUBJOFSPO-BSBWFM w ίϯετϥΫλͰλΠϓώϯτ͓͍ͯͨ͠Ϋϥε Λ%*ίϯςφ͕஫ೖͯ͘͠ΕΔ w ඞཁͳΫϥεʹ͞ΒʹඞཁͳΠϯελϯε͕͋ Ε͹࠶ؼతʹΠϯελϯεΛ஫ೖ͢Δ

Slide 11

Slide 11 text

%*$POUBJOFSPO-BSBWFM #SFBE

Slide 12

Slide 12 text

%*$POUBJOFSPO-BSBWFM #SFBE *OFFE #BDPO -FUUVDFBOE5PNBUP public function __construct( Bacon $bacon, Lettuce $lettuce, Tomato $tomato ) { // }

Slide 13

Slide 13 text

%*$POUBJOFSPO-BSBWFM %*$POUBJOFS (JWFZPV #SFBE *OFFE #BDPO -FUUVDFBOE5PNBUP #BDPO -FUUVDF 5PNBUP

Slide 14

Slide 14 text

%*$POUBJOFSPO-BSBWFM %*$POUBJOFS *OFFE4BMU #SFBE #BDPO -FUUVDF 5PNBUP public function __construct(Salt $salt) { // }

Slide 15

Slide 15 text

%*$POUBJOFSPO-BSBWFM %*$POUBJOFS (JWFZPV *OFFE4BMU #SFBE #BDPO -FUUVDF 5PNBUP 4BMU

Slide 16

Slide 16 text

%*$POUBJOFSPO-BSBWFM %*$POUBJOFS /FFE /FFE /FFE #SFBE #BDPO -FUUVDF 5PNBUP 4BMU /FFE

Slide 17

Slide 17 text

$MBTT#JOEJOH w %*ίϯςφʹ͋Β͔͡ΊΠϯελϯεΛಥͬࠐ ΊΔ

Slide 18

Slide 18 text

$MBTT#JOEJOH app->bind( // ίϯετϥΫλͰλΠϓώϯτ͞ΕΔΫϥε໊ \App\Dinners\PotatoTips::class, function ($app) { // ࣮ࡍʹฦ͞ΕΔΠϯελϯε return new \App\Dinners\Blt; } ); }

Slide 19

Slide 19 text

$MBTT#JOEJOHT "QQMJDBUJPO *OFFE 1PUBUP5JQT %*$POUBJOFS

Slide 20

Slide 20 text

$MBTT#JOEJOHT "QQMJDBUJPO *OFFE 1PUBUP5JQT %*$POUBJOFS $this->app->bind( \App\Dinners\PotatoTips::class, function ($app) { return new \App\Dinners\Blt; } );

Slide 21

Slide 21 text

$MBTT#JOEJOHT "QQMJDBUJPO *OFFE 1PUBUP5JQT %*$POUBJOFS (JWFZPV #MU

Slide 22

Slide 22 text

$MBTT#JOEJOHT "QQMJDBUJPO *OFFE 1PUBUP5JQT %*$POUBJOFS (JWFZPV #MU ˞௨ৗͷλΠϓώϯτͱಉ༷ɺ ܧঝؔ܎ʹͳ͍ͱΤϥʔʹͳΓ·͢

Slide 23

Slide 23 text

͜͜·Ͱલ࠲

Slide 24

Slide 24 text

ຊ୊ ͜ͷ%*ίϯςφ͕໾ʹཱͬͨ৔໘Λ͝঺հʂʂʂ

Slide 25

Slide 25 text

ͦͷ ࣮૷ͷࠩ͠ସ͑

Slide 26

Slide 26 text

Ғ͍ਓʮந৅ʹґଘͤΑʯ w Α͋͘Δ%*ίϯςφͷ࢖͍ํͱͯ͠ந৅Ϋϥε ʹ۩৅ΫϥεΛ$MBTT#JOEJOH͢Δ

Slide 27

Slide 27 text

*OUFSGBDFBOE$MBTT interface Burger { public function addTopping($toppingName); } class Blt implements Burger { public function addTopping($toppingName) { // } }

Slide 28

Slide 28 text

#JOE*OUFSGBDF /* in DI Container */ public function boot() { // ΠϯλʔϑΣʔεʹ۩৅ΫϥεΛbind // BurgerΠϯλʔϑΣʔεΛλΠϓώϯτ͢Δͱ // BltΫϥε͕஫ೖ͞ΕΔ $this->app->bind(Burger::class, Blt::class); }

Slide 29

Slide 29 text

ಥવͷϦΫΤετ ʮԶ͸#-5͡Όͳͯ͘ςϦϠΩόʔΨʔ͕৯΂͍ͨʯ

Slide 30

Slide 30 text

๻ʮطଘίʔυΛॻ͖׵͑ͣʹ ཁ๬ʹ౴͍͑ͨʯ

Slide 31

Slide 31 text

ͦ͏ͩʂந৅ͩʂ w ͜ͷ࣌ɺٻΊΒΕͯΔͷ͸#VSHFSΠϯλʔ ϑΣʔεΛ࣮૷ͨ͠৽ͨͳόʔΨʔ w ͭ·Γ಺෦తͳ࣮૷͕Ͳ͏มΘΖ͏ͱͦͷந৅ Λ࣮૷͢Ε͹ࠩ͠ସ͕͑Մೳ

Slide 32

Slide 32 text

/FX$MBTT interface Burger { public function addTopping($toppingName); } class Blt implements Burger { public function addTopping($toppingName) { // } } class Teriyaki implements Burger { public function addTopping($toppingName) { // } }

Slide 33

Slide 33 text

$IBOHF$MBTT#JOEJOH /* in DI Container */ public function boot() { // ݩʑͷΫϥε // $this->app->bind(Burger::class, Blt::class); // ৽ࠩ͘͠͠ସ͑ΔΫϥεΛBinding $this->app->bind(Burger::class, Teriyaki::class); }

Slide 34

Slide 34 text

.JTTJPO$PNQMFUF 㱼ʆ w ந৅ͱ%*ίϯςφΛ͏·͘ѻͬͯطଘίʔυʹ खΛೖΕͣʹ৽͍͠ίʔυʹࠩ͠ସ͑Δ͜ͱ͕ Մೳ w %*ίϯςφ͚ͩͷ࿩Ͱ͸ͳ͍ΜͰ͕͢ศརͩΑ ͱ͍͏ʜͶʜ

Slide 35

Slide 35 text

ͦͷ ςετ࣮૷

Slide 36

Slide 36 text

ྫ͑͹͜ΜͳςετΛॻ͖͍ͨ

Slide 37

Slide 37 text

501ϖʔδʹΞΫηεͨ͠Β ͪΌΜͱϖʔδ͕දࣔ͞ΕΔ͔

Slide 38

Slide 38 text

"QQMJDBUJPO5FTUJOH w %#ʹ໰͍߹Θͤͯฦ͖ͬͯͨ΋ͷ͕501ϖʔδ ʹग़Δ͸ͣʜ w ͖ͪΜͱɺ͔ͭ%#͔ΒͷϨεϙϯε͕ࡌͬ ͯΕ͹0,

Slide 39

Slide 39 text

"QQMJDBUJPO5FTUJOH /** * TOPϖʔδʹΞΫηεͨ͠Β’username'ͷจࣈྻ͕͋Γɺ * HTTPεςʔλείʔυ͕200Ͱ͋Δ͜ͱ */ public function testAccessTopPage() { $this->visit('/top') ->see(‘username') ->assertResponseOk(); }

Slide 40

Slide 40 text

೰Έ w ςετέʔε࣮ߦ͞ΕΔ౓ʹ%#ΞΫηε͢Δͷ πϥΠ w ੒ޭ༻ࣦഊ༻ͷσʔλΛέʔε͝ͱʹ༻ҙ͢Δ ͷπϥΠ w ςετલޙͰ%#ͷ͓૟আͱ͔πϥΠ

Slide 41

Slide 41 text

6TF%*$POUBJOFS ͦΕɺ%*ίϯςφͰղܾͰ͖·͢Α

Slide 42

Slide 42 text

$MBTT#JOEJOH w σʔλʹΞΫηεͯ͠ΔΫϥε΋%*ίϯςφ͔ Β஫ೖ͞Ε͍ͯΔ w ςετத͚ͩσʔλΞΫηεΫϥεʹߜͬͯϞο ΫΫϥεʹ#JOEJOHͯ͠͠·͑͹͓̺

Slide 43

Slide 43 text

.BLJOH.PDL$MBTT // σʔλΞΫηεΫϥεͷϞοΫ࡞੒ $userMock = \Mockery::mock(\User::class); $userMock->shouldReceive(‘getUsers')->andReturn('username');

Slide 44

Slide 44 text

#JOEJOH.PDL$MBTT // ϞοΫΫϥεΛBinding $this->app->bind(\User::class, function () use ($userMock) { return $userMock; });

Slide 45

Slide 45 text

5FTUJOH public function testAccessTopPage() { // σʔλΞΫηεΫϥεͷϞοΫ࡞੒ $userMock = \Mockery::mock(\User::class); $userMock->shouldReceive('getUsers')->andReturn('username'); // ϞοΫΫϥεΛBinding $this->app->bind(\User::class, function () use ($userMock) { return $userMock; }); // ςετ࣮ߦ $this->visit('/top') ->see('username') ->assertResponseOk(); }

Slide 46

Slide 46 text

.JTTJPO$PNQMFUF 㶅㱿㶅 w ष͍΋ͷʹ֖ςετͷ໨తΛՌͨͨ͢ΊʹΞϓ ϦέʔγϣϯͷҰ෦෼͚ͩϞοΫͰࠩ͠ସ͑Δ ͜ͱ͕Ͱ͖ͨʂ w ΞΫηεςετͰͳͯ͘΋͍Ζ͍Ζͳͱ͜ΖͰ Ԡ༻Մೳ w "1*ΞΫηεͷϞοΫͱ͔

Slide 47

Slide 47 text

·ͱΊ w %*ίϯςφ͸Ϋϥεͷґଘ͕ղܾ͞ΕͨΠϯε λϯεΛฦͯ͘͠ΕΔຐ๏ͷശ w ͏·͘པΕ͹ςετ΍࣮૷ͷࠩ͠ସ͕͑ͱͯ΋ ؆୯@ ᵇʮЏ @ w ΠέͯΔ%*ίϯςφϥΠϒϥϦ͸Ұഋ͋ΔͷͰ ֤ࣗ(PPHMFઌੜʂ

Slide 48

Slide 48 text

Ҏ্ʂ