From cc0e0271b807a652f9d3fd7f19431b1d8306f9b5 Mon Sep 17 00:00:00 2001 From: shibafu Date: Sat, 23 May 2020 15:56:51 +0900 Subject: [PATCH] add test --- app/Services/CheckinCsvImporter.php | 2 +- tests/Unit/Services/CheckinCsvImporterTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Services/CheckinCsvImporter.php b/app/Services/CheckinCsvImporter.php index ae90faf..542a9ad 100644 --- a/app/Services/CheckinCsvImporter.php +++ b/app/Services/CheckinCsvImporter.php @@ -59,7 +59,7 @@ class CheckinCsvImporter $imported = 0; foreach ($csv->getRecords() as $offset => $record) { $line = $offset + 1; - if (self::IMPORT_LIMIT < $alreadyImportedCount + $imported) { + if (self::IMPORT_LIMIT <= $alreadyImportedCount + $imported) { $limit = self::IMPORT_LIMIT; $errors[] = "{$line} 行 : インポート機能で取り込めるデータは{$limit}件までに制限されています。これ以上取り込みできません。"; throw new CsvImportException(...$errors); diff --git a/tests/Unit/Services/CheckinCsvImporterTest.php b/tests/Unit/Services/CheckinCsvImporterTest.php index 9ba29aa..d418e5d 100644 --- a/tests/Unit/Services/CheckinCsvImporterTest.php +++ b/tests/Unit/Services/CheckinCsvImporterTest.php @@ -291,4 +291,19 @@ class CheckinCsvImporterTest extends TestCase $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/date.utf8.csv'); $importer->execute(); } + + public function testRecordLimit() + { + $user = factory(User::class)->create(); + factory(Ejaculation::class, 5000)->create([ + 'user_id' => $user->id, + 'source' => Ejaculation::SOURCE_CSV + ]); + + $this->expectException(CsvImportException::class); + $this->expectExceptionMessage('2 行 : インポート機能で取り込めるデータは5000件までに制限されています。これ以上取り込みできません。'); + + $importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/link.utf8.csv'); + $importer->execute(); + } }