Skip to content

Commit

Permalink
[9-8] InquiryCsvBuilderTestクラスのCSVのテストを実装
Browse files Browse the repository at this point in the history
  • Loading branch information
hidenorigoto committed Dec 28, 2015
1 parent 7a0cf54 commit 29fb521
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/lists/ch09/09-08.txt
@@ -0,0 +1,22 @@
public function CSVが正しく作られること()
{
$inquiry1 = new Inquiry();
$inquiry1->setId(1);
$inquiry1->setName('テストあいうえお');
$inquiry1->setEmail('aiu@example.com');
$inquiry2 = new Inquiry();
$inquiry2->setId(2);
$inquiry2->setName('テストかきく けこ');
$inquiry2->setEmail('keko@example.com');
$inquiryCollection = new ArrayCollection([$inquiry1, $inquiry2]);
$this->inquiryRepository->expects($this->once())
->method('findAllByKeyword')
->willReturn($inquiryCollection);

$result = $this->SUT->build('テスト');

$expected = '1,テストあいうえお,aiu@example.com' . "\r\n" .
'2,"テストかきく けこ",keko@example.com' . "\r\n";

$this->assertThat($result, $this->equalTo($expected));
}
19 changes: 19 additions & 0 deletions src/AppBundle/Tests/Service/Csv/InquiryCsvBuilderTest.php
Expand Up @@ -22,6 +22,25 @@ class InquiryCsvBuilderTest extends \PHPUnit_Framework_TestCase
*/
public function CSVが正しく作られること()
{
$inquiry1 = new Inquiry();
$inquiry1->setId(1);
$inquiry1->setName('テストあいうえお');
$inquiry1->setEmail('aiu@example.com');
$inquiry2 = new Inquiry();
$inquiry2->setId(2);
$inquiry2->setName('テストかきく けこ');
$inquiry2->setEmail('keko@example.com');
$inquiryCollection = new ArrayCollection([$inquiry1, $inquiry2]);
$this->inquiryRepository->expects($this->once())
->method('findAllByKeyword')
->willReturn($inquiryCollection);

$result = $this->SUT->build('テスト');

$expected = '1,テストあいうえお,aiu@example.com' . "\r\n" .
'2,"テストかきく けこ",keko@example.com' . "\r\n";

$this->assertThat($result, $this->equalTo($expected));
}

protected function setUp()
Expand Down

0 comments on commit 29fb521

Please sign in to comment.