-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change INR factory and send msi response code, to allow reuse a…
…nd fix connectivity VOL-5801
- Loading branch information
Showing
11 changed files
with
57 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,12 @@ | |
use Dvsa\Olcs\Api\Service\Nr\InrClient; | ||
use Dvsa\Olcs\DocumentShare\Data\Object\File; | ||
use Dvsa\Olcs\Transfer\Command\CommandInterface; | ||
use Dvsa\Olcs\Api\Service\Nr\InrClientInterface; | ||
use Dvsa\Olcs\Api\Entity\Si\ErruRequest as ErruRequestEntity; | ||
use Dvsa\Olcs\Api\Domain\Command\Cases\Si\SendResponse as SendResponseCmd; | ||
use Laminas\Http\Response; | ||
use Laminas\Http\Client\Adapter\Exception\RuntimeException as AdapterRuntimeException; | ||
use Dvsa\Olcs\Api\Domain\Exception\InrClientException; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* SendResponse | ||
* | ||
* @author Ian Lindsay <[email protected]> | ||
*/ | ||
final class SendResponse extends AbstractCommandHandler implements UploaderAwareInterface | ||
{ | ||
use UploaderAwareTrait; | ||
|
@@ -32,10 +25,9 @@ final class SendResponse extends AbstractCommandHandler implements UploaderAware | |
'Document' | ||
]; | ||
|
||
/** | ||
* @var InrClient | ||
*/ | ||
protected $inrClient; | ||
public function __construct(private readonly InrClient $inrClient) | ||
{ | ||
} | ||
|
||
/** | ||
* SendResponse | ||
|
@@ -96,11 +88,4 @@ private function updateStatus(ErruRequestEntity $erruRequest, $statusKey) | |
|
||
return $erruRequest; | ||
} | ||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) | ||
{ | ||
$fullContainer = $container; | ||
|
||
$this->inrClient = $container->get(InrClientInterface::class); | ||
return parent::__invoke($fullContainer, $requestedName, $options); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/api/module/Api/src/Domain/CommandHandler/Cases/Si/SendResponseFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dvsa\Olcs\Api\Domain\CommandHandler\Cases\Si; | ||
|
||
use Dvsa\Olcs\Api\Service\Nr\InrClientInterface; | ||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Psr\Container\ContainerInterface; | ||
|
||
final class SendResponseFactory implements FactoryInterface | ||
{ | ||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) | ||
{ | ||
$inrClient = $container->build(InrClientInterface::class, ['path' => '/ncr']); | ||
return (new SendResponse($inrClient))->__invoke($container, $requestedName, $options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dvsa\OlcsTest\Api\Domain\CommandHandler\Cases\Si; | ||
|
||
use Dvsa\Olcs\Api\Domain\Exception\InrClientException; | ||
use Mockery as m; | ||
use Dvsa\Olcs\Api\Domain\Command\Result; | ||
use Dvsa\OlcsTest\Api\Domain\CommandHandler\AbstractCommandHandlerTestCase; | ||
|
@@ -10,25 +13,22 @@ | |
use Dvsa\Olcs\Api\Domain\Repository\ErruRequest as ErruRequestRepo; | ||
use Dvsa\Olcs\Api\Entity\Si\ErruRequest as ErruRequestEntity; | ||
use Dvsa\Olcs\Api\Service\Nr\InrClient; | ||
use Dvsa\Olcs\Api\Service\Nr\InrClientInterface; | ||
use Laminas\Http\Client\Adapter\Exception\RuntimeException as AdapterRuntimeException; | ||
use Dvsa\Olcs\Api\Service\File\ContentStoreFileUploader; | ||
use Dvsa\Olcs\DocumentShare\Data\Object\File; | ||
|
||
/** | ||
* SendResponseTest | ||
* | ||
* @author Ian Lindsay <[email protected]> | ||
*/ | ||
class SendResponseTest extends AbstractCommandHandlerTestCase | ||
{ | ||
private readonly m\MockInterface $inrService; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->sut = new SendResponse(); | ||
$this->inrService = m::mock(InrClient::class); | ||
|
||
$this->sut = new SendResponse($this->inrService); | ||
$this->mockRepo('ErruRequest', ErruRequestRepo::class); | ||
|
||
$this->mockedSmServices = [ | ||
InrClientInterface::class => m::mock(InrClient::class), | ||
'FileUploader' => m::mock(ContentStoreFileUploader::class) | ||
]; | ||
|
||
|
@@ -70,15 +70,13 @@ public function testHandleCommand() | |
$this->repoMap['ErruRequest']->shouldReceive('fetchUsingId')->once()->with($command)->andReturn($erruRequest); | ||
$this->repoMap['ErruRequest']->shouldReceive('save')->once()->with(m::type(ErruRequestEntity::class)); | ||
|
||
$this->mockedSmServices[InrClientInterface::class] | ||
->shouldReceive('makeRequest') | ||
->once() | ||
$this->inrService | ||
->expects('makeRequest') | ||
->with($xml) | ||
->andReturn(202); | ||
|
||
$this->mockedSmServices[InrClientInterface::class] | ||
->shouldReceive('close') | ||
->once() | ||
$this->inrService | ||
->expects('close') | ||
->withNoArgs(); | ||
|
||
$result = $this->sut->handleCommand($command); | ||
|
@@ -101,7 +99,7 @@ public function testHandleCommand() | |
*/ | ||
public function testHandleCommandInvalidResponseCode() | ||
{ | ||
$this->expectException(\Dvsa\Olcs\Api\Domain\Exception\InrClientException::class); | ||
$this->expectException(InrClientException::class); | ||
$this->expectExceptionMessage('INR Http response code was 400'); | ||
|
||
$xml = 'xml string'; | ||
|
@@ -128,15 +126,13 @@ public function testHandleCommandInvalidResponseCode() | |
$this->repoMap['ErruRequest']->shouldReceive('fetchUsingId')->once()->with($command)->andReturn($erruRequest); | ||
$this->repoMap['ErruRequest']->shouldReceive('save')->once()->with(m::type(ErruRequestEntity::class)); | ||
|
||
$this->mockedSmServices[InrClientInterface::class] | ||
->shouldReceive('makeRequest') | ||
->once() | ||
$this->inrService | ||
->expects('makeRequest') | ||
->with($xml) | ||
->andReturn(400); | ||
|
||
$this->mockedSmServices[InrClientInterface::class] | ||
->shouldReceive('close') | ||
->once() | ||
$this->inrService | ||
->expects('close') | ||
->withNoArgs(); | ||
|
||
$this->sut->handleCommand($command); | ||
|
@@ -147,7 +143,7 @@ public function testHandleCommandInvalidResponseCode() | |
*/ | ||
public function testHandleCommandAdapterException() | ||
{ | ||
$this->expectException(\Dvsa\Olcs\Api\Domain\Exception\InrClientException::class); | ||
$this->expectException(InrClientException::class); | ||
$this->expectExceptionMessage('There was an error sending the INR response adapter exception message'); | ||
|
||
$xml = 'xml string'; | ||
|
@@ -174,9 +170,8 @@ public function testHandleCommandAdapterException() | |
$this->repoMap['ErruRequest']->shouldReceive('fetchUsingId')->once()->with($command)->andReturn($erruRequest); | ||
$this->repoMap['ErruRequest']->shouldReceive('save')->once()->with(m::type(ErruRequestEntity::class)); | ||
|
||
$this->mockedSmServices[InrClientInterface::class] | ||
->shouldReceive('makeRequest') | ||
->once() | ||
$this->inrService | ||
->expects('makeRequest') | ||
->with($xml) | ||
->andThrow(AdapterRuntimeException::class, 'adapter exception message'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters