Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small amendments #33

Closed
wants to merge 1 commit into from
Closed
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 @@ -37,7 +37,7 @@
"symfony/routing": "If you want to use SelfAwareProfileRequestHandler"
},
"require-dev": {
"phpunit/phpunit": "^9.6.13",
"phpunit/phpunit": "^10.5.20",
"phpstan/phpstan": "^1.10.41",
"friendsofphp/php-cs-fixer": "*",
"php-parallel-lint/php-parallel-lint": "*",
Expand Down
7 changes: 0 additions & 7 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 @@ -34,6 +34,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>
Loading