diff --git a/src/Client/Mandator/MandatorClient.php b/src/Client/Mandator/MandatorClient.php index 0139371..7200953 100644 --- a/src/Client/Mandator/MandatorClient.php +++ b/src/Client/Mandator/MandatorClient.php @@ -46,4 +46,41 @@ public function getList(): array $this->hydratorConfigFactory->createMandatorConfig() ); } + + /** @inheritDoc */ + public function create( + string $name, + bool $demo_mode, + int $pricemodel_id = 0, + string $description = '', + int $industry_type = 1, + ): StructInterface { + return $this->responseMapper->getObject( + $this->soapClient->create([ + 'name' => $name, + 'demo_mode' => $demo_mode, + 'pricemodel_id' => $pricemodel_id, + 'description' => $description, + 'industry_type' => $industry_type, + ]), + 'createResult', + $this->hydratorConfigFactory->createMandatorConfig() + ); + } + + /** @inheritDoc */ + public function importScenario( + int $mandator_id, + string $scenario_data, + string $language_code + ): bool { + return $this->responseMapper->getBoolean( + $this->soapClient->importScenario([ + 'mandator_id' => $mandator_id, + 'scenario_data' => $scenario_data, + 'language_code' => $language_code, + ]), + 'importScenarioResult', + ); + } } diff --git a/src/Client/Mandator/MandatorClientInterface.php b/src/Client/Mandator/MandatorClientInterface.php index 0777e3e..c598756 100644 --- a/src/Client/Mandator/MandatorClientInterface.php +++ b/src/Client/Mandator/MandatorClientInterface.php @@ -3,6 +3,7 @@ namespace Scn\EvalancheSoapApiConnector\Client\Mandator; use Scn\EvalancheSoapApiConnector\Client\ClientInterface; +use Scn\EvalancheSoapApiConnector\Exception\EmptyResultException; use Scn\EvalancheSoapStruct\Struct\Mandator\MandatorInterface; use Scn\EvalancheSoapStruct\Struct\StructInterface; @@ -25,4 +26,36 @@ public function getById(int $id): StructInterface; * @return MandatorInterface[] */ public function getList(): array; + + /** + * Creates a new mandator + * + * @param string $name Name of the new mandator + * @param bool $demo_mode Set to `true` if the mandator should be a demo-mandator + * @param int $pricemodel_id If of the designated pricemodel (will be ignored for demo-mandators) + * @param string $description Descriptive text for the mandator + * @param int $industry_type Industry-type the mandator should be assigned to + */ + public function create( + string $name, + bool $demo_mode, + int $pricemodel_id = 0, + string $description = '', + int $industry_type = 1, + ): StructInterface; + + /** + * Imports a new scenario + * + * @param int $mandator_id The id of the mandator the scenario should be imported to + * @param string $scenario_data Base64-encoded scenario-json data + * @param string $language_code ISO2 language code + * + * @throws EmptyResultException + */ + public function importScenario( + int $mandator_id, + string $scenario_data, + string $language_code + ): bool; } diff --git a/tests/Client/Mandator/MandatorClientTest.php b/tests/Client/Mandator/MandatorClientTest.php index 0625432..10a2735 100644 --- a/tests/Client/Mandator/MandatorClientTest.php +++ b/tests/Client/Mandator/MandatorClientTest.php @@ -14,11 +14,6 @@ use Scn\EvalancheSoapStruct\Struct\Mandator\MandatorInterface; use stdClass; -/** - * Class MandatorClientTest - * - * @package Scn\EvalancheSoapApiConnector\Client\Mandator - */ class MandatorClientTest extends TestCase { /** @@ -48,7 +43,12 @@ class MandatorClientTest extends TestCase public function setUp(): void { - $this->soapClient = $this->getWsdlMock(['getById', 'getList']); + $this->soapClient = $this->getWsdlMock([ + 'getById', + 'getList', + 'create', + 'importScenario', + ]); $this->responseMapper = $this->getMockBuilder(ResponseMapperInterface::class)->getMock(); $this->hydratorConfigFactory = $this->getMockBuilder(HydratorConfigFactoryInterface::class)->getMock(); $this->extractor = $this->getMockBuilder(ExtractorInterface::class)->getMock(); @@ -124,4 +124,87 @@ public function testGetListCanReturnArrayOfMandatorInterface() $this->subject->getList() ); } + + public function testCreateReturnsMandatorInstance(): void + { + $config = $this->getMockBuilder(HydratorConfigInterface::class)->getMock(); + $object = $this->getMockBuilder(MandatorInterface::class)->getMock(); + + $result = new stdClass(); + $result->createResult = $object; + + $name = 'some-name'; + $demo_mode = true; + $pricemodel_id = 123; + $description = 'some-description'; + $industry_type = 111; + + $this->hydratorConfigFactory->expects($this->once())->method('createMandatorConfig') + ->willReturn($config); + + $this->soapClient + ->expects($this->once()) + ->method('create') + ->with([ + 'name' => $name, + 'demo_mode' => $demo_mode, + 'pricemodel_id' => $pricemodel_id, + 'description' => $description, + 'industry_type' => $industry_type, + ]) + ->willReturn($result); + + $this->responseMapper + ->expects($this->once()) + ->method('getObject') + ->with($result, 'createResult', $config) + ->willReturn($object); + + self::assertSame( + $object, + $this->subject->create( + $name, + $demo_mode, + $pricemodel_id, + $description, + $industry_type + ) + ); + } + + public function testImportScenarioImports(): void + { + $object = $this->getMockBuilder(MandatorInterface::class)->getMock(); + + $result = new stdClass(); + $result->importScenarioResult = $object; + + $mandator_id = 666; + $scenario_content = 'some-data'; + $language_code = 'some-language'; + + $this->soapClient + ->expects($this->once()) + ->method('importScenario') + ->with([ + 'mandator_id' => $mandator_id, + 'scenario_data' => $scenario_content, + 'language_code' => $language_code, + ]) + ->willReturn($result); + + $this->responseMapper + ->expects($this->once()) + ->method('getBoolean') + ->with($result, 'importScenarioResult') + ->willReturn(true); + + self::assertTrue( + $this->subject->importScenario( + $mandator_id, + $scenario_content, + $language_code, + ) + ); + } }