From b29a82435cb695cb0b2e20fa53094f62d3866cf5 Mon Sep 17 00:00:00 2001 From: shibafu Date: Sat, 15 Feb 2020 22:53:10 +0900 Subject: [PATCH] =?UTF-8?q?DataProvider=E3=82=92=E4=BD=BF=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E6=9B=B8=E3=81=84?= =?UTF-8?q?=E3=81=A6=E3=81=BF=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Unit/Io/CheckinCsvImporterTest.php | 68 +++++++++--------------- 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/tests/Unit/Io/CheckinCsvImporterTest.php b/tests/Unit/Io/CheckinCsvImporterTest.php index 3a81ded..5776838 100644 --- a/tests/Unit/Io/CheckinCsvImporterTest.php +++ b/tests/Unit/Io/CheckinCsvImporterTest.php @@ -23,71 +23,51 @@ class CheckinCsvImporterTest extends TestCase $importer->execute(); } - public function testMissingTimeUTF8() + /** + * @dataProvider provideMissingTime + */ + public function testMissingTime($filename) { $user = factory(User::class)->create(); $this->expectException(CsvImportException::class); $this->expectExceptionMessage('日時列は必須です。'); - $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/missing-time.utf8.csv'); + $importer = new CheckinCsvImporter($user, $filename); $importer->execute(); } - public function testMissingTimeSJIS() + public function provideMissingTime() { - $user = factory(User::class)->create(); - $this->expectException(CsvImportException::class); - $this->expectExceptionMessage('日時列は必須です。'); - - $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/missing-time.sjis.csv'); - $importer->execute(); + return [ + 'UTF8' => [__DIR__ . '/../../fixture/Csv/missing-time.utf8.csv'], + 'SJIS' => [__DIR__ . '/../../fixture/Csv/missing-time.sjis.csv'], + ]; } - public function testDateNoSecondUTF8() + /** + * @dataProvider provideDate + */ + public function testDate($expectedDate, $filename) { $user = factory(User::class)->create(); - $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/date-nosecond.utf8.csv'); + $importer = new CheckinCsvImporter($user, $filename); $importer->execute(); $ejaculation = $user->ejaculations()->first(); $this->assertSame(1, $user->ejaculations()->count()); - $this->assertEquals(Carbon::create(2020, 1, 23, 6, 1, 0), $ejaculation->ejaculated_date); + $this->assertEquals($expectedDate, $ejaculation->ejaculated_date); } - public function testDateNoZeroNoSecondUTF8() + public function provideDate() { - $user = factory(User::class)->create(); + $date = Carbon::create(2020, 1, 23, 6, 1, 0, 'Asia/Tokyo'); - $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/date-nozero-nosecond.utf8.csv'); - $importer->execute(); - $ejaculation = $user->ejaculations()->first(); - - $this->assertSame(1, $user->ejaculations()->count()); - $this->assertEquals(Carbon::create(2020, 1, 23, 6, 1, 0), $ejaculation->ejaculated_date); - } - - public function testDateUTF8() - { - $user = factory(User::class)->create(); - - $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/date.utf8.csv'); - $importer->execute(); - $ejaculation = $user->ejaculations()->first(); - - $this->assertSame(1, $user->ejaculations()->count()); - $this->assertEquals(Carbon::create(2020, 1, 23, 6, 1, 0), $ejaculation->ejaculated_date); - } - - public function testDateNoZeroUTF8() - { - $user = factory(User::class)->create(); - - $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/date-nozero.utf8.csv'); - $importer->execute(); - $ejaculation = $user->ejaculations()->first(); - - $this->assertSame(1, $user->ejaculations()->count()); - $this->assertEquals(Carbon::create(2020, 1, 23, 6, 1, 0), $ejaculation->ejaculated_date); + return [ + 'Zero, Second, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date.utf8.csv'], + 'NoZero, Second, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date-nozero.utf8.csv'], + 'Zero, NoSecond, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date-nosecond.utf8.csv'], + 'NoZero, NoSecond, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date-nozero-nosecond.utf8.csv'], + ]; } }