-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+simple endpoint test removed StatusResponse (not used)
- Loading branch information
Showing
4 changed files
with
168 additions
and
9 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |