Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dependent System with Laravel

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

Dependent System with Laravel

The story about how to make the dependent system with Laravel.

Avatar for Takuma Seno

Takuma Seno

October 22, 2016
Tweet

More Decks by Takuma Seno

Other Decks in Programming

Transcript

  1. サー ビス層とGuzzle u s e G u z z l

    e H t t p \ C l i e n t ; c l a s s S e r v i c e { p r o t e c t e d $ c l i e n t ; p u b l i c f u n c t i o n _ _ c o n s t r u c t ( C l i e n t $ c l i e n t ) { $ t h i s - > c l i e n t = $ c l i e n t ; } p u b l i c f u n c t i o n g e t ( ) { $ r e s p o n s e = $ t h i s - > c l i e n t - > r e q u e s t ( ' G E T ' , ' / ' ) ; . / / t r a n s f o r m t h e r e s p o n s e i n t o t h e m o d e l s . r e t u r n $ m o d e l s } }
  2. サー ビスの動作を確認 Guzzle はユニットテスト向けの機能が充実 $ m o c k =

    n e w M o c k H a n d l e r ( [ n e w R e s p o n s e ( 2 0 0 , [ ] , ' r e s p o n s e . . . ' ) ] ) ; $ h a n d l e r = H a n d l e r S t a c k : : c r e a t e ( $ m o c k ) ; $ c l i e n t = n e w C l i e n t ( [ ' h a n d l e r ' = > $ h a n d l e r ] ) ; $ s e r v i c e = n e w S e r v i c e ( $ c l i e n t ) ; $ m o d e l s = $ s e r v i c e - > g e t ( ) ; . / / c h e c k t h e r e s p o n s e . .
  3. コントロー ラのユニットテスト Mockery を使ってインスタンスをモックする c l a s s C

    o n t r o l l e r T e s t e x t e n d s T e s t C a s e { p u b l i c f u n c t i o n t e s t G e t ( ) { $ m o c k = M o c k e r y : : m o c k ( ' o v e r l o a d : A p p \ S e r v i c e ' ) ; $ m o c k - > s h o u l d R e c e i v e ( ' g e t ' ) - > a n d R e t u r n ( ' i d e a l m o d e l s ' ) ; $ t h i s - > v i s i t ( ' / s e r v i c e ' ) - > s e e J s o n ( [ / / i d e a l A P I r e s p o n s e ] ) ; } }