|
5 | 5 | */
|
6 | 6 | namespace Magento\Paypal\Test\Unit\Model\Payflow\Service\Request;
|
7 | 7 |
|
8 |
| -use Magento\Framework\Math\Random; |
9 | 8 | use Magento\Framework\DataObject;
|
| 9 | +use Magento\Framework\Math\Random; |
10 | 10 | use Magento\Framework\UrlInterface;
|
11 | 11 | use Magento\Paypal\Model\Payflow\Service\Request\SecureToken;
|
12 | 12 | use Magento\Paypal\Model\Payflow\Transparent;
|
| 13 | +use Magento\Paypal\Model\PayflowConfig; |
| 14 | +use Magento\Quote\Model\Quote; |
| 15 | +use PHPUnit_Framework_MockObject_MockObject as MockObject; |
13 | 16 |
|
14 |
| -/** |
15 |
| - * Test class for \Magento\Paypal\Model\Payflow\Service\Request\SecureToken |
16 |
| - */ |
17 | 17 | class SecureTokenTest extends \PHPUnit\Framework\TestCase
|
18 | 18 | {
|
19 | 19 | /**
|
20 | 20 | * @var SecureToken
|
21 | 21 | */
|
22 |
| - protected $model; |
| 22 | + private $service; |
23 | 23 |
|
24 | 24 | /**
|
25 |
| - * @var \PHPUnit_Framework_MockObject_MockObject|Transparent |
| 25 | + * @var Transparent|MockObject |
26 | 26 | */
|
27 |
| - protected $transparent; |
| 27 | + private $transparent; |
28 | 28 |
|
29 | 29 | /**
|
30 |
| - * @var \PHPUnit_Framework_MockObject_MockObject|Random |
| 30 | + * @var Random|MockObject |
31 | 31 | */
|
32 |
| - protected $mathRandom; |
| 32 | + private $mathRandom; |
33 | 33 |
|
34 | 34 | /**
|
35 |
| - * @var \PHPUnit_Framework_MockObject_MockObject|UrlInterface |
| 35 | + * @inheritdoc |
36 | 36 | */
|
37 |
| - protected $url; |
38 |
| - |
39 | 37 | protected function setUp()
|
40 | 38 | {
|
41 |
| - $this->url = $this->createMock(\Magento\Framework\UrlInterface::class); |
42 |
| - $this->mathRandom = $this->createMock(\Magento\Framework\Math\Random::class); |
43 |
| - $this->transparent = $this->createMock(\Magento\Paypal\Model\Payflow\Transparent::class); |
| 39 | + $url = $this->getMockForAbstractClass(UrlInterface::class); |
| 40 | + $this->mathRandom = $this->getMockBuilder(Random::class) |
| 41 | + ->getMock(); |
| 42 | + $this->transparent = $this->getMockBuilder(Transparent::class) |
| 43 | + ->disableOriginalConstructor() |
| 44 | + ->getMock(); |
44 | 45 |
|
45 |
| - $this->model = new SecureToken( |
46 |
| - $this->url, |
| 46 | + $this->service = new SecureToken( |
| 47 | + $url, |
47 | 48 | $this->mathRandom,
|
48 | 49 | $this->transparent
|
49 | 50 | );
|
50 | 51 | }
|
51 | 52 |
|
52 | 53 | public function testRequestToken()
|
53 | 54 | {
|
54 |
| - $request = new DataObject(); |
| 55 | + $storeId = 1; |
55 | 56 | $secureTokenID = 'Sdj46hDokds09c8k2klaGJdKLl032ekR';
|
| 57 | + $response = new DataObject([ |
| 58 | + 'result' => '0', |
| 59 | + 'respmsg' => 'Approved', |
| 60 | + 'securetoken' => '80IgSbabyj0CtBDWHZZeQN3', |
| 61 | + 'securetokenid' => $secureTokenID, |
| 62 | + 'result_code' => '0', |
| 63 | + ]); |
56 | 64 |
|
57 |
| - $this->transparent->expects($this->once()) |
58 |
| - ->method('buildBasicRequest') |
59 |
| - ->willReturn($request); |
60 |
| - $this->transparent->expects($this->once()) |
61 |
| - ->method('fillCustomerContacts'); |
62 |
| - $this->transparent->expects($this->once()) |
63 |
| - ->method('getConfig') |
64 |
| - ->willReturn($this->createMock(\Magento\Paypal\Model\PayflowConfig::class)); |
65 |
| - $this->transparent->expects($this->once()) |
66 |
| - ->method('postRequest') |
67 |
| - ->willReturn(new DataObject()); |
| 65 | + $quote = $this->getMockBuilder(Quote::class) |
| 66 | + ->disableOriginalConstructor() |
| 67 | + ->getMock(); |
| 68 | + $quote->method('getStoreId') |
| 69 | + ->willReturn($storeId); |
68 | 70 |
|
69 |
| - $this->mathRandom->expects($this->once()) |
70 |
| - ->method('getUniqueHash') |
71 |
| - ->willReturn($secureTokenID); |
| 71 | + $this->transparent->expects(self::once()) |
| 72 | + ->method('setStore') |
| 73 | + ->with($storeId); |
72 | 74 |
|
73 |
| - $this->url->expects($this->exactly(3)) |
74 |
| - ->method('getUrl'); |
| 75 | + $this->transparent->method('buildBasicRequest') |
| 76 | + ->willReturn(new DataObject()); |
75 | 77 |
|
76 |
| - $quote = $this->createMock(\Magento\Quote\Model\Quote::class); |
| 78 | + $config = $this->getMockBuilder(PayflowConfig::class) |
| 79 | + ->disableOriginalConstructor() |
| 80 | + ->getMock(); |
| 81 | + $this->transparent->method('getConfig') |
| 82 | + ->willReturn($config); |
| 83 | + $this->transparent->method('postRequest') |
| 84 | + ->with(self::callback(function ($request) use ($secureTokenID) { |
| 85 | + self::assertEquals($secureTokenID, $request->getSecuretokenid(), '{Secure Token} should match.'); |
| 86 | + return true; |
| 87 | + })) |
| 88 | + ->willReturn($response); |
| 89 | + |
| 90 | + $this->mathRandom->method('getUniqueHash') |
| 91 | + ->willReturn($secureTokenID); |
77 | 92 |
|
78 |
| - $this->model->requestToken($quote); |
| 93 | + $actual = $this->service->requestToken($quote); |
79 | 94 |
|
80 |
| - $this->assertEquals($secureTokenID, $request->getSecuretokenid()); |
| 95 | + self::assertEquals($secureTokenID, $actual->getSecuretokenid()); |
81 | 96 | }
|
82 | 97 | }
|
0 commit comments