ããã«ã¡ã¯ãæè¿ã¯ãè¶ã趣å³ãªãã§ããã¨ããã¨ã¾ãã§ãä¸åãªäººã®ããã«æãã¦ãã YamaYuski ã§ãã
ãã¦ãå··ã§ã¯ã©ããããã¦ããããã¹ãããªããã®ãï¼æ°å¹´åããï¼æµè¡ãã¦ããããã§ããã
å½æè¡ããã°ã§ãã
- PHP7 ã® assert ã«ããç°¡æãã¹ãã¯ãããã
- åå¿è ããã¹ãã³ã¼ããæ¸ãããã«ãªã£ãçµç·¯ã¨ãªã¹ã¹ã¡ã®ãã¹ããã¬ã¼ã ã¯ã¼ã¯
ã¨ãã¹ãã«é¢ããè¨äºãããã¾ãã
å¼ç¤¾ããæè¿ã®ããã¸ã§ã¯ãã§ã¯ãã¹ããæ¸ãåæã§PRãé£ã³äº¤ã£ã¦ãã¾ãã
èèã®(PHP5.2çã®æ代ãããã)ããããã¬ã¬ã·ã¼ã³ã¼ããä¿å®ããããã¸ã§ã¯ãã§ããæ°è¦ã«ãã¹ãã³ã¼ãã追å ãç¶ãã¦ããæãå¤ãã§ãã
ãã®ä¸ã§ä»åã¯ãPHPã®Webã¢ããªã±ã¼ã·ã§ã³ãã¬ã¼ã ã¯ã¼ã¯ Laravel ã«ããããã¹ãææ³ããç´¹ä»ãã¾ããå
å®ãããµãã¼ãã®ãããã§ãæ軽ã«ãã¹ããæ¸ãããã§ãï¼
Laravel ã®ãã¹ããµãã¼ãã¯ï¼
å
¬å¼ã®ããã¥ã¡ã³ãã¯ãã¡ãã§ãã
ç¾å¨ã Laravel 5.4 ã§ã¯ PHPUnit 5.7 ããã¼ã¹ãã¬ã¼ã ã¯ã¼ã¯ã¨ãã¦ãã¹ããè¡ããã¨ãåºæ¥ã¾ãã
ãã¡ããã Behat ã Codeception ãªã©ãä»ã®ãã¹ããã¬ã¼ã ã¯ã¼ã¯ãå©ç¨ãã¦
Laravel ã¢ããªã±ã¼ã·ã§ã³ããã¹ããããã¨ãå¯è½ã§ãããä»åã¯å¥ã®ã©ã¤ãã©ãªããã¬ã¼ã ã¯ã¼ã¯ã¯å
¥ãããç´ ã®ã¾ã¾ã® Laravel ãã¹ãã®ã¿è¸ã¾ãã¦ã¾ã¨ãã¦ãã¾ãã
Laravel ã¢ããªã±ã¼ã·ã§ã³ãä½æããæç¹ã§ãæ¢ã« vendor/bin/phpunit
ã¨ã³ãã³ããæã¦ã°ããã«ãã¹ããå®è¡åºæ¥ãã§ãããã
$ vendor/bin/phpunit PHPUnit 5.7.19 by Sebastian Bergmann and contributors. .. 2 / 2 (100%) Time: 872 ms, Memory: 6.00MB OK (2 tests, 2 assertions)
ããã Laravel ã¢ããªã±ã¼ã·ã§ã³ã§ã¯ãäºåã®è¨å®ãªãã§ããã«ãã¹ããæ¸ããã¨ãåºæ¥ãããã§ããã§ã¯æ©éæ¸ãå§ãã¾ãããã
ãã¹ãã®ç¨®é¡
Laravel ã§ã¯ã
- ã¢ããªã±ã¼ã·ã§ã³ãã¹ã
- ãã©ã¦ã¶ãã¹ã(â»Laravel 5.4以ä¸)
- æ®éã®ã¦ããããã¹ã
ãè¡ããã¨ãåºæ¥ã¾ãã
æ®éã®ã¦ããããã¹ãã¯è¨ãããããªã§ããã Laravel ã§ã¯è¿½å 㧠ã¢ããªã±ã¼ã·ã§ã³ãã¹ã åã³ ãã©ã¦ã¶ãã¹ã ãæ軽ã«è¡ããä»çµã¿ãããã£ã¦ãã¾ãã
ä¸ã¤ä¸ã¤ã¿ã¦ããã¾ãããã
ã¢ããªã±ã¼ã·ã§ã³ãã¹ã
ã¢ããªã±ã¼ã·ã§ã³ãã¹ã(HTTPãã¹ããFeatureãã¹ãã¨ã)ã¯ããã¹ãã±ã¼ã¹ãã¨ã«æ§ç¯ããã Laravel Application ã«å¯¾ãã¦ä»®æ³ã®ãªã¯ã¨ã¹ããæããã¬ã¹ãã³ã¹ã¨ãã¦è¿ã£ã¦ããã¬ã¹ãã³ã¹ã³ã¼ããjsonãæ£ãããã©ãããã§ãã¯ãããAPIã¬ãã«ã®ãã¹ãã§ãã
<?php namespace Tests\Feature; class BasicTest extends \Tests\TestCase { /** * é常ã®GETãªã¯ã¨ã¹ããæ£ããå¦çãããã */ public function testBasicTest() { $response = $this->get('/'); $response->assertStatus(200); } /** * ãã°ã¤ã³ããç¶æ ã§ãªã¯ã¨ã¹ããæ£ããå¦çãããã */ public function testLoggedIn() { $user = factory(\App\User::class)->create(); $response = $this->actingAs($user) ->get('/'); $response->assertStatus(200); } }
factory
ã«é¢ãã¦ã¯å¾è¿°ãã¾ããããã®ããã«è¨è¿°ããã ãã§ä»®æ³ã®HTTPãªã¯ã¨ã¹ããçæããã¬ã¹ãã³ã¹ãåå¾ãã¦ããã¾ãã
HTTPã¢ã¯ã»ã¹ã§ééããã³ã¼ãã®åºç¤çãªã¨ã©ã¼(useæ¼ããreturnå¿ããªã©)ã®ãã§ãã¯ã«æå¹ã§ãã
<?php namespace Tests\Feature; class JsonTest extends \Tests\TestCase { public function testJson() { $response = $this->json('POST', '/user', ['name' => 'Sally']); $response ->assertStatus(200) ->assertJson([ 'created' => true, ]); } }
ã¾ããjsonAPIã®ãã¹ãã«ããã¦ç価ãçºæ®ãã¾ãã
factory
ãªã©ã§å¿ è¦ãªãã¼ã¿ã®ç¨æ- ãªã¯ã¨ã¹ãã®éä¿¡
- ã¬ã¹ãã³ã¹ã®ã¢ãµã¼ã·ã§ã³
ã®ä¸ç¹ã«ãã¹ãã³ã¼ããéä¸ããããã¨ãåºæ¥ãã®ã§ãå°ãªãã³ã¼ãéã§é©åã«ãã¹ãã³ã¼ããè¨è¿°ãããã¨ãåºæ¥ã¾ãã
åæã«ãCookieãSessionæ
å ±ãæ£ããè¨å®ããã¦ãããã®ã¢ãµã¼ã·ã§ã³ãè¡ããã¨ãåºæ¥ã¾ããã
ãã©ã¦ã¶ãã¹ã
ãããä»åã®ç®çåå(æ©è½)ã§ãï¼
Laravel 5.4 ããã Laravel Dusk ã¨ããæ°ãããã¹ãã©ã¤ãã©ãªãå©ç¨ã§ããããã«ãªãã¾ããã
ãã®ã©ã¤ãã©ãªã¯ ChromeDriver ã¨ãããã©ã¦ã¶ãèªåæä½åºæ¥ãæ©è½ãæã£ã¦ãã¦ãèªåã§ãã©ã¦ã¶ã(å¥ããã»ã¹ã§)ç«ã¡ä¸ãã¦HTTPã¢ã¯ã»ã¹ãè¡ã£ãããDOMãjavascriptãæä½ããããã¾ãã
æºåã¯å°ãè¤éã§ãããä¸åº¦ç°å¢ãæ´ãã°ããã«ãã©ã¦ã¶ãã¹ããæ¸ããããã«ãªãã§ãããã
# å¥ãªãã¸ããªã«ãªã£ã¦ããã®ã§ composer require $ composer require "laravel/dusk" --dev # åæãã£ã¬ã¯ããªã»ãã¡ã¤ã«ã®çæ $ php artisan dusk:install
// app/Providers/AppServiceProvider.php ã«è¿½è¨ /** * Register any application services. * * @return void */ public function register() { if ($this->app->environment('local', 'testing')) { $this->app->register(\Laravel\Dusk\DuskServiceProvider::class); } }
ããã§åæåã¯å®äºã§ãã
å®éã®ãã¹ãå®è¡ã®ããã«ã¯ãäºåã«æ®éã«ãã©ã¦ã¶ããã¢ã¯ã»ã¹åºæ¥ãã¢ããªã±ã¼ã·ã§ã³ç°å¢(php artisan serveã§ãOK)ãç¨æãã¦ããå¿
è¦ãããã¾ãã
å®éã«å¥ããã»ã¹ã§ãã©ã¦ã¶ãç«ã¡ä¸ãã¦ããã¢ã¯ã»ã¹ããã®ã§ãå¿
é ã§ããã
ããã¦ããã®ã¢ããªã±ã¼ã·ã§ã³ç°å¢ã«ç¹ãããã .env ã® APP_URL ãè¨å®ãã¦ããã¾ãã
ã§ãå®éã«ãã¹ãã /tests/Browser/
å
ã«æ¸ãã¦ããã¾ãã
<?php namespace Tests\Browser; class ExampleTest extends \Tests\DuskTestCase { /** * ãã°ã¤ã³ãã¦ã¿ã */ public function testBasicExample() { $user = factory(\App\User::class)->create([ 'email' => '[email protected]', ]); $this->browse(function ($browser) use ($user) { $browser->visit('/login') ->type('email', $user->email) ->type('password', 'secret') ->press('Login') ->assertPathIs('/home'); }); } }
Laravel 5.3 ã¾ã§ãä¸è¨ ã¢ããªã±ã¼ã·ã§ã³ãã¹ã ã§è¡ã£ã¦ãããããªDOMæä½(type
ãpress
)ã®è¨è¿°ã§ããã¹ããæ¸ããã¨ãåºæ¥ã¾ãã
å®éã«å®è¡ããã«ã¯ã vendor/bin/phpunit
ã®ä»£ããã« php artisan dusk
ãå®è¡ãã¾ãã
$ php artisan dusk PHPUnit 5.7.19 by Sebastian Bergmann and contributors. . 1 / 1 (100%) Time: 9.37 seconds, Memory: 4.00MB OK (1 test, 1 assertion)
ãã®ã³ãã³ããå©ãã¨ãWindowsãªã©ã§åãããå ´åã¯èªåã§Chromeãã©ã¦ã¶ãç«ã¡ä¸ãã£ã¦ãæå®ãããå
¥åãåæã«è¡ã£ã¦ããã¾ãã
ãªããã«ãã³ã¤ã¤ã
â»ãã®Dusk Testãè¡ãããã«ã¯ãä¸è¨ã®ããã«ãã¹ãç°å¢ã«Chromium/Google Chromeãã©ã¦ã¶èªä½ãã¤ã³ã¹ãã¼ã«ããã¦ããå¿
è¦ãããã¾ãã
Linuxã§ãä»®æ³ãã£ã¹ãã¬ã¤ãä½æãããã¨ã§å¯¾å¿å¯è½ã§ãããä»åã¯ãã®ææ³ã«ã¤ãã¦ã¯çç¥ãã¾ãã
ã¾ãã以åã® Laravel ã§ã¯ç¢ºèªåºæ¥ãªãã£ãããã¼ãã¼ãã®1ãã¼åä½ã®å
¥åãããã¦ã¹ã®æä½ããjavascriptã®æä½ããè¡ããã¨ãåºæ¥ã¾ããããç¾å®ã®ã¦ã¼ã¶ãã¹ãã«è¿ãèªåãã¹ããå®ç¾ãããã¨ãåºæ¥ã¾ãããåãï¼
ãã©ã¦ã¶ã®æä½èªä½ã¯ facebook/php-webdriver ãå©ç¨ãã¦ããã®ã§ããã¡ãã®ããã¥ã¡ã³ããåèã«ããã¨ãããç確ãªæä½ã¨ã¢ãµã¼ã·ã§ã³ãè¡ããã®ã§ã¯ãªããã¨æãã¾ãã
ãã®ææ³ã¯ãéçºè
ãæ軽ã«å®éã®ãã©ã¦ã¶ã®èªåãã¹ããæ¸ããææ³ã¨ãããã¨ã§ãçããã«å¼·ããå§ããããæã§ãï¼
(çè
ã¯ã¾ã 5.3ç°å¢ãªã®ã§ä½¿ãã¦ããªã…ã)
æ®éã®ã¦ããããã¹ã
æ®éã« PHPUnit ã使ã£ã¦ãæ®éã«ç¹å®ã¯ã©ã¹ã®åæ©è½ãã¹ããè¡ãã¾ãã
æ®éã®ã¦ããããã¹ãã®ä½ãæ¹ã«ã¤ãã¦ã¯ä»åã¯çç¥ãã¾ãããå¾è¿°ã®ãµãã¼ãæ©è½ãä½µç¨ãã¦ããç°¡åã«æ¸ããã®ã§ã¯ãªããã¨æãã¾ãã
ã¦ããããã¹ããè¡ãã«ããã£ã¦ã
- ã¢ãã¯åãã¤ãããããããã¢ãã¯ã£ã¦ãªãã
- ãã¼ã¿ãã¼ã¹å¦çããã¹ã¦ã¢ãã¯ããã®ã¯ã¤ãã
- ãã¹ãã«å¿ è¦ãªãã¼ã¿ã®æºåãé¢å
ãªã©ãå
±éã®åé¡ç¹ãããèããã¾ãã
Laravel ã§ã¯ãããã£ãå
±é課é¡ã解決åºæ¥ãæ©è½ãæãã¦ããã®ã§ãããç°¡åã«ãããç´ æ©ããã¹ãã³ã¼ããè¨è¿°ãããã¨ãåºæ¥ã¾ãã
ã¢ãã¯å
ã¦ããããã¹ãã§ããã¹ã対象ã®ã¡ã½ãããä¾åãã¦ããå¤é¨ã®è¦ç´ (å¤é¨ã¯ã©ã¹ãDB)ã¯ãã¢ãã¯å (æ¡ä»¶çã§è²ã
ååãå¤ããã®ã§ãããããã§ã¯åã«ã¢ãã¯åã¨è¨ãã¾ã)ããè¡ãã¹ãã¨ããã¦ãã¾ãã
å¤é¨ä¾åã®ãã°ã§ãã¹ãã失æãããã¨ãé²ãããã§ããã¨ããå¤é¨ä¾åã®ããã®åæåå¦ç(ãã¼ã¿ã®æ¿å
¥ãªã©)ãè¡ãã¨ãã¦ããããã¹ãèªä½ã®ã³ã¼ãéãå¢ããè¦èªæ§ãæªããªã£ã¦ãã¾ãããã§ããã
ããã§ããã¹ã対象ã®ã¡ã½ãã以å¤ã®å¤é¨ã¯ã©ã¹ãDBæä½ãªã©ãã¢ãã¯åãã¦ããããããå¼æ°ã§ãã®ã¡ã½ãããå¼ãã ããããããæ»ãå¤ãè¿ããã¨ãã宣è¨ãäºåã«è¡ãã宣è¨éãã«æä½ãè¡ããããã©ãããã¢ãµã¼ã·ã§ã³ããã¢ãã¯ãªãã¸ã§ã¯ããå©ç¨ãã¦ãã¹ããè¡ãã¾ãã
ã¢ãã¯å㯠PHPUnit èªä½ã®æ©è½ã«å«ã¾ãã¦ãã¾ãã
<?php class ExampleTest extends TestCase { public function testObserversAreUpdated() { // Observer ã¯ã©ã¹ã®ã¢ãã¯ãä½æãã¾ãã // update() ã¡ã½ããã®ã¿ã®ã¢ãã¯ã§ãã $observer = $this->getMockBuilder(Observer::class) ->setMethods(['update']) ->getMock(); // update() ã¡ã½ãããä¸åº¦ã ãã³ã¼ã«ããããã®éã® // ãã©ã¡ã¼ã¿ã¯æåå 'something' ã¨ãªãã // ã¨ãããã¨ãæå¾ ãã¦ãã¾ãã $observer->expects($this->once()) ->method('update') ->with($this->equalTo('something')); // Subject ãªãã¸ã§ã¯ããä½æããObserver ãªãã¸ã§ã¯ãã® // ã¢ãã¯ãã¢ã¿ãããã¾ãã $subject = new Subject('My subject'); $subject->attach($observer); // $subject ãªãã¸ã§ã¯ãã® doSomething() ã¡ã½ãããã³ã¼ã«ãã¾ãã // ããã¯ãObserver ãªãã¸ã§ã¯ãã®ã¢ãã¯ã® update() ã¡ã½ãããã // æåå 'something' ãå¼æ°ã¨ãã¦ã³ã¼ã«ãããã¨ãæå¾ ããã¦ãã¾ãã $subject->doSomething(); } }
ãã®ãããªå½¢ã§ã¢ãã¯ãªãã¸ã§ã¯ããä½æããããããã¹ã対象ã®ã¯ã©ã¹ã«æ¸¡ãã¦ãã¹ããè¡ãã¾ãã
ã¾ããéçã¡ã½ãããå©ç¨ãã Facade 㯠Mockery ã¨ããã¢ããã³ã°ã©ã¤ãã©ãªãå©ç¨ãã¦ã¢ãã¯åãããã¨ãåºæ¥ã¾ãã
<?php class UserControllerTest extends TestCase { public function testGetIndex() { Cache::shouldReceive('get') ->once() ->with('key') ->andReturn('value'); $response = $this->get('/users'); // ... } }
ãã®ä»ã«ãã Laravel ã®å種æ©è½ã¯ãã¹ãããããããã¢ãã¯ã®æºåãåºæ¥ã¦ãã¾ãã詳ãã㯠Mocking – Laravel 5.4 ãã覧ãã ããã
…ãã®ã¢ãã¯ãªãã¸ã§ã¯ã宣è¨ãã¡ãã£ã¨é¢åã§ããããã£ã¨åãããããã¦ä½¿ããããã¢ãã¯åã¯åºæ¥ãªããã®ã§ããããã
ãã®çãã®ä¸ã¤ã« Prophecy ãããã¾ãã
Prophecy
Prophecy ã¯ããã©ã¦ã¶ãã¹ãã«ç¶ãä»åã¤ããªã·ã®ã©ã¤ãã©ãªã§ãï¼
ããã¯æè¿ã®PHPUnitã«å梱ãããããã«ãªã£ããæ°ããã®ã¢ããã³ã°ã©ã¤ãã©ãªã§ããå®éã®ã³ã¼ããè¦ã¦ã¿ã¾ãããã
<?php class ExampleTest extends TestCase { /** * PHPUnit ã®ã¢ãã¯ã使ã£ãå®è£ */ public function testObserversAreUpdatedWithPhpunitMock() { // ã¢ãã¯ã®çæ $observer = $this->getMockBuilder(Observer::class) ->setMethods(['update']) ->getMock(); // ã¢ãã¯ã®å®£è¨ $observer->expects($this->once()) ->method('update') ->with($this->equalTo('something')); // å®è¡ $subject = new Subject('My subject'); $subject->attach($observer); $subject->doSomething(); } /** * Prophecy ã使ã£ãå®è£ */ public function testObserversAreUpdatedWithProphecy() { // ã¢ãã¯ã®çæ $observer = $this->prophesize(Observer::class); // ã¢ãã¯ã®å®£è¨ $observer->update('something') ->shouldBeCalled(); // å®è¡ $subject = new Subject('My subject'); $subject->attach($observer->reveal()); $subject->doSomething(); } }
ãã¦ãä¸è¨ã®ã³ã¼ãäºã¤ãæ¯ã¹ã¦ãã©ã¡ããè¯ãã¨æãã¾ããï¼ç§ã¯ä¸ã® Prophecy
ãã³ã¼ãéãå°ãªããç´æçãªå®£è¨ãè¡ããã®ã§åãããããã¨æã£ã¦ãã¾ãã
ããã¯ã«ãªãã®ã¯ $subject->attach($observer->reveal());
ã¨ãã¤ã³ã¹ã¿ã³ã¹ã渡ãæã®ã¡ã½ãããå¢ãã¦ããç¹ã§ããã
ãããæ¯åå¿ãã¦è¬ã®ã¨ã©ã¼ãåºã¾ãã
ãããé¤ãã°ãã·ã³ãã«ãªå®£è¨ã§ã¢ãã¯åãè¡ããã®ã§ãæ¯éãªã¹ã¹ã¡ãããæã
ãã¼ã¿ãã¼ã¹ãå©ç¨ãããã¹ã
ãã¸ãã¯ã®ä¸ã§DBã®æä½ã¯å¤§ããªæ¯éãæã£ã¦ãã¾ãããããã®DBã®æä½ãå
¨ã¦ã¢ãã¯åããã®ã¯é常ã«å¤§å¤ã§ãã
ããã§ã Laravel ã§ã¯ãå¿
è¦ãªDBã®ã¬ã³ã¼ããç°¡åã«çæãããã®ã¬ã³ã¼ããå©ç¨ãããã¹ããè¡ããæ£ããã¬ã³ã¼ããæ´æ°ããããããã§ãã¯ããä»çµã¿ãç¨æããã¦ãã¾ãã
æ軽ãªã¬ã³ã¼ãçæ
Laravel ã«ã¯ DatabaseFactory ã¨ãããã®ãåå¨ãã¾ãã
ããã¯ãäºåã«å Model ã®æ
å ±ãçæãã¦ãããã¨ã§ããã¹ãæã«ç°¡åã« Model ã
new/insert åºæ¥ãä»çµã¿ã§ãã
$factory->define(App\User::class, function (Faker\Generator $faker) { return [ 'name' => $faker->name, 'email' => $faker->unique()->safeEmail, 'password' => bcrypt('secret'), 'remember_token' => str_random(10), ]; });
Factory ãã¡ã¤ã«ã«ãã®ããã«å®ç¾©ããã¨ããã¹ãæã«
<?php namespace Tests\Feature; class BasicTest extends \Tests\TestCase { /** * ãã°ã¤ã³ããç¶æ ã§ãªã¯ã¨ã¹ããæ£ããå¦çãããã */ public function testLoggedIn() { // Model ã®çæ(+ insert) $user = factory(\App\User::class)->create(); $response = $this->actingAs($user) ->get('/'); $response->assertStatus(200); } }
factory
ã°ãã¼ãã«é¢æ°ãå¼ã¶ã ãã§ããã®ã¢ãã«ãçæåºæ¥ã¾ãã
->create();
ã¨ãããã¨ã§ INSERT ãåæã«è¡ãã¾ãã
ã¾ãããã¼ã¿ã¹ã¼ã¹ã®æ´æ°ãè¡ããããã®ãã¹ããè¡ãããã®ã¡ã½ããã¨ãã¦
$this->assertDatabaseHas('users', [ 'email' => '[email protected]' ]);
ã¨ãã£ããã®ãããã¾ããããã§ã
- åä½ç¨ã®ãã¼ã¿ã®æºå
- åä½å¾ã®ãã¼ã¿å¤åã®ã¢ãµã¼ã·ã§ã³
ãæ軽ã«è¡ããã¨ãåºæ¥ã¾ãã
Faker ã«ããããã¼ãã¼ã¿çæ
Factory ã®å®ç¾©æã«ã Faker\Generator $faker
ã¨ããã¤ã³ã¹ã¿ã³ã¹ã渡ããã¦ãã¾ãã
ãã㯠fzaninotto/Faker ã¨å¼ã°ãããã¹ãç¨ã®ããã¼ãã¼ã¿çæã©ã¤ãã©ãªã§ãã
é常ã§ããã° "[email protected]"
ã ã¨ãã "Taro Yamada"
ã ã¨ããã£ãããã¼ãã¼ã¿ãé½åº¦çæãã¾ããããã® Faker ãå©ç¨ããã¨ããããã¹ãã§ä½¿ãããæååãæ°å¤ããèªåã§çæãã¦ããã¾ãã
ä½æãé»è©±çªå·ãååãä¼ç¤¾åãªã©ãªã©ãå¤å½©ãªããã¼ãã¼ã¿ããåå½ã«åãããå½¢ã§ã©ã³ãã ã«åå¾ãããã¨ãå¯è½ã§ãã
ãã©ã³ã¶ã¯ã·ã§ã³ã§ãã¹ãDBãæ±ããªã
ãã¹ãã±ã¼ã¹ã« \Illuminate\Foundation\Testing\DatabaseTransactions
ã¨ããtraitãå ãããã¨ã§ããã¹ãã®åå¾ã§ãã©ã³ã¶ã¯ã·ã§ã³ãå¼µã£ã¦ããã¹ãæã®ã¬ã³ã¼ãæ¿å
¥ãæ´æ°ããã®ãã¹ãã ãã¨ãããã¨ãå¯è½ã§ãã
Laravel ã®ãã©ã³ã¶ã¯ã·ã§ã³ã¯è¤æ°åè¡ãããããµãã¼ãããã¦ããã®ã§ããã¹ãå
ã§ã³ããããè¡ã£ã¦ããå®éã«ã³ãããããããã¨ã¯ããã¾ããã
ããã§ããã¹ãç¨ã®DBãæ±ããã¨ãªããã¹ããè¡ããã¨ãåºæ¥ã¾ã(AUTO_INCREMENTã®å¤ãªã©ãä¸é¨ã¯å½±é¿ãåãã¦ãã¾ãã¾ã)ã
ã¾ã¨ã
- Laravel ãªãçµåãã¹ããåä½ãã¹ããç°¡åã«ãããã
- DBã使ã£ããã¹ãããã¼ã¿ã®ç¨æãç°¡åã ã
- ã¢ãã¯ã Prophecy ã§ç´æçã«è¡ããã
ã¨ã Laravel ã¢ããªã±ã¼ã·ã§ã³ã¯ç´ æ´ããããã¹ã¿ãã«ç°å¢ã«ããã¨è¨ãã¾ããçããã Laravel ã使ã£ã¦ä½ãã¢ããªã±ã¼ã·ã§ã³ãçµãæã¯ãæ¯éãããã®ãã¹ããä½é¨ãã¦ã¿ã¦ãã ãããï¼
P.S.
ã¢ããªã±ã¼ã·ã§ã³ã«ã¼ããã£ã¬ã¯ããªã« .env.testing
ã¨ãããã¡ã¤ã«ãç½®ãã¨ãã¦ããããã¹ããåãããæã ããã®ãã¡ã¤ã«ã«æ¸ãããç°å¢å®æ°ãèªã¿è¾¼ãã§ããã¾ããã
ç°å¢å®æ°ã«é¢ãã¦ã¯ phpunit.xml
ã§ãè¨è¿°åºæ¥ãã®ã§ãå ´åã«å¿ãã¦ä½¿ãåãã¾ããã(åç°å¢ã§ã®ãã¹ãç¨DBã³ãã¯ã·ã§ã³ã .env.testing
ã«æ¸ãã¦ã¿ãã)ã