Skip to content

Commit

Permalink
More tests and more stability.
Browse files Browse the repository at this point in the history
  • Loading branch information
roquie committed May 17, 2017
1 parent ee77bbd commit e0b5b0d
Show file tree
Hide file tree
Showing 22 changed files with 848 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Features:
* general statuses (In the requests/responses may to meet `canceled` or `cancelled` variants. They will be converted to general status like as `cancelled`.)

TODO:
* translate to English comments and system (error) messages
* validation
* implement method `card`
* implement method `recurrent`
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ExceptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ExceptionFactory
* @param $message
* @param \Psr\Http\Message\RequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @return \ErrorException
* @return ErrorException
*/
public static function createFromMessage($message, RequestInterface $request, ResponseInterface $response)
{
Expand Down
22 changes: 22 additions & 0 deletions src/Exception/UnitellerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,30 @@
namespace Tmconsulting\Uniteller\Exception;

use Http\Client\Exception\HttpException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class UnitellerException extends HttpException
{
/**
* @param \Psr\Http\Message\RequestInterface $request
* @param \Psr\Http\Message\ResponseInterface $response
* @param \Exception|null $previous
* @return static
*/
public static function create(
RequestInterface $request,
ResponseInterface $response,
\Exception $previous = null
) {
$message = sprintf(
'[url] %s [http method] %s [status code] %s [reason phrase] %s',
$request->getRequestTarget(),
$request->getMethod(),
$response->getStatusCode(),
$response->getReasonPhrase()
);

return new static($message, $request, $response, $previous);
}
}
2 changes: 2 additions & 0 deletions src/Http/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Tmconsulting\Uniteller\Http;

use BadMethodCallException;
use Tmconsulting\Uniteller\Exception\FormatNotSupportedException;
use Tmconsulting\Uniteller\Exception\RequestNotSupportedException;
use Tmconsulting\Uniteller\Request\RequestInterface;
use Tmconsulting\Uniteller;
Expand Down Expand Up @@ -42,6 +43,7 @@ final class Format
* @param $format
* @param $requestName
* @return int
* @throws \Tmconsulting\Uniteller\Exception\FormatNotSupportedException
* @throws \Tmconsulting\Uniteller\Exception\RequestNotSupportedException
*/
public static function resolve($format, $requestName)
Expand Down
2 changes: 1 addition & 1 deletion src/Http/HttpManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Tmconsulting\Uniteller\Http;

use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
use Http\Client\Exception\RequestException;
use Http\Client\HttpClient;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down
5 changes: 2 additions & 3 deletions src/Order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,8 @@ public function setEOrderData($eOrderData)
}

foreach (explode(', ', $eOrderData) as $item) {
foreach (explode('=', $item) as list($key, $value)) {
$this->eOrderData[$key] = $value;
}
list($key, $value) = explode('=', $item);
$this->eOrderData[$key] = $value;
}

return $this;
Expand Down
36 changes: 36 additions & 0 deletions tests/Cancel/CancelBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Created by Roquie.
* E-mail: [email protected]
* GitHub: Roquie
* Date: 17/05/2017
*/

namespace Tmconsulting\Uniteller\Tests\Cancel;

use Tmconsulting\Uniteller\Cancel\CancelBuilder;
use Tmconsulting\Uniteller\Cancel\RVRReason;
use Tmconsulting\Uniteller\Tests\TestCase;

class CancelBuilderTest extends TestCase
{
public function testBuildObject()
{
$builder = new CancelBuilder();
$builder->setBillNumber(1);
$builder->setCurrency('RUB');
$builder->setRvrReason(RVRReason::SHOP);
$builder->setSelectFields([]);
$builder->setSubtotalP(10);

$expected = [
'Billnumber' => 1,
'Subtotal_P' => 10,
'Currency' => 'RUB',
'RVRReason' => RVRReason::SHOP,
'S_FIELDS' => []
];

$this->assertEquals($expected, $builder->toArray());
}
}
71 changes: 71 additions & 0 deletions tests/Cancel/CancelRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Created by Roquie.
* E-mail: [email protected]
* GitHub: Roquie
* Date: 17/05/2017
*/

namespace Tmconsulting\Uniteller\Tests\Cancel;

use Tmconsulting\Uniteller\Cancel\CancelRequest;
use Tmconsulting\Uniteller\Http\HttpManagerInterface;
use Tmconsulting\Uniteller\Order\Order;
use Tmconsulting\Uniteller\Order\Status;
use Tmconsulting\Uniteller\Tests\TestCase;

class CancelRequestTest extends TestCase
{
public function testCanRequestHandleResponse()
{
$manager = $this->createMock(HttpManagerInterface::class);
$manager
->expects($this->once())
->method('request')
->willReturn($this->getStubContents('cancel'));

$request = new CancelRequest();
/** @var \Tmconsulting\Uniteller\Order\Order $order */
foreach ($request->execute($manager) as $order) {
$this->assertInstanceOf(Order::class, $order);
$this->assertEquals('Value of address', $order->getAddress());
$this->assertEquals('Value of approvalcode', $order->getApprovalCode());
$this->assertEquals('Value of bankname', $order->getBankName());
$this->assertEquals('Value of billnumber', $order->getBillNumber());
$this->assertEquals('Value of bookingcom_id', $order->getBookingcomId());
$this->assertEquals('Value of bookingcom_pincode', $order->getBookingcomPincode());
$this->assertEquals('Value of card_idp', $order->getCardIdp());
$this->assertEquals('Value of cardholder', $order->getCardHolder());
$this->assertEquals('Value of cardnumber', $order->getCardNumber());
$this->assertEquals('Value of cardtype', $order->getCardType());
$this->assertEquals('Value of comment', $order->getComment());
$this->assertEquals('Value of currency', $order->getCurrency());
$this->assertEquals(true, $order->isCvc2());
$this->assertInstanceOf(\DateTime::class, $order->getDate());
$this->assertEquals('Value of email', $order->getEmail());
$this->assertEquals('Value of emoneytype', $order->getEMoneyType());
$this->assertEquals(['foo' => 'bar', 'baz' => 'bue'], $order->getEOrderData());
$this->assertEquals('Value of error_code', $order->getErrorCode());
$this->assertEquals('Value of error_comment', $order->getErrorComment());
$this->assertEquals('Value of firstname', $order->getFirstName());
$this->assertEquals('Value of gds_payment_purpose_id', $order->getGdsPaymentPurposeId());
$this->assertEquals('Value of idata', $order->getIData());
$this->assertEquals('Value of ipaddress', $order->getIp());
$this->assertEquals('Value of lastname', $order->getLastName());
$this->assertEquals('Value of loan_id', $order->getLoanId());
$this->assertEquals('Value of message', $order->getMessage());
$this->assertEquals('Value of middlename', $order->getMiddleName());
$this->assertEquals(true, $order->isNeedConfirm());
$this->assertEquals('Value of ordernumber', $order->getOrderNumber());
$this->assertEquals('Value of parent_order_number', $order->getParentOrderNumber());
$this->assertEquals('Value of paymenttype', $order->getPaymentType());
$this->assertEquals('Value of phone', $order->getPhone());
$this->assertEquals('Value of pt_code', $order->getPtCode());
$this->assertEquals('Value of recommendation', $order->getRecommendation());
$this->assertEquals('Value of response_code', $order->getResponseCode());
$this->assertEquals(Status::PAID, $order->getStatus());
$this->assertEquals('Value of total', $order->getTotal());
$this->assertInstanceOf(\DateTime::class, $order->getPacketDate());
}
}
}
22 changes: 22 additions & 0 deletions tests/Cancel/RVRReasonTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Created by Roquie.
* E-mail: [email protected]
* GitHub: Roquie
* Date: 17/05/2017
*/

namespace Tmconsulting\Uniteller\Tests\Cancel;

use Tmconsulting\Uniteller\Cancel\RVRReason;
use Tmconsulting\Uniteller\Tests\TestCase;

class RVRReasonTest extends TestCase
{
public function testConstValuesEqualsDocumentationValues()
{
$this->assertEquals(RVRReason::SHOP, 1);
$this->assertEquals(RVRReason::CARDHOLDER, 2);
$this->assertEquals(RVRReason::FRAUD, 3);
}
}
Loading

0 comments on commit e0b5b0d

Please sign in to comment.