Permalink
Browse files

第二種 Collection 測試方法

  • Loading branch information...
1 parent 3198380 commit 0bc408423156af0c7602a6d4db60bdb1bd8b7b10 @oomusou committed Jul 8, 2016
Showing with 32 additions and 0 deletions.
  1. +32 −0 tests/Unit/PostServiceTest.php
@@ -33,4 +33,36 @@ public function 顯示所有文章1()
];
$this->assertArraySubset($expected, $actual);
}
+
+ /** @test */
+ public function 顯示所有文章2()
+ {
+ /** arrange */
+ collect(range(1, 3))->each(function ($value) {
+ Post::create([
+ 'title' => "title{$value}",
+ 'description' => "desc{$value}",
+ 'content' => "content{$value}"
+ ]);
+ });
+
+ /** act */
+ $actual = app(PostService::class)
+ ->displayAllPosts()
+ ->pick([
+ 'title',
+ 'description',
+ 'content'
+ ])
+ ->all();
+
+ /** assert */
+ $expected = [
+ ['title1', 'desc1', 'content1'],
+ ['title2', 'desc2', 'content2'],
+ ['title3', 'desc3', 'content3'],
+ ];
+
+ $this->assertEquals($expected, $actual);
+ }
}

0 comments on commit 0bc4084

Please sign in to comment.