DataProviderを使ってテストを書いてみる
This commit is contained in:
parent
67b697a600
commit
b29a82435c
@ -23,71 +23,51 @@ class CheckinCsvImporterTest extends TestCase
|
|||||||
$importer->execute();
|
$importer->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMissingTimeUTF8()
|
/**
|
||||||
|
* @dataProvider provideMissingTime
|
||||||
|
*/
|
||||||
|
public function testMissingTime($filename)
|
||||||
{
|
{
|
||||||
$user = factory(User::class)->create();
|
$user = factory(User::class)->create();
|
||||||
$this->expectException(CsvImportException::class);
|
$this->expectException(CsvImportException::class);
|
||||||
$this->expectExceptionMessage('日時列は必須です。');
|
$this->expectExceptionMessage('日時列は必須です。');
|
||||||
|
|
||||||
$importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/missing-time.utf8.csv');
|
$importer = new CheckinCsvImporter($user, $filename);
|
||||||
$importer->execute();
|
$importer->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMissingTimeSJIS()
|
public function provideMissingTime()
|
||||||
{
|
{
|
||||||
$user = factory(User::class)->create();
|
return [
|
||||||
$this->expectException(CsvImportException::class);
|
'UTF8' => [__DIR__ . '/../../fixture/Csv/missing-time.utf8.csv'],
|
||||||
$this->expectExceptionMessage('日時列は必須です。');
|
'SJIS' => [__DIR__ . '/../../fixture/Csv/missing-time.sjis.csv'],
|
||||||
|
];
|
||||||
$importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/missing-time.sjis.csv');
|
|
||||||
$importer->execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDateNoSecondUTF8()
|
/**
|
||||||
|
* @dataProvider provideDate
|
||||||
|
*/
|
||||||
|
public function testDate($expectedDate, $filename)
|
||||||
{
|
{
|
||||||
$user = factory(User::class)->create();
|
$user = factory(User::class)->create();
|
||||||
|
|
||||||
$importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/date-nosecond.utf8.csv');
|
$importer = new CheckinCsvImporter($user, $filename);
|
||||||
$importer->execute();
|
$importer->execute();
|
||||||
$ejaculation = $user->ejaculations()->first();
|
$ejaculation = $user->ejaculations()->first();
|
||||||
|
|
||||||
$this->assertSame(1, $user->ejaculations()->count());
|
$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');
|
return [
|
||||||
$importer->execute();
|
'Zero, Second, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date.utf8.csv'],
|
||||||
$ejaculation = $user->ejaculations()->first();
|
'NoZero, Second, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date-nozero.utf8.csv'],
|
||||||
|
'Zero, NoSecond, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date-nosecond.utf8.csv'],
|
||||||
$this->assertSame(1, $user->ejaculations()->count());
|
'NoZero, NoSecond, UTF8' => [$date, __DIR__ . '/../../fixture/Csv/date-nozero-nosecond.utf8.csv'],
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user