/** * Run test placeRequest method * * @return void */ public function testPlaceRequestSuccess() { $response = $this->getResponseObject(); $this->adapter->expects($this->once())->method('sale')->with($this->getTransferData())->willReturn($response); $this->loggerMock->expects($this->once())->method('debug')->with(['request' => $this->getTransferData(), 'client' => TransactionSale::class, 'response' => ['success' => 1]]); $actualResult = $this->model->placeRequest($this->getTransferObjectMock()); $this->assertTrue(is_object($actualResult['object'])); $this->assertEquals(['object' => $response], $actualResult); }
/** * @covers \Magento\Braintree\Gateway\Http\Client\TransactionSubmitForSettlement::process */ public function testPlaceRequest() { $data = new Successful(['success'], [true]); $this->adapter->expects(static::once())->method('submitForSettlement')->willReturn($data); /** @var TransferInterface|\PHPUnit_Framework_MockObject_MockObject $transferObjectMock */ $transferObjectMock = $this->getTransferObjectMock(); $response = $this->client->placeRequest($transferObjectMock); static::assertTrue(is_object($response['object'])); static::assertEquals(['object' => $data], $response); }
/** * @covers \Magento\Braintree\Gateway\Command\GetPaymentNonceCommand::execute */ public function testExecute() { $publicHash = '3wv2m24d2er3'; $customerId = 1; $token = 'jd2vnq'; $nonce = 's1dj23'; $this->subjectReader->expects(static::once())->method('readPublicHash')->willReturn($publicHash); $this->subjectReader->expects(static::once())->method('readCustomerId')->willReturn($customerId); $this->tokenManagement->expects(static::once())->method('getByPublicHash')->with($publicHash, $customerId)->willReturn($this->paymentToken); $this->paymentToken->expects(static::once())->method('getGatewayToken')->willReturn($token); $obj = new \stdClass(); $obj->success = true; $obj->paymentMethodNonce = new \stdClass(); $obj->paymentMethodNonce->nonce = $nonce; $this->adapter->expects(static::once())->method('createNonce')->with($token)->willReturn($obj); $this->responseValidator->expects(static::once())->method('validate')->with(['response' => ['object' => $obj]])->willReturn($this->validationResult); $this->validationResult->expects(static::once())->method('isValid')->willReturn(true); $this->validationResult->expects(static::never())->method('getFailsDescription'); $expected = $this->getMockBuilder(ArrayResult::class)->disableOriginalConstructor()->setMethods(['get'])->getMock(); $expected->expects(static::once())->method('get')->willReturn(['paymentMethodNonce' => $nonce]); $this->resultFactory->expects(static::once())->method('create')->willReturn($expected); $actual = $this->command->execute(['publicHash' => $publicHash, 'customerId' => $customerId]); static::assertEquals($expected, $actual); static::assertEquals($nonce, $actual->get()['paymentMethodNonce']); }
/** * Get items with limit */ public function testGetItemsWithNullLimit() { $transations = range(1, TransactionsCollection::TRANSACTION_MAXIMUM_COUNT + 10); $this->filterMapperMock->expects($this->once())->method('getFilter')->willReturn(new BraintreeSearchNodeStub()); $this->braintreeAdapterMock->expects($this->once())->method('search')->willReturn($transations); $this->entityFactoryMock->expects($this->exactly(TransactionsCollection::TRANSACTION_MAXIMUM_COUNT))->method('create')->willReturn($this->transactionMapMock); $collection = new TransactionsCollection($this->entityFactoryMock, $this->braintreeAdapterMock, $this->filterMapperMock); $collection->setPageSize(null); $collection->addFieldToFilter('orderId', ['like' => '0']); $items = $collection->getItems(); $this->assertEquals(TransactionsCollection::TRANSACTION_MAXIMUM_COUNT, count($items)); $this->assertInstanceOf(DocumentInterface::class, $items[1]); }
/** * @param string $lastTransactionId * @return \Braintree\ResourceCollection|\PHPUnit_Framework_MockObject_MockObject */ private function getNotExpiredExpectedCollection($lastTransactionId) { $isExpectations = ['id' => ['is' => $lastTransactionId], 'status' => [\Braintree\Transaction::AUTHORIZATION_EXPIRED]]; $collection = $this->getMockBuilder(\Braintree\ResourceCollection::class)->disableOriginalConstructor()->getMock(); $this->braintreeAdapter->expects(static::once())->method('search')->with(static::callback(function (array $filters) use($isExpectations) { foreach ($filters as $filter) { /** @var IsNode $filter */ if (!isset($isExpectations[$filter->name])) { return false; } if ($isExpectations[$filter->name] !== $filter->toParam()) { return false; } } return true; }))->willReturn($collection); return $collection; }
/** * @covers \Magento\Braintree\Model\Ui\ConfigProvider::getClientToken */ public function testGetClientToken() { $this->braintreeAdapter->expects(static::once())->method('generate')->willReturn(self::CLIENT_TOKEN); static::assertEquals(self::CLIENT_TOKEN, $this->configProvider->getClientToken()); }