diff --git a/app/api/module/Cli/src/Domain/CommandHandler/DataGovUkExport.php b/app/api/module/Cli/src/Domain/CommandHandler/DataGovUkExport.php index b824ef7756..3a37e6736e 100644 --- a/app/api/module/Cli/src/Domain/CommandHandler/DataGovUkExport.php +++ b/app/api/module/Cli/src/Domain/CommandHandler/DataGovUkExport.php @@ -104,6 +104,12 @@ private function processPsvOperatorList() ['id' => $document->getId('document')], $document->getId('document') ); + + $tempFilePath = tempnam(sys_get_temp_dir(), 'psv_operator_list_'); + file_put_contents($tempFilePath, $csvContent); + $this->uploadToS3($tempFilePath); + unlink($tempFilePath); + $email = $this->handleSideEffect($emailQueue); $this->result->merge($email); @@ -135,6 +141,8 @@ private function processInternationalGoodsList() $document->getId('document') ); + $this->uploadToS3($csvContent); + $email = $this->handleSideEffect($emailQueue); $this->result->merge($email); diff --git a/app/api/test/module/Cli/src/Domain/CommandHandler/DataGovUkExportTest.php b/app/api/test/module/Cli/src/Domain/CommandHandler/DataGovUkExportTest.php index 387ed89f79..42e4b8487b 100644 --- a/app/api/test/module/Cli/src/Domain/CommandHandler/DataGovUkExportTest.php +++ b/app/api/test/module/Cli/src/Domain/CommandHandler/DataGovUkExportTest.php @@ -180,15 +180,22 @@ public function testInternationalGoods() ] ); + $this->mockS3client->shouldAllowMockingMethod('putObject'); + $this->mockS3client->shouldReceive('putObject') + ->once() + ->andReturn([]); + $actual = $this->sut->handleCommand($cmd); $date = new DateTime('now'); - $expectedFile = $this->tmpPath . '/' . $fileName . '_' . + + $expectedFileName = $fileName . '_' . $date->format(DataGovUkExport::FILE_DATETIME_FORMAT) . '.csv'; + $expectedFilePath = $this->tmpPath . '/' . $expectedFileName; $expectMsg = 'Fetching data for international goods list' . - 'Creating CSV file: ' . $expectedFile; + 'Creating CSV file: ' . $expectedFilePath . 'Uploaded file to S3: '.$expectedFileName; $this->assertEquals( $expectMsg, @@ -294,16 +301,20 @@ public function testPsvOperatorListOk() ] ); + $this->mockS3client->shouldAllowMockingMethod('putObject'); + $this->mockS3client->shouldReceive('putObject') + ->once() + ->andReturn([]); + $actual = $this->sut->handleCommand($cmd); $expectMsg = 'Fetching data from DB for PSV Operators' . - 'create csv file content'; + 'create csv file contentUploaded file to S3: psv_operator_list_'; - static::assertEquals( - $expectMsg, - implode('', $actual->toArray()['messages']) - ); + $actualMsg = implode('', $actual->toArray()['messages']); + + static::assertStringStartsWith($expectMsg, $actualMsg); } public function testOperatorLicenceOk()