Skip to content

Commit e7c73e0

Browse files
committed
CsvImporter
1 parent f644a98 commit e7c73e0

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

resources/translations/messages.en.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@
416416
<source>Subscriber not found</source>
417417
<source>Subscriber not found</source>
418418
</trans-unit>
419+
<trans-unit id="subscription.unexpected_error">
420+
<source>Unexpected error: %error%</source>
421+
<target>Unexpected error: %error%</target>
422+
</trans-unit>
419423

420424
</body>
421425
</file>

src/Domain/Subscription/Service/CsvImporter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
use PhpList\Core\Domain\Subscription\Model\Dto\ImportSubscriberDto;
99
use Symfony\Component\Validator\Validator\ValidatorInterface;
1010
use League\Csv\Exception as CsvException;
11+
use Symfony\Contracts\Translation\TranslatorInterface;
1112
use Throwable;
1213

1314
class CsvImporter
1415
{
1516
public function __construct(
1617
private readonly CsvRowToDtoMapper $rowMapper,
1718
private readonly ValidatorInterface $validator,
19+
private readonly TranslatorInterface $translator,
1820
) {
1921
}
2022

@@ -46,7 +48,9 @@ public function import(string $csvFilePath): array
4648

4749
$validDtos[] = $dto;
4850
} catch (Throwable $e) {
49-
$errors[$index + 1][] = 'Unexpected error: ' . $e->getMessage();
51+
$errors[$index + 1][] = $this->translator->trans('Unexpected error: %error%', [
52+
'%error%' => $e->getMessage()
53+
]);
5054
}
5155
}
5256

tests/Unit/Domain/Subscription/Service/SubscriberCsvImporterTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,29 @@ class SubscriberCsvImporterTest extends TestCase
2424
{
2525
private SubscriberManager&MockObject $subscriberManagerMock;
2626
private SubscriberAttributeManager&MockObject $attributeManagerMock;
27-
private SubscriptionManager&MockObject $subscriptionManagerMock;
2827
private SubscriberRepository&MockObject $subscriberRepositoryMock;
2928
private CsvImporter&MockObject $csvImporterMock;
3029
private SubscriberAttributeDefinitionRepository&MockObject $attributeDefinitionRepositoryMock;
31-
private EntityManagerInterface $entityManager;
3230
private SubscriberCsvImporter $subject;
3331

3432
protected function setUp(): void
3533
{
3634
$this->subscriberManagerMock = $this->createMock(SubscriberManager::class);
3735
$this->attributeManagerMock = $this->createMock(SubscriberAttributeManager::class);
38-
$this->subscriptionManagerMock = $this->createMock(SubscriptionManager::class);
36+
$subscriptionManagerMock = $this->createMock(SubscriptionManager::class);
3937
$this->subscriberRepositoryMock = $this->createMock(SubscriberRepository::class);
4038
$this->csvImporterMock = $this->createMock(CsvImporter::class);
4139
$this->attributeDefinitionRepositoryMock = $this->createMock(SubscriberAttributeDefinitionRepository::class);
42-
$this->entityManager = $this->createMock(EntityManagerInterface::class);
40+
$entityManager = $this->createMock(EntityManagerInterface::class);
4341

4442
$this->subject = new SubscriberCsvImporter(
4543
subscriberManager: $this->subscriberManagerMock,
4644
attributeManager: $this->attributeManagerMock,
47-
subscriptionManager: $this->subscriptionManagerMock,
45+
subscriptionManager: $subscriptionManagerMock,
4846
subscriberRepository: $this->subscriberRepositoryMock,
4947
csvImporter: $this->csvImporterMock,
5048
attrDefinitionRepository: $this->attributeDefinitionRepositoryMock,
51-
entityManager: $this->entityManager,
49+
entityManager: $entityManager,
5250
);
5351
}
5452

0 commit comments

Comments
 (0)