Skip to content

Commit 9fb7ed9

Browse files
committed
Add new mandator-client methods
- create - importScenario
1 parent 607ed64 commit 9fb7ed9

File tree

3 files changed

+159
-6
lines changed

3 files changed

+159
-6
lines changed

src/Client/Mandator/MandatorClient.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,41 @@ public function getList(): array
4646
$this->hydratorConfigFactory->createMandatorConfig()
4747
);
4848
}
49+
50+
/** @inheritDoc */
51+
public function create(
52+
string $name,
53+
bool $demo_mode,
54+
int $pricemodel_id = 0,
55+
string $description = '',
56+
int $industry_type = 1,
57+
): StructInterface {
58+
return $this->responseMapper->getObject(
59+
$this->soapClient->create([
60+
'name' => $name,
61+
'demo_mode' => $demo_mode,
62+
'pricemodel_id' => $pricemodel_id,
63+
'description' => $description,
64+
'industry_type' => $industry_type,
65+
]),
66+
'createResult',
67+
$this->hydratorConfigFactory->createMandatorConfig()
68+
);
69+
}
70+
71+
/** @inheritDoc */
72+
public function importScenario(
73+
int $mandator_id,
74+
string $scenario_data,
75+
string $language_code
76+
): bool {
77+
return $this->responseMapper->getBoolean(
78+
$this->soapClient->importScenario([
79+
'mandator_id' => $mandator_id,
80+
'scenario_data' => $scenario_data,
81+
'language_code' => $language_code,
82+
]),
83+
'importScenarioResult',
84+
);
85+
}
4986
}

src/Client/Mandator/MandatorClientInterface.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Scn\EvalancheSoapApiConnector\Client\Mandator;
44

55
use Scn\EvalancheSoapApiConnector\Client\ClientInterface;
6+
use Scn\EvalancheSoapApiConnector\Exception\EmptyResultException;
67
use Scn\EvalancheSoapStruct\Struct\Mandator\MandatorInterface;
78
use Scn\EvalancheSoapStruct\Struct\StructInterface;
89

@@ -25,4 +26,36 @@ public function getById(int $id): StructInterface;
2526
* @return MandatorInterface[]
2627
*/
2728
public function getList(): array;
29+
30+
/**
31+
* Creates a new mandator
32+
*
33+
* @param string $name Name of the new mandator
34+
* @param bool $demo_mode Set to `true` if the mandator should be a demo-mandator
35+
* @param int $pricemodel_id If of the designated pricemodel (will be ignored for demo-mandators)
36+
* @param string $description Descriptive text for the mandator
37+
* @param int $industry_type Industry-type the mandator should be assigned to
38+
*/
39+
public function create(
40+
string $name,
41+
bool $demo_mode,
42+
int $pricemodel_id = 0,
43+
string $description = '',
44+
int $industry_type = 1,
45+
): StructInterface;
46+
47+
/**
48+
* Imports a new scenario
49+
*
50+
* @param int $mandator_id The id of the mandator the scenario should be imported to
51+
* @param string $scenario_data Base64-encoded scenario-json data
52+
* @param string $language_code ISO2 language code
53+
*
54+
* @throws EmptyResultException
55+
*/
56+
public function importScenario(
57+
int $mandator_id,
58+
string $scenario_data,
59+
string $language_code
60+
): bool;
2861
}

tests/Client/Mandator/MandatorClientTest.php

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
use Scn\EvalancheSoapStruct\Struct\Mandator\MandatorInterface;
1515
use stdClass;
1616

17-
/**
18-
* Class MandatorClientTest
19-
*
20-
* @package Scn\EvalancheSoapApiConnector\Client\Mandator
21-
*/
2217
class MandatorClientTest extends TestCase
2318
{
2419
/**
@@ -48,7 +43,12 @@ class MandatorClientTest extends TestCase
4843

4944
public function setUp(): void
5045
{
51-
$this->soapClient = $this->getWsdlMock(['getById', 'getList']);
46+
$this->soapClient = $this->getWsdlMock([
47+
'getById',
48+
'getList',
49+
'create',
50+
'importScenario',
51+
]);
5252
$this->responseMapper = $this->getMockBuilder(ResponseMapperInterface::class)->getMock();
5353
$this->hydratorConfigFactory = $this->getMockBuilder(HydratorConfigFactoryInterface::class)->getMock();
5454
$this->extractor = $this->getMockBuilder(ExtractorInterface::class)->getMock();
@@ -124,4 +124,87 @@ public function testGetListCanReturnArrayOfMandatorInterface()
124124
$this->subject->getList()
125125
);
126126
}
127+
128+
public function testCreateReturnsMandatorInstance(): void
129+
{
130+
$config = $this->getMockBuilder(HydratorConfigInterface::class)->getMock();
131+
$object = $this->getMockBuilder(MandatorInterface::class)->getMock();
132+
133+
$result = new stdClass();
134+
$result->createResult = $object;
135+
136+
$name = 'some-name';
137+
$demo_mode = true;
138+
$pricemodel_id = 123;
139+
$description = 'some-description';
140+
$industry_type = 111;
141+
142+
$this->hydratorConfigFactory->expects($this->once())->method('createMandatorConfig')
143+
->willReturn($config);
144+
145+
$this->soapClient
146+
->expects($this->once())
147+
->method('create')
148+
->with([
149+
'name' => $name,
150+
'demo_mode' => $demo_mode,
151+
'pricemodel_id' => $pricemodel_id,
152+
'description' => $description,
153+
'industry_type' => $industry_type,
154+
])
155+
->willReturn($result);
156+
157+
$this->responseMapper
158+
->expects($this->once())
159+
->method('getObject')
160+
->with($result, 'createResult', $config)
161+
->willReturn($object);
162+
163+
self::assertSame(
164+
$object,
165+
$this->subject->create(
166+
$name,
167+
$demo_mode,
168+
$pricemodel_id,
169+
$description,
170+
$industry_type
171+
)
172+
);
173+
}
174+
175+
public function testImportScenarioImports(): void
176+
{
177+
$object = $this->getMockBuilder(MandatorInterface::class)->getMock();
178+
179+
$result = new stdClass();
180+
$result->importScenarioResult = $object;
181+
182+
$mandator_id = 666;
183+
$scenario_content = 'some-data';
184+
$language_code = 'some-language';
185+
186+
$this->soapClient
187+
->expects($this->once())
188+
->method('importScenario')
189+
->with([
190+
'mandator_id' => $mandator_id,
191+
'scenario_data' => $scenario_content,
192+
'language_code' => $language_code,
193+
])
194+
->willReturn($result);
195+
196+
$this->responseMapper
197+
->expects($this->once())
198+
->method('getBoolean')
199+
->with($result, 'importScenarioResult')
200+
->willReturn(true);
201+
202+
self::assertTrue(
203+
$this->subject->importScenario(
204+
$mandator_id,
205+
$scenario_content,
206+
$language_code,
207+
)
208+
);
209+
}
127210
}

0 commit comments

Comments
 (0)