function setUp() { Config::setIdSeparator(false); XmlSerializer::$sort = false; $this->curl = $curl = m::mock('Curl'); $factory = m::mock(new Factory()); $factory->shouldReceive('createHttpsClient')->with('the user', 'the passw')->andReturn($curl); Config::setFactory($factory); Config::set('the user', 'the passw', Config::ENV_SANDBOX); }
function testCall() { XmlSerializer::$sort = true; $data = $this->schemaRequest('WpfPayment.json'); $requestXml = $this->schemaRequest('WpfPayment.xml'); $responseXml = $this->schemaResponse('WpfPayment_new.xml'); $this->curlMock()->shouldReceive('xmlPost')->with('https://testpayment.hypercharge.net/payment', $requestXml)->once()->andReturn($responseXml); $request = new PaymentRequest($data['payment']); $url = new PaymentUrl(Config::getMode()); $ws = new XmlWebservice(); $response = $ws->call($url, $request); $this->assertIsA($response, 'Hypercharge\\Payment'); $this->assertEqual($response->type, 'WpfPayment'); }
function testEachWith3Pages() { XmlSerializer::$sort = false; $curl = $this->curlMock(3); $data = array('start_date' => '2013-06-05', 'period' => 'P1W'); $requestXml = '<?xml version="1.0" encoding="UTF-8"?> <reconcile> <start_date>2013-06-05</start_date> <end_date>2013-06-12</end_date> <page>1</page> </reconcile> '; $curl->shouldReceive('xmlPost')->with('https://test.hypercharge.net/reconcile/by_date/CHANNEL_TOKEN', $requestXml)->once()->andReturn($this->schemaResponse('reconcile_by_date_page_1.xml')); $requestXml = '<?xml version="1.0" encoding="UTF-8"?> <reconcile> <start_date>2013-06-05</start_date> <end_date>2013-06-12</end_date> <page>2</page> </reconcile> '; $curl->shouldReceive('xmlPost')->with('https://test.hypercharge.net/reconcile/by_date/CHANNEL_TOKEN', $requestXml)->once()->andReturn($this->schemaResponse('reconcile_by_date_page_2.xml')); $requestXml = '<?xml version="1.0" encoding="UTF-8"?> <reconcile> <start_date>2013-06-05</start_date> <end_date>2013-06-12</end_date> <page>3</page> </reconcile> '; $curl->shouldReceive('xmlPost')->with('https://test.hypercharge.net/reconcile/by_date/CHANNEL_TOKEN', $requestXml)->once()->andReturn($this->schemaResponse('reconcile_by_date_page_3.xml')); $n = 0; $_this = $this; $uids = array(); Transaction::each('CHANNEL_TOKEN', $data, function ($trx) use(&$n, $_this, &$uids) { $n++; $_this->assertIsA($trx, 'Hypercharge\\Transaction'); if (isset($uids[$trx->unique_id])) { $_this->fail("dublicate trx: {$n} unique_id: {$trx->unique_id}"); } $uids[$trx->unique_id] = true; }); $this->assertEqual($n, 298); }
/** * @param string xml * @return array */ function parseXml($xml) { $dom = new \SimpleXMLElement($xml); return XmlSerializer::dom2hash($dom); }