Skip to content

Commit

Permalink
^phpunit 10.5.20
Browse files Browse the repository at this point in the history
+simple endpoint test
removed StatusResponse (not used)
  • Loading branch information
mathielen committed Jun 10, 2024
2 parents 7f3f5ab + ca17b58 commit a4e23ac
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/CXml/Model/CXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function __construct(
#[Serializer\XmlAttribute]
private readonly \DateTimeInterface $timestamp,
#[Serializer\SerializedName('Request')]
private readonly ?Request $request,
private readonly ?Request $request = null,
#[Serializer\SerializedName('Response')]
private readonly ?Response $response = null,
#[Serializer\SerializedName('Message')]
Expand Down
9 changes: 0 additions & 9 deletions src/CXml/Model/Response/StatusResponse.php

This file was deleted.

1 change: 1 addition & 0 deletions src/CXml/Processor/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Processor
CXmlNotImplementedException::class => 450,
];

// TODO create enum for this?
private static array $exceptionCodeMapping = [
// cxml
450 => 'Not Implemented',
Expand Down
111 changes: 111 additions & 0 deletions tests/CXmlTest/Handling/HandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

namespace CXmlTest\Handling;

use CXml\Authentication\SimpleSharedSecretAuthenticator;
use CXml\Builder;
use CXml\Context;
use CXml\Credential\Registry;
use CXml\Endpoint;
use CXml\Handler\HandlerInterface;
use CXml\Handler\HandlerRegistry;
use CXml\Model\Credential;
use CXml\Model\PayloadInterface;
use CXml\Model\Response\ResponsePayloadInterface;
use CXml\Processor\HeaderProcessor;
use CXml\Processor\Processor;
use CXml\Serializer;
use CXml\Validation\DtdValidator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
* @internal
* @coversNothing
*/
final class HandlerTest extends TestCase
{
public static function getEndpointData(): iterable
{
yield [
self::loadFixture('quote_request.xml'),
'QuoteMessage',
];

// TODO add more cases
}

private static function loadFixture(string $filename): ?string
{
return \file_get_contents(__DIR__ . '/fixtures/' . $filename);
}

#[DataProvider('getEndpointData')]
public function testEndpoint(string $requestCxml, string $expectedHandlerCalled): void
{
$serializer = Serializer::create();
$messageValidator = new DtdValidator(__DIR__ . '/../../metadata/cxml/dtd/1.2.050/');

$credentialRepository = new Registry();
$credentialRepository->registerCredential(
new Credential(
'NetworkId',
'AN00000123',
),
);
$credentialRepository->registerCredential(
new Credential(
'NetworkId',
'AN00000456',
),
);

$authenticator = new SimpleSharedSecretAuthenticator('Secret!123');

$requestProcessor = new HeaderProcessor(
$credentialRepository,
$authenticator,
);

$actualHandlerCalled = '(none)';

$quoteMessageHandler = new class($actualHandlerCalled) implements HandlerInterface {
public function __construct(private string &$actualHandlerCalled)
{
}

public static function getRequestName(): string
{
return 'QuoteMessage';
}

public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface
{
$this->actualHandlerCalled = 'QuoteMessage';

return null;
}
};

$handlerRegistry = new HandlerRegistry();
$handlerRegistry->register($quoteMessageHandler);

$builder = Builder::create();

$processor = new Processor(
$requestProcessor,
$handlerRegistry,
$builder,
);

$endpoint = new Endpoint(
$serializer,
$messageValidator,
$processor,
);

$endpoint->parseAndProcessStringAsCXml($requestCxml);

self::assertSame($expectedHandlerCalled, $actualHandlerCalled);
}
}
69 changes: 69 additions & 0 deletions tests/CXmlTest/Handling/fixtures/quote_request.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.060/cXML.dtd">
<cXML payloadID="0c30050@supplierorg.com" timestamp="2021-01-08T23:00:06-08:00" xml:lang="en-US">
<Header>
<From>
<Credential domain="NetworkId">
<Identity>AN00000123</Identity>
</Credential>
</From>
<To>
<Credential domain="NetworkId">
<Identity>AN00000456</Identity>
</Credential>
</To>
<Sender>
<Credential domain="NetworkId">
<Identity>AN00000123</Identity>
<SharedSecret>Secret!123</SharedSecret>
</Credential>
<UserAgent>Suppliers Super Order Processor</UserAgent>
</Sender>
</Header>
<Message>
<QuoteMessage>
<QuoteMessageHeader type="accept" currency="USD" quoteDate="2021-01-08T23:00:06-08:00" quoteID="quoteId" xml:lang="de">
<OrganizationID>
<Credential domain="domain">
<Identity>identity</Identity>
</Credential>
</OrganizationID>

<Total>
<Money currency="USD">100.00</Money>
</Total>

<ShipTo>
<Address>
<Name xml:lang="en">Acme Inc.</Name>
<PostalAddress>
<DeliverTo>Acme Inc.</DeliverTo>
<DeliverTo>Joe Smith</DeliverTo>
<Street>123 Anystreet</Street>
<City>Sunnyvale</City>
<State>CA</State>
<PostalCode>90489</PostalCode>
<Country isoCountryCode="US">United States</Country>
</PostalAddress>
<Phone name="company">
<TelephoneNumber>
<CountryCode isoCountryCode="US">1</CountryCode>
<AreaOrCityCode>800</AreaOrCityCode>
<Number>1234567</Number>
</TelephoneNumber>
</Phone>
</Address>
</ShipTo>

<Contact>
<Name xml:lang="en">Joe Smith</Name>
<Email>joe.smith@siemens.com</Email>
<IdReference identifier="123456" domain="GUID" />
</Contact>

<Comments>This is a comment</Comments>
<Extrinsic name="expiry_date">2023-01-08T23:00:06-08:00</Extrinsic>
</QuoteMessageHeader>
</QuoteMessage>
</Message>
</cXML>

0 comments on commit a4e23ac

Please sign in to comment.