Skip to content

Commit

Permalink
Add ID3 wsdl test for local element property
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Feb 12, 2020
1 parent d695c11 commit c78b78d
Show file tree
Hide file tree
Showing 8 changed files with 3,667 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/Client/Id3Generator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php


namespace GoetasWebservices\SoapServices\SoapClient\Tests\Client;


use GoetasWebservices\WsdlToPhp\Generation\JmsSoapConverter;
use GoetasWebservices\WsdlToPhp\Tests\Generator;
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlConverter;

class Id3Generator extends Generator
{
protected function generateJMSFiles(array $schemas, array $services)
{
$converter = new YamlConverter($this->namingStrategy);
$converter->addAliasMapType('http://www.w3.org/2001/XMLSchema', 'base64Binary', 'string');
$soapConverter = new JmsSoapConverter($converter);

$this->setNamespaces($converter);
$items = $converter->convert($schemas);
$items = array_merge($items, $soapConverter->visitServices($services));
return $items;
}
}
183 changes: 183 additions & 0 deletions tests/Client/Id3Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php


namespace GoetasWebservices\SoapServices\SoapClient\Tests\Client;

use GoetasWebservices\SoapServices\SoapClient\Arguments\Headers\Handler\HeaderHandler;
use GoetasWebservices\SoapServices\SoapClient\Arguments\Headers\Header;
use GoetasWebservices\SoapServices\SoapClient\Arguments\Headers\MustUnderstandHeader;
use GoetasWebservices\SoapServices\SoapClient\ClientFactory;
use GoetasWebservices\SoapServices\SoapClient\Envelope\Handler\FaultHandler;
use GoetasWebservices\SoapServices\SoapClient\Envelope\SoapEnvelope\Parts\Fault;
use GoetasWebservices\SoapServices\SoapClient\Exception\FaultException;
use GoetasWebservices\SoapServices\SoapClient\Metadata\Generator\MetadataGenerator;
use GoetasWebservices\SoapServices\SoapClient\Metadata\Loader\DevMetadataLoader;
use GoetasWebservices\WsdlToPhp\Tests\Generator;
use GoetasWebservices\XML\SOAPReader\SoapReader;
use GoetasWebservices\XML\WSDLReader\DefinitionsReader;
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Response;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
use JMS\Serializer\Handler\HandlerRegistryInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

class Id3Test extends \PHPUnit_Framework_TestCase
{
protected static $namespaces = [
'http://biometricid.id3.eu/'=> 'Id3\Biom',
'http://docs.oasis-open.org/bias/ns/bias-2.0/'=> 'Id3\Bias',
'http://biometricid.id3.eu/ws/types'=> 'Id3\Biom\Types',
'http://bias.biometricid.id3.eu/'=> 'Id3\Biom\Bias',
'http://standards.iso.org/iso-iec/19785/-3/ed-2/'=> 'Id3\ISO19785',
'http://standards.iso.org/iso/3166/-1/ed-3/'=> 'Id3\ISO3166'
];
/**
* @var Generator
*/
protected static $generator;

/**
* @var \GuzzleHttp\Handler\MockHandler
*/
protected $responseMock;

protected $requestResponseStack = [];

/**
* @var ClientFactory
*/
private $factory;

public static function setUpBeforeClass()
{
self::$generator = new Id3Generator(self::$namespaces);
self::$generator->generate([__DIR__ . '/../Fixtures/Id3/Id3BiometricIdServicePort.wsdl']);
self::$generator->registerAutoloader();
}

public static function tearDownAfterClass()
{
self::$generator->unRegisterAutoloader();
//self::$generator->cleanDirectories();
}

public function setUp()
{
$ref = new \ReflectionClass(Fault::class);
$headerHandler = new HeaderHandler();
$serializer = self::$generator->buildSerializer(function (HandlerRegistryInterface $h) use ($headerHandler) {
$h->registerSubscribingHandler($headerHandler);
$h->registerSubscribingHandler(new FaultHandler());
}, [
'GoetasWebservices\SoapServices\SoapClient\Envelope\SoapEnvelope12' => dirname($ref->getFileName()) . '/../../../Resources/metadata/jms12',
'GoetasWebservices\SoapServices\SoapClient\Envelope\SoapEnvelope' => dirname($ref->getFileName()) . '/../../../Resources/metadata/jms',
]);

$this->responseMock = new MockHandler();
$history = Middleware::history($this->requestResponseStack);

$handler = HandlerStack::create($this->responseMock);
$handler->push($history);

$guzzle = new Client(['handler' => $handler]);


$naming = new ShortNamingStrategy();
$dispatcher = new EventDispatcher();
$wsdlReader = new DefinitionsReader(null, $dispatcher);
$soapReader = new SoapReader();
$dispatcher->addSubscriber($soapReader);

$metadataGenerator = new MetadataGenerator($naming, self::$namespaces);
$metadataLoader = new DevMetadataLoader($metadataGenerator, $soapReader, $wsdlReader);


$this->factory = new ClientFactory($metadataLoader, $serializer);
$this->factory->setHttpClient(new GuzzleAdapter($guzzle));
$this->factory->setHeaderHandler($headerHandler);
}

public function testIdentifySubject() {
$httpResponse = new Response(200, ['Content-Type' => 'application/soap+xml'], '
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<ns2:IdentifySubjectResponse xmlns:ns2="http://biometricid.id3.eu/"
xmlns:ns3="http://docs.oasis-open.org/bias/ns/bias-2.0/"
xmlns:ns4="http://standards.iso.org/iso-iec/19785/-3/ed-2/">
<ns2:IdentifySubjectResponsePackage>
<errorCode>0</errorCode>
<token>
<ns3:TokenValue>200212001623138IDENTIFYSUBJ00001</ns3:TokenValue>
</token>
</ns2:IdentifySubjectResponsePackage>
</ns2:IdentifySubjectResponse>
</soap:Body>
</soap:Envelope>');

$this->responseMock->append($httpResponse);

$client = $this->factory->getClient(__DIR__ . '/../Fixtures/Id3/Id3BiometricIdServicePort.wsdl');
$this->assertNull($client->__getLastRequestMessage());

$identifySubjectRequestType = "Id3\Biom\IdentifySubjectRequest";
$personalDataType = "Id3\Biom\PersonalData";
$candidateBiometricType = "Id3\Biom\Bias\CandidateBiometricType";

$personalData = new $personalDataType();
$personalData->setFingerDataRecord([]);

$candidate = new $candidateBiometricType();
$candidate->setFormatOwner(27);
$candidate->setFormatType(32775);
$candidate->setType("finger");
$candidate->setSubtype("17");
//$candidate->setData($data);
$candidate->setAnnotation(0);
$candidate->setQuality(100);

$personalData->addToFingerDataRecord($candidate);

$req = new $identifySubjectRequestType();
$req->setData($personalData);

$response = $client->identifySubject($req);

$this->assertXmlStringEqualsXmlString(
'
<SOAP:Envelope xmlns:SOAP="http://www.w3.org/2003/05/soap-envelope">
<SOAP:Body>
<ns-4c7934d9:IdentifySubject xmlns:ns-4c7934d9="http://biometricid.id3.eu/">
<ns-4c7934d9:IdentifySubjectRequest>
<data>
<FingerDataRecord>
<FingerprintData>
<format_owner>27</format_owner>
<format_type>32775</format_type>
<type><![CDATA[finger]]></type>
<subtype><![CDATA[17]]></subtype>
<annotation>0</annotation>
<quality>100</quality>
</FingerprintData>
</FingerDataRecord>
</data>
</ns-4c7934d9:IdentifySubjectRequest>
</ns-4c7934d9:IdentifySubject>
</SOAP:Body>
</SOAP:Envelope>',
(string)$client->__getLastRequestMessage()->getBody());

$package = $response->getIdentifySubjectResponsePackage();
$this->assertNotNull($package);
$this->assertEquals(0, $package->getErrorCode());
$token = $package->getToken();

$this->assertEquals("200212001623138IDENTIFYSUBJ00001", $token->getTokenValue());


}
}
Loading

0 comments on commit c78b78d

Please sign in to comment.