Permalink
Browse files

第一種 Collection 測試方法

  • Loading branch information...
1 parent c9606ad commit 9fa92fbedd7f367b12510dbeee10bdf8020338d9 @oomusou committed Jul 8, 2016
Showing with 15 additions and 10 deletions.
  1. +15 −10 tests/Unit/PostServiceTest.php
@@ -9,23 +9,28 @@ class PostServiceTest extends TestCase
use DatabaseMigrations;
/** @test */
- public function 顯示所有文章()
+ public function 顯示所有文章1()
{
/** arrange */
- $expected = [
- ['title' => 'title1', 'description' => 'desc1', 'content' => 'content1'],
- ['title' => 'title2', 'description' => 'desc2', 'content' => 'content2'],
- ['title' => 'title3', 'description' => 'desc3', 'content' => 'content3'],
- ];
-
- collect($expected)->each(function ($value) {
- Post::create($value);
+ collect(range(1, 3))->each(function ($value) {
+ Post::create([
+ 'title' => "title{$value}",
+ 'description' => "desc{$value}",
+ 'content' => "content{$value}"
+ ]);
});
/** act */
- $actual = app(PostService::class)->displayAllPosts()->toArray();
+ $actual = app(PostService::class)
+ ->displayAllPosts()
+ ->toArray();
/** assert */
+ $expected = [
+ ['title' => 'title1', 'description' => 'desc1', 'content' => 'content1'],
+ ['title' => 'title2', 'description' => 'desc2', 'content' => 'content2'],
+ ['title' => 'title3', 'description' => 'desc3', 'content' => 'content3'],
+ ];
$this->assertArraySubset($expected, $actual);
}
}

0 comments on commit 9fa92fb

Please sign in to comment.