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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"require": {
"php": "^8.1",
"ext-soap": "*",
"scn/evalanche-soap-api-struct": "^2.4",
"scn/evalanche-soap-api-struct": "^2.5",
"scn/hydrator": "^2|^3",
"scn/hydrator-property-values": "^2.0|^3.0"
},
Expand Down
179 changes: 99 additions & 80 deletions composer.lock

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions src/Client/Generic/ContentGenerationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Scn\EvalancheSoapApiConnector\Client\Generic;

use Scn\EvalancheSoapApiConnector\Exception\EmptyResultException;
use Scn\EvalancheSoapStruct\Struct\Generic\HashMapInterface;
use Scn\EvalancheSoapStruct\Struct\Generic\JobStateInterface;

interface ContentGenerationInterface extends GetJobStateInterface
{
/**
* Runs the content-generation
*
* @throws EmptyResultException
*/
public function runContentGeneration(
int $id,
HashMapInterface $variables
): JobStateInterface;
}
31 changes: 31 additions & 0 deletions src/Client/Generic/ContentGenerationTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Scn\EvalancheSoapApiConnector\Client\Generic;

use Scn\EvalancheSoapStruct\Struct\Generic\HashMapInterface;
use Scn\EvalancheSoapStruct\Struct\Generic\JobStateInterface;

trait ContentGenerationTrait
{
use GetJobStateTrait;

/** @inheritDoc */
public function runContentGeneration(
int $id,
HashMapInterface $variables
): JobStateInterface {
return $this->responseMapper->getObject(
$this->soapClient->runContentGeneration([
'resource_id' => $id,
'variables' => $this->extractor->extract(
$this->hydratorConfigFactory->createHashMapConfig(),
$variables
)
]),
'runContentGenerationResult',
$this->hydratorConfigFactory->createJobStateConfig()
);
}
}
20 changes: 20 additions & 0 deletions src/Client/Generic/GetJobStateInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Scn\EvalancheSoapApiConnector\Client\Generic;

use Scn\EvalancheSoapApiConnector\Exception\EmptyResultException;
use Scn\EvalancheSoapStruct\Struct\Generic\JobStateInterface;

interface GetJobStateInterface
{
/**
* Returns the state of a background-job
*
* @throws EmptyResultException
*/
public function getJobState(
string $job_id,
): JobStateInterface;
}
23 changes: 23 additions & 0 deletions src/Client/Generic/GetJobStateTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Scn\EvalancheSoapApiConnector\Client\Generic;

use Scn\EvalancheSoapStruct\Struct\Generic\JobStateInterface;

trait GetJobStateTrait
{
/** @inheritDoc */
public function getJobState(
string $job_id,
): JobStateInterface {
return $this->responseMapper->getObject(
$this->soapClient->getJobState([
'job_id' => $job_id,
]),
'getJobStateResult',
$this->hydratorConfigFactory->createJobStateConfig()
);
}
}
2 changes: 2 additions & 0 deletions src/Client/LeadPage/LeadpageClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Scn\EvalancheSoapApiConnector\Client\AbstractClient;
use Scn\EvalancheSoapApiConnector\Client\ClientInterface;
use Scn\EvalancheSoapApiConnector\Client\Generic\ContentGenerationTrait;
use Scn\EvalancheSoapApiConnector\Client\Generic\EditorModuleTypesTrait;
use Scn\EvalancheSoapApiConnector\Client\Generic\ResourceTrait;
use Scn\EvalancheSoapApiConnector\Exception\EmptyResultException;
Expand All @@ -15,6 +16,7 @@

class LeadpageClient extends AbstractClient implements LeadpageClientInterface
{
use ContentGenerationTrait;
use ResourceTrait;
use EditorModuleTypesTrait;
const PORTNAME = 'leadpage';
Expand Down
7 changes: 6 additions & 1 deletion src/Client/LeadPage/LeadpageClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
namespace Scn\EvalancheSoapApiConnector\Client\LeadPage;

use Scn\EvalancheSoapApiConnector\Client\ClientInterface;
use Scn\EvalancheSoapApiConnector\Client\Generic\ContentGenerationInterface;
use Scn\EvalancheSoapApiConnector\Client\Generic\EditorModulesTypesTraitInterface;
use Scn\EvalancheSoapApiConnector\Client\Generic\ResourceTraitInterface;
use Scn\EvalancheSoapApiConnector\Exception\EmptyResultException;
use Scn\EvalancheSoapStruct\Struct\Generic\HashMapInterface;
use Scn\EvalancheSoapStruct\Struct\Generic\ResourceInformationInterface;
use Scn\EvalancheSoapStruct\Struct\LeadPage\LeadpageConfigurationInterface;

interface LeadpageClientInterface extends ResourceTraitInterface, EditorModulesTypesTraitInterface, ClientInterface
interface LeadpageClientInterface extends
ContentGenerationInterface,
ResourceTraitInterface,
EditorModulesTypesTraitInterface,
ClientInterface
{
/**
* @param int $id
Expand Down
2 changes: 2 additions & 0 deletions src/Client/Mailing/MailingClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Scn\EvalancheSoapApiConnector\Client\AbstractClient;
use Scn\EvalancheSoapApiConnector\Client\ClientInterface;
use Scn\EvalancheSoapApiConnector\Client\Generic\ContentGenerationTrait;
use Scn\EvalancheSoapApiConnector\Client\Generic\EditorModuleTypesTrait;
use Scn\EvalancheSoapApiConnector\Client\Generic\ResourceTrait;
use Scn\EvalancheSoapApiConnector\Exception\EmptyResultException;
Expand All @@ -29,6 +30,7 @@
*/
final class MailingClient extends AbstractClient implements MailingClientInterface
{
use ContentGenerationTrait;
use ResourceTrait;
use EditorModuleTypesTrait;
const PORTNAME = 'mailing';
Expand Down
7 changes: 6 additions & 1 deletion src/Client/Mailing/MailingClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Scn\EvalancheSoapApiConnector\Client\Mailing;

use Scn\EvalancheSoapApiConnector\Client\ClientInterface;
use Scn\EvalancheSoapApiConnector\Client\Generic\ContentGenerationInterface;
use Scn\EvalancheSoapApiConnector\Client\Generic\EditorModulesTypesTraitInterface;
use Scn\EvalancheSoapApiConnector\Client\Generic\ResourceTraitInterface;
use Scn\EvalancheSoapApiConnector\Exception\EmptyResultException;
Expand All @@ -29,7 +30,11 @@
*
* @package Scn\EvalancheSoapApiConnector\Client\Mailing
*/
interface MailingClientInterface extends ResourceTraitInterface, EditorModulesTypesTraitInterface, ClientInterface
interface MailingClientInterface extends
ContentGenerationInterface,
ResourceTraitInterface,
EditorModulesTypesTraitInterface,
ClientInterface
{
/**
* @param int $id
Expand Down
49 changes: 49 additions & 0 deletions src/Hydrator/Config/Generic/JobStateConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Scn\EvalancheSoapApiConnector\Hydrator\Config\Generic;

use Scn\EvalancheSoapApiConnector\Hydrator\Config\HydratorConfigInterface;
use Scn\EvalancheSoapStruct\Struct\Generic\JobState;
use Scn\EvalancheSoapStruct\Struct\StructInterface;
use Scn\HydratorPropertyValues\Property\IntegerValue;
use Scn\HydratorPropertyValues\Property\StringValue;

/**
* @package Scn\EvalancheSoapApiConnector\Hydrator\Generic
*/
class JobStateConfig implements HydratorConfigInterface
{
/**
* @return StructInterface
*/
public function getObject(): StructInterface
{
return new JobState();
}

/**
* @return array
*/
public function getHydratorProperties(): array
{
return [
'id' => StringValue::set('id'),
'status' => IntegerValue::set('status'),
'status_description' => StringValue::set('statusDescription'),
];
}

/**
* @return array
*/
public function getExtractorProperties(): array
{
return [
'id' => StringValue::get('id'),
'status' => IntegerValue::get('status'),
'status_description' => StringValue::get('statusDescription'),
];
}
}
6 changes: 6 additions & 0 deletions src/Hydrator/Config/HydratorConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Scn\EvalancheSoapApiConnector\Hydrator\Config\Generic\HashMapConfig;
use Scn\EvalancheSoapApiConnector\Hydrator\Config\Generic\JobHandleConfig;
use Scn\EvalancheSoapApiConnector\Hydrator\Config\Generic\JobResultConfig;
use Scn\EvalancheSoapApiConnector\Hydrator\Config\Generic\JobStateConfig;
use Scn\EvalancheSoapApiConnector\Hydrator\Config\Generic\MassUpdateResultConfig;
use Scn\EvalancheSoapApiConnector\Hydrator\Config\Generic\ResourceInformationConfig;
use Scn\EvalancheSoapApiConnector\Hydrator\Config\Generic\ResourceTypeInformationConfig;
Expand Down Expand Up @@ -376,4 +377,9 @@ public function createMailingTemplateAllowedTemplatesConfig(): HydratorConfigInt
{
return new MailingTemplateAllowedTemplatesConfig();
}

public function createJobStateConfig(): HydratorConfigInterface
{
return new JobStateConfig();
}
}
2 changes: 2 additions & 0 deletions src/Hydrator/Config/HydratorConfigFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@ public function createContainerDetailConfig(): HydratorConfigInterface;
public function createArticleIndividualizationConfig(): HydratorConfigInterface;

public function createMailingTemplateAllowedTemplatesConfig(): HydratorConfigInterface;

public function createJobStateConfig(): HydratorConfigInterface;
}
90 changes: 89 additions & 1 deletion tests/Client/Mailing/MailingClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Scn\EvalancheSoapStruct\Struct\Generic\HashMapInterface;
use Scn\EvalancheSoapStruct\Struct\Generic\JobHandleInterface;
use Scn\EvalancheSoapStruct\Struct\Generic\JobResultInterface;
use Scn\EvalancheSoapStruct\Struct\Generic\JobStateInterface;
use Scn\EvalancheSoapStruct\Struct\Generic\ResourceInformationInterface;
use Scn\EvalancheSoapStruct\Struct\Generic\ResourceTypeInformationInterface;
use Scn\EvalancheSoapStruct\Struct\Generic\ServiceStatusInterface;
Expand Down Expand Up @@ -115,7 +116,9 @@ public function setUp(): void
'getContentContainerData',
'setContentContainerData',
'updateModuleTypes',
'retrieveModuleTypes'
'retrieveModuleTypes',
'runContentGeneration',
'getJobState',
]);
$this->responseMapper = $this->getMockBuilder(ResponseMapperInterface::class)->getMock();
$this->hydratorConfigFactory = $this->getMockBuilder(HydratorConfigFactoryInterface::class)->getMock();
Expand Down Expand Up @@ -1592,4 +1595,89 @@ public function testGetModuleTypesCanReturnString(): void

static::assertSame('some-thing', $this->subject->getModuleTypes($id));
}

public function testRunContentGenerationReturnsData(): void
{
$id = 666;
$extractedData = ['some' => 'data'];

$hashMapConfig = $this->createMock(HydratorConfigInterface::class);
$hydrator = $this->createMock(HydratorConfigInterface::class);
$result = $this->createMock(JobStateInterface::class);
$variables = $this->createMock(HashMapInterface::class);

$response = new stdClass();
$response->runContentGenerationResult = $result;

$this->hydratorConfigFactory->expects($this->once())
->method('createHashMapConfig')
->willReturn($hashMapConfig);
$this->hydratorConfigFactory->expects($this->once())
->method('createJobStateConfig')
->willReturn($hydrator);

$this->soapClient->expects($this->once())
->method('runContentGeneration')
->with([
'resource_id' => $id,
'variables' => $extractedData
])->willReturn($response);

$this->responseMapper->expects($this->once())
->method('getObject')
->with(
$response,
'runContentGenerationResult',
$hydrator
)
->willReturn($response->runContentGenerationResult);

$this->extractor->expects($this->once())
->method('extract')
->with(
$hashMapConfig,
$variables
)
->willReturn($extractedData);

self::assertSame(
$result,
$this->subject->runContentGeneration($id, $variables)
);
}

public function testGetJobStateReturnsData(): void
{
$id = 'some-id';

$hydrator = $this->createMock(HydratorConfigInterface::class);
$result = $this->createMock(JobStateInterface::class);

$response = new stdClass();
$response->getJobStateResult = $result;

$this->hydratorConfigFactory->expects($this->once())
->method('createJobStateConfig')
->willReturn($hydrator);

$this->soapClient->expects($this->once())
->method('getJobState')
->with([
'job_id' => $id,
])->willReturn($response);

$this->responseMapper->expects($this->once())
->method('getObject')
->with(
$response,
'getJobStateResult',
$hydrator
)
->willReturn($response->getJobStateResult);

self::assertSame(
$result,
$this->subject->getJobState($id)
);
}
}
Loading