client = new Client($bitpay->get('logger')); $this->client->setContainer($bitpay->getContainer()); @mkdir(dirname($bitpay->getContainer()->getParameter('logger.file'))); @touch($bitpay->getContainer()->getParameter('logger.file')); } public function testCreateInvoice() { $item = $this->getMockItem(); $item->method('getPrice')->will($this->returnValue(1)); $buyer = $this->getMockBuyer(); $buyer->method('getAddress')->will($this->returnValue(array())); $invoice = $this->getMockInvoice(); $invoice->method('getItem')->willReturn($item); $invoice->method('getBuyer')->willReturn($buyer); $invoice->method('setId')->will($this->returnSelf()); $invoice->method('setUrl')->will($this->returnSelf()); $invoice->method('setStatus')->will($this->returnSelf()); $invoice->method('setBtcPrice')->will($this->returnSelf()); $invoice->method('setPrice')->will($this->returnSelf()); $invoice->method('setInvoiceTime')->will($this->returnSelf()); $invoice->method('setExpirationTime')->will($this->returnSelf()); $invoice->method('setCurrentTime')->will($this->returnSelf()); $invoice->method('setBtcPaid')->will($this->returnSelf()); $invoice->method('setRate')->will($this->returnSelf()); $invoice->method('setExceptionStatus')->will($this->returnSelf()); $invoice->method('getCurrency')->willReturn($this->getMockCurrency()); $invoice = $this->client->createInvoice($invoice); $this->assertInstanceOf('Bitpay\InvoiceInterface', $invoice); } /** * @depends testCreateInvoice */ public function testGetResponse() { $this->assertNull($this->client->getResponse()); } /** * @depends testCreateInvoice */ public function testGetRequest() { $this->assertNull($this->client->getRequest()); } /** * @depends testGetRequest * @depends testGetResponse * @expectedException Exception */ public function testCreateInvoiceWithError() { $this->assertNull($this->client->getResponse()); $this->assertNull($this->client->getRequest()); $invoice = $this->getMockInvoice(); $invoice->method('setId')->will($this->returnSelf()); $invoice->method('setUrl')->will($this->returnSelf()); $invoice->method('setStatus')->will($this->returnSelf()); $invoice->method('setBtcPrice')->will($this->returnSelf()); $invoice->method('setPrice')->will($this->returnSelf()); $invoice->method('setInvoiceTime')->will($this->returnSelf()); $invoice->method('setExpirationTime')->will($this->returnSelf()); $invoice->method('setCurrentTime')->will($this->returnSelf()); $invoice->method('setBtcPaid')->will($this->returnSelf()); $invoice->method('setRate')->will($this->returnSelf()); $invoice->method('setExceptionStatus')->will($this->returnSelf()); $invoice->method('getCurrency')->willReturn($this->getMockCurrency()); $invoice->method('getItem')->willReturn($this->getMockItem()); $invoice->method('getBuyer')->willReturn($this->getMockBuyer()); // throws exception $this->client->createInvoice($invoice); } /** * @expectedException Exception */ public function testGetCurrenciesWithException() { $currencies = $this->client->getCurrencies(); } private function getMockInvoice() { $invoice = $this->getMockBuilder('Bitpay\InvoiceInterface') ->setMethods( array( 'getPrice', 'getCurrency', 'getItem', 'getBuyer', 'getTransactionSpeed', 'getNotificationEmail', 'getNotificationUrl', 'getRedirectUrl', 'getPosData', 'getStatus', 'isFullNotifications', 'getId', 'getUrl', 'getBtcPrice', 'getInvoiceTime', 'getExpirationTime', 'getCurrentTime', 'getOrderId', 'getItemDesc', 'getItemCode', 'isPhysical', 'getBuyerName', 'getBuyerAddress1', 'getBuyerAddress2', 'getBuyerCity', 'getBuyerState', 'getBuyerZip', 'getBuyerCountry', 'getBuyerEmail', 'getBuyerPhone', 'getExceptionStatus', 'getBtcPaid', 'getRate', 'setId', 'setUrl', 'setStatus', 'setBtcPrice', 'setPrice', 'setInvoiceTime', 'setExpirationTime', 'setCurrentTime', 'setBtcPaid', 'setRate', 'setExceptionStatus', ) ) ->getMock(); return $invoice; } private function getMockBuyer() { return $this->getMockBuilder('Bitpay\BuyerInterface') ->setMethods( array( 'getPhone', 'getEmail', 'getFirstName', 'getLastName', 'getAddress', 'getCity', 'getState', 'getZip', 'getCountry', ) ) ->getMock(); } private function getMockItem() { return $this->getMockBuilder('Bitpay\ItemInterface') ->setMethods( array( 'getCode', 'getDescription', 'getPrice', 'getQuantity', 'isPhysical', ) ) ->getMock(); } private function getMockCurrency() { return $this->getMockBuilder('Bitpay\CurrencyInterface') ->setMethods( array( 'getCode', 'getSymbol', 'getPrecision', 'getExchangePctFee', 'isPayoutEnabled', 'getName', 'getPluralName', 'getAlts', 'getPayoutFields', ) ) ->getMock(); } }