Last active
April 10, 2018 21:40
-
-
Save RyosukeKamei/e60ab8df4c4ab63c8e689e699be45343 to your computer and use it in GitHub Desktop.
本当に理解しているか自信ないから、改めてTDD(テスト駆動開発)をやってみた~アジャイルでDevOpsなシステム構築実践~ ref: https://qiita.com/RyosukeKamei/items/a6b37444961305f5ba5d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-- 試験区分をすべて取得 | |
Route::get('/getAllExamination', 'ExaminationController@getAll'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker-compose exec workspace php artisan make:test ExaminationTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExaminationController extends Controller | |
{ | |
/** | |
* すべての試験区分を取得 | |
* | |
* | |
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\static[] | |
*/ | |
public function getAll() | |
{ | |
/* | |
* オブジェクトをreturnするとLaravelがJSONにしてくれる | |
*/ | |
return Examination::all(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function testExaminationGetAll() | |
{ | |
/* | |
* レスポンスを取得 | |
*/ | |
$response = $this->json('GET', '/api/getAllExamination'); | |
/* | |
* テストケース | |
* 1. ステータスコード200が返ること | |
*/ | |
$response->assertStatus(200); | |
/* | |
* テストケース | |
* 2. 取得するJOSNを配列にすると1件以上存在すること(0件はありえない) | |
*/ | |
$this->assertGreaterThanOrEqual(1, count(json_decode($response->getContent()))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./vendor/bin/phpunit tests/Feature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./vendor/bin/phpunit --filter=ExaminationTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker-compose exec workspace php artisan make:controller ExaminationController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker-compose exec workspace ./vendor/bin/phpunit --filter=testExaminationGetAll | |
PHPUnit 6.5.4 by Sebastian Bergmann and contributors. | |
. 1 / 1 (100%) | |
Time: 619 ms, Memory: 12.00MB | |
OK (1 test, 3 assertions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker-compose exec workspace ./vendor/bin/phpunit --filter=testExaminationGetAll | |
PHPUnit 6.5.4 by Sebastian Bergmann and contributors. | |
F 1 / 1 (100%) | |
Time: 579 ms, Memory: 10.00MB | |
There was 1 failure: | |
1) Tests\Feature\ExaminationTest::testExaminationGetAll | |
Failed asserting that 0 is equal to 1 or is greater than 1. | |
/var/www/tests/Feature/ExaminationTest.php:44 | |
FAILURES! | |
Tests: 1, Assertions: 3, Failures: 1. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker-compose exec workspace ./vendor/bin/phpunit --filter=testExaminationGetAll | |
PHPUnit 6.5.4 by Sebastian Bergmann and contributors. | |
. 1 / 1 (100%) | |
Time: 553 ms, Memory: 10.00MB | |
OK (1 test, 1 assertion) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker-compose exec workspace ./vendor/bin/phpunit --filter=testExaminationGetAll | |
PHPUnit 6.5.4 by Sebastian Bergmann and contributors. | |
F 1 / 1 (100%) | |
Time: 703 ms, Memory: 10.00MB | |
There was 1 failure: | |
1) Tests\Feature\ExaminationTest::testExaminationGetAll | |
Expected status code 200 but received 404. | |
Failed asserting that false is true. | |
/var/www/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:78 | |
/var/www/tests/Feature/ExaminationTest.php:30 | |
FAILURES! | |
Tests: 1, Assertions: 1, Failures: 1. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ php vendor/bin/phpunit --filter=visit_sample_page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ php artisan make:test ExaminationTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./vendor/bin/phpunit --filter=testExaminationGetAll |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment