Skip to content

Instantly share code, notes, and snippets.

@dracony
Created October 7, 2016 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dracony/65b5b3eabbf410e43c56fd5123608c88 to your computer and use it in GitHub Desktop.
Save dracony/65b5b3eabbf410e43c56fd5123608c88 to your computer and use it in GitHub Desktop.
<?php
namespace Rocket\Task\Tests\Service;
use PHPUnit_Framework_TestCase;
use Rocket\Task\Service\RocketRoute;
use SoapClient;
use DOMDocument;
class RocketRouteTest extends PHPUnit_Framework_TestCase
{
protected $config = [
'notamWsdl' => 'https://wsdl/',
'user' => 'user@email.com',
'password' => 'pass'
];
protected $notamRequest = '
<?xml version="1.0"?>
<REQNOTAM>
<USR>user@email.com</USR>
<PASSWD>1a1dc91c907325c69271ddf0c944bc72</PASSWD>
<ICAO>UKKK</ICAO>
</REQNOTAM>
';
protected $notamResponse = '
<?xml version="1.0" encoding="UTF-8"?>
<REQNOTAM>
<RESULT>0</RESULT>
<NOTAMSET ICAO="UKKK">
<NOTAM id="A2389/16">
<ItemQ>UKBV/QOBCE/IV/M /A /000/999/5024N03027E</ItemQ>
<ItemA>UKKK</ItemA>
<ItemB>1609261120</ItemB>
<ItemC>1612252359</ItemC>
<ItemD />
<ItemE>OBST ERECTED CRANE.</ItemE>
</NOTAM>
</NOTAMSET>
</REQNOTAM>
';
protected $rocketRoute;
public function setUp()
{
$this->rocketRoute = $this->getMockBuilder(RocketRoute::class)
->setMethods(['buildSoapClient'])
->setConstructorArgs([$this->config])
->getMock();
}
public function testSearchCode()
{
$soapClient = $this->getMockBuilder(SoapClient::class)
->setMethods(['getNotam'])
->disableOriginalConstructor()
->getMock();
$this->rocketRoute
->expects($this->once())
->method('buildSoapClient')
->with($this->config['notamWsdl'])
->willReturn($soapClient);
$soapClient
->expects($this->once())
->method('getNotam')
->with($this->normalizeXml($this->notamRequest))
->willReturn($this->normalizeXml($this->notamResponse));
$locations = $this->rocketRoute->searchNotam('UKKK');
$this->assertEquals([
[
'lat' => 50.40,
'lng' => 30.45,
'description' => 'OBST ERECTED CRANE.'
]
], $locations);
}
protected function normalizeXml($str)
{
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadXml(trim($str));
return $dom->saveXml();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment