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 42f93a3
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 9 deletions.
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
98 changes: 98 additions & 0 deletions tests/CXmlTest/Handling/EndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?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;

class EndpointTest extends TestCase
{

public static function getEndpointData(): iterable
{
yield [
self::loadFixture('quote_request.xml'),
null,
];

// 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 $expectedResponseCxml): 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
);

$handlerRegistry = new HandlerRegistry();
$handlerRegistry->register(new class() implements HandlerInterface {
public static function getRequestName(): string
{
return 'QuoteMessage';
}

public function handle(PayloadInterface $payload, Context $context): ?ResponsePayloadInterface
{
return null;
}
});


$builder = Builder::create();

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

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

$actualResponseCxml = $endpoint->parseAndProcessStringAsCXml($requestCxml);
$this->assertEquals($expectedResponseCxml, $actualResponseCxml);
}
}
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="[email protected]" 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>[email protected]</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 42f93a3

Please sign in to comment.