Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/Client/Mandator/MandatorClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}
}
33 changes: 33 additions & 0 deletions src/Client/Mandator/MandatorClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
95 changes: 89 additions & 6 deletions tests/Client/Mandator/MandatorClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
use Scn\EvalancheSoapStruct\Struct\Mandator\MandatorInterface;
use stdClass;

/**
* Class MandatorClientTest
*
* @package Scn\EvalancheSoapApiConnector\Client\Mandator
*/
class MandatorClientTest extends TestCase
{
/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
)
);
}
}