Skip to content

Commit

Permalink
Issue #62: Rename fromXml() to withXml().
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Nov 3, 2017
1 parent 1b7d1fb commit 89defad
Show file tree
Hide file tree
Showing 23 changed files with 35 additions and 42 deletions.
2 changes: 2 additions & 0 deletions src/Messages/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use EC\Poetry\Messages\Traits\ArrayAccessTrait;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
use EC\Poetry\Messages\Traits\ParserAwareTrait;

/**
* Class AbstractMessage
Expand All @@ -15,6 +16,7 @@
abstract class AbstractMessage implements MessageInterface
{
use ArrayAccessTrait;
use ParserAwareTrait;

const COMMUNICATION_SYNCHRONOUS = 'synchrone';
const COMMUNICATION_ASYNCHRONOUS = 'asynchrone';
Expand Down
2 changes: 1 addition & 1 deletion src/Messages/ComponentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @package EC\Poetry\Messages
*/
interface ComponentInterface extends \ArrayAccess
interface ComponentInterface extends ParserAwareInterface, \ArrayAccess
{
/**
* Get template name.
Expand Down
5 changes: 2 additions & 3 deletions src/Messages/Components/AbstractComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
use EC\Poetry\Messages\ComponentInterface;
use EC\Poetry\Messages\Traits\ArrayAccessTrait;
use EC\Poetry\Messages\Traits\ParserAwareTrait;
use EC\Poetry\Messages\ParserAwareInterface;

/**
* Class AbstractComponent
*
* @package EC\Poetry\Messages\Components
*/
abstract class AbstractComponent implements ComponentInterface, ParserAwareInterface
abstract class AbstractComponent implements ComponentInterface
{
use ArrayAccessTrait;
use ParserAwareTrait;
Expand All @@ -36,7 +35,7 @@ public function getAttributes()
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
*/
public function fromXml($xml)
public function withXml($xml)
{
$this->setRaw($xml);

Expand Down
2 changes: 1 addition & 1 deletion src/Messages/Components/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private function parseSourceLanguage(Parser $parser)
$parser->eachComponent("documentSource/documentSourceLang", function (Parser $language) {
$this->withSourceLanguage()
->setParser($this->getParser())
->fromXml($language->outerHtml());
->withXml($language->outerHtml());
}, $this);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Messages/Notifications/AbstractNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use EC\Poetry\Events\ParseNotificationEvent;
use EC\Poetry\Messages\AbstractMessage;
use EC\Poetry\Messages\Traits\ParserAwareTrait;
use EC\Poetry\Messages\ParserAwareInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

Expand All @@ -15,7 +14,6 @@
*/
abstract class AbstractNotification extends AbstractMessage implements ParserAwareInterface, EventSubscriberInterface
{
use ParserAwareTrait;

/**
* {@inheritdoc}
Expand All @@ -42,7 +40,7 @@ abstract public function onParseNotification(ParseNotificationEvent $event);
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
*/
public function fromXml($xml)
public function withXml($xml)
{
$this->setRaw($xml);

Expand Down
8 changes: 4 additions & 4 deletions src/Messages/Notifications/StatusUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function onParseNotification(ParseNotificationEvent $event)
$parser = $this->getParser();
$parser->addXmlContent($event->getXml());
if ('status' === $parser->getAttribute('POETRY/request', 'type')) {
$this->fromXml($event->getXml());
$this->withXml($event->getXml());
$event->setEvent(new StatusUpdatedEvent($this));
$event->stopPropagation();
}
Expand All @@ -49,20 +49,20 @@ protected function parseXml($xml)
$parser->addXmlContent($xml);

$xml = $parser->getOuterContent('POETRY/request/demandeId');
$this->getIdentifier()->fromXml($xml);
$this->getIdentifier()->withXml($xml);

$this->setMessageId($parser->getAttribute('POETRY/request', 'id'));

$parser->eachComponent("POETRY/request/status", function (Parser $component) {
$this->withStatus()
->setParser($this->getParser())
->fromXml($component->outerHtml());
->withXml($component->outerHtml());
}, $this);

$parser->eachComponent("POETRY/request/attributions", function (Parser $component) {
$this->withTarget()
->setParser($this->getParser())
->fromXml($component->outerHtml());
->withXml($component->outerHtml());
}, $this);

return $this;
Expand Down
6 changes: 3 additions & 3 deletions src/Messages/Notifications/TranslationReceived.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function onParseNotification(ParseNotificationEvent $event)
$parser = $this->getParser();
$parser->addXmlContent($event->getXml());
if ('translation' === $parser->getAttribute('POETRY/request', 'type')) {
$this->fromXml($event->getXml());
$this->withXml($event->getXml());
$event->setEvent(new TranslationReceivedEvent($this));
$event->stopPropagation();
}
Expand All @@ -47,14 +47,14 @@ protected function parseXml($xml)
$parser->addXmlContent($xml);

$xml = $parser->getOuterContent('POETRY/request/demandeId');
$this->getIdentifier()->fromXml($xml);
$this->getIdentifier()->withXml($xml);

$this->setMessageId($parser->getAttribute('POETRY/request', 'id'));

$parser->eachComponent("POETRY/request/attributions", function (Parser $component) {
$this->withTarget()
->setParser($this->getParser())
->fromXml($component->outerHtml());
->withXml($component->outerHtml());
}, $this);

return $this;
Expand Down
5 changes: 1 addition & 4 deletions src/Messages/Requests/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use EC\Poetry\Messages\AbstractMessage;
use EC\Poetry\Messages\Components\Identifier;
use EC\Poetry\Messages\ParserAwareInterface;
use EC\Poetry\Messages\Traits\ParserAwareTrait;
use EC\Poetry\Services\Settings;

/**
Expand All @@ -15,8 +14,6 @@
*/
abstract class AbstractRequest extends AbstractMessage implements ParserAwareInterface
{
use ParserAwareTrait;

const REQUEST_NEW = 'new';
const REQUEST_POST = 'post';
const REQUEST_NEW_POST = 'newPost';
Expand Down Expand Up @@ -64,7 +61,7 @@ abstract public function getType();
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
*/
public function fromXml($xml)
public function withXml($xml)
{
$this->setRaw($xml);

Expand Down
4 changes: 1 addition & 3 deletions src/Messages/Responses/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use EC\Poetry\Events\ParseResponseEvent;
use EC\Poetry\Messages\AbstractMessage;
use EC\Poetry\Messages\Traits\ParserAwareTrait;

/**
* Class AbstractResponse.
Expand All @@ -13,7 +12,6 @@
*/
abstract class AbstractResponse extends AbstractMessage implements ResponseInterface
{
use ParserAwareTrait;

/**
* {@inheritdoc}
Expand All @@ -40,7 +38,7 @@ abstract public function onParseResponse(ParseResponseEvent $event);
*
* @return \EC\Poetry\Messages\MessageInterface|\EC\Poetry\Messages\ComponentInterface
*/
public function fromXml($xml)
public function withXml($xml)
{
$this->setRaw($xml);

Expand Down
3 changes: 1 addition & 2 deletions src/Messages/Responses/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace EC\Poetry\Messages\Responses;

use EC\Poetry\Messages\ParserAwareInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Interface ResponseInterface
*
* @package EC\Poetry\Messages\Responses
*/
interface ResponseInterface extends ParserAwareInterface, EventSubscriberInterface
interface ResponseInterface extends EventSubscriberInterface
{

}
6 changes: 3 additions & 3 deletions src/Messages/Responses/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function onParseResponse(ParseResponseEvent $event)
$parser = $this->getParser();
$parser->addXmlContent($event->getXml());
if ($parser->getContent('POETRY/request/status') !== null) {
$event->setMessage($this->fromXml($event->getXml()));
$event->setMessage($this->withXml($event->getXml()));
$event->stopPropagation();
}
}
Expand All @@ -47,14 +47,14 @@ protected function parseXml($xml)
$parser->addXmlContent($xml);

$xml = $parser->getOuterContent('POETRY/request/demandeId');
$this->getIdentifier()->fromXml($xml);
$this->getIdentifier()->withXml($xml);

$this->setMessageId($parser->getAttribute('POETRY/request', 'id'));

$parser->eachComponent("POETRY/request/status", function (Parser $component) {
$this->withStatus()
->setParser($this->getParser())
->fromXml($component->outerHtml());
->withXml($component->outerHtml());
}, $this);

return $this;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Messages/Components/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testValidation()
public function testParsing($xml, $type, $nickname, $email)
{
/** @var \EC\Poetry\Messages\Components\Contact $component */
$component = $this->getContainer()->get('component.contact')->fromXml($xml);
$component = $this->getContainer()->get('component.contact')->withXml($xml);

expect($component->getType())->to->equal($type);
expect($component->getNickname())->to->equal($nickname);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Messages/Components/DetailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testValidation()
public function testParsing($xml, $fixtures)
{
/** @var \EC\Poetry\Messages\Components\Details $component */
$component = $this->getContainer()->get('component.details')->fromXml($xml);
$component = $this->getContainer()->get('component.details')->withXml($xml);

foreach ($fixtures as $method => $value) {
expect($component->$method())->to->equal($value);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Messages/Components/IdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testValidation()
public function testParsing($xml, $code, $year, $number, $version, $part, $product)
{
/** @var \EC\Poetry\Messages\Components\Identifier $component */
$component = $this->getContainer()->get('component.identifier')->fromXml($xml);
$component = $this->getContainer()->get('component.identifier')->withXml($xml);

expect($component->getCode())->to->equal($code);
expect($component->getYear())->to->equal($year);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Messages/Components/ReferenceDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testValidation()
public function testParsing($xml, $fixtures)
{
/** @var \EC\Poetry\Messages\Components\ReferenceDocument $component */
$component = $this->getContainer()->get('component.reference_document')->fromXml($xml);
$component = $this->getContainer()->get('component.reference_document')->withXml($xml);
foreach ($fixtures as $method => $value) {
expect($component->$method())->to->equal($value);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Messages/Components/ReturnAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testValidation()
public function testParsing($xml, $fixtures)
{
/** @var \EC\Poetry\Messages\Components\ReturnAddress $component */
$component = $this->getContainer()->get('component.return_address')->fromXml($xml);
$component = $this->getContainer()->get('component.return_address')->withXml($xml);

foreach ($fixtures as $method => $value) {
expect($component->$method())->to->equal($value);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Messages/Components/SourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testValidation()
public function testParsing($xml, $expected)
{
/** @var \EC\Poetry\Messages\Components\Source $component */
$component = $this->getContainer()->get('component.source')->fromXml($xml);
$component = $this->getContainer()->get('component.source')->withXml($xml);

foreach ($expected as $getComponent => $properties) {
if ($this->isComponentCollection($properties)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Messages/Components/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testValidation()
public function testParsing($xml, $date, $time, $message, $code, $type)
{
/** @var \EC\Poetry\Messages\Components\Status $component */
$component = $this->getContainer()->get('component.status')->fromXml($xml);
$component = $this->getContainer()->get('component.status')->withXml($xml);

expect($component->getDate())->to->equal($date);
expect($component->getTime())->to->equal($time);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Messages/Components/TargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testValidation()
public function testParsing($xml, $targetProperties, $addressProperties, $contactProperties)
{
/** @var \EC\Poetry\Messages\Components\Target $target */
$target = $this->getContainer()->get('component.target')->fromXml($xml);
$target = $this->getContainer()->get('component.target')->withXml($xml);

foreach ($targetProperties as $method => $value) {
expect($target->$method())->to->equal($value);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Messages/Notifications/StatusUpdatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testRender()
public function testParsing($xml, $identifier, $statuses, $targets)
{
/** @var \EC\Poetry\Messages\Notifications\StatusUpdated $message */
$message = $this->getContainer()->get('notification.status_updated')->fromXml($xml);
$message = $this->getContainer()->get('notification.status_updated')->withXml($xml);

foreach ($identifier as $method => $expected) {
expect($message->getIdentifier()->{$method}())->to->equal($expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testRender()
public function testParsing($xml, $identifier, $targets)
{
/** @var \EC\Poetry\Messages\Notifications\TranslationReceived $message */
$message = $this->getContainer()->get('notification.translation_received')->fromXml($xml);
$message = $this->getContainer()->get('notification.translation_received')->withXml($xml);

foreach ($identifier as $method => $expected) {
expect($message->getIdentifier()->{$method}())->to->equal($expected);
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Messages/Responses/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class StatusTest extends AbstractTest
public function testParsing($xml, $identifier, $statuses)
{
/** @var \EC\Poetry\Messages\Responses\Status $message */
$message = $this->getContainer()->get('response.status')->fromXml($xml);
$message = $this->getContainer()->get('response.status')->withXml($xml);

foreach ($identifier as $method => $expected) {
expect($message->getIdentifier()->{$method}())->to->equal($expected);
Expand All @@ -52,7 +52,7 @@ public function testParsing($xml, $identifier, $statuses)
public function testValidation($xml, array $expectations)
{
/** @var \EC\Poetry\Messages\Responses\Status $message */
$message = $this->getContainer()->get('response.status')->fromXml($xml);
$message = $this->getContainer()->get('response.status')->withXml($xml);
foreach ($expectations as $method => $result) {
if (is_array($result) && is_numeric(key($result))) {
foreach ($result as $key => $values) {
Expand Down
6 changes: 3 additions & 3 deletions tests/src/NotificationHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testFunctionCallback()
$message = $this->getFixture('messages/notifications/status-updated.xml');
$response = $this->notifyServer('/notification', 'username', 'password', $message);
/** @var \EC\Poetry\Messages\Responses\Status $status */
$status = $this->getContainer()->get('response.status')->fromXml($response);
$status = $this->getContainer()->get('response.status')->withXml($response);
expect($status->getMessageId())->to->be->equal('1069698');
date_default_timezone_set('Europe/Brussels');
expect($status->getStatuses()[0]->getDate())->to->be->equal(date('d/m/Y'));
Expand All @@ -69,15 +69,15 @@ public function testFunctionCallback()
$message = $this->getFixture('messages/notifications/status-updated-nok.xml');
$response = $this->notifyServer('/notification', 'username', 'password', $message);
/** @var \EC\Poetry\Messages\Responses\Status $status */
$status = $this->getContainer()->get('response.status')->fromXml($response);
$status = $this->getContainer()->get('response.status')->withXml($response);
expect($status->getStatuses()[0]->getMessage())->to->be->equal('identifier.year: This value should be greater than 2000.');
expect($status->getStatuses()[0]->getCode())->to->be->equal('-1');

// Test an incorrect authentication.
$message = $this->getFixture('messages/notifications/status-updated.xml');
$response = $this->notifyServer('/notification', 'wrong-username', 'wrong-password', $message);
/** @var \EC\Poetry\Messages\Responses\Status $status */
$status = $this->getContainer()->get('response.status')->fromXml($response);
$status = $this->getContainer()->get('response.status')->withXml($response);
expect($status->getStatuses()[0]->getMessage())->to->be->equal('Poetry service cannot authenticate on notification callback: username or password not valid.');
expect($status->getStatuses()[0]->getCode())->to->be->equal('-1');
}
Expand Down

0 comments on commit 89defad

Please sign in to comment.