Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
[change] (PHPLIB-318) Refactor tests to fit latest API changes. (#176)
Browse files Browse the repository at this point in the history
Co-authored-by: sixer1182 <[email protected]>
  • Loading branch information
Simon Gabriel and sixer1182 authored May 5, 2020
1 parent 70797b3 commit 977062d
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

### Change
* Fix some minor issues.
* Refactor tests due to API changes.

### Added
* TraceId property to payment and transactions.
Expand Down
2 changes: 1 addition & 1 deletion test/BasePaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected function assertPending($transaction)
*/
public function createBasket(): Basket
{
$orderId = self::generateRandomId();
$orderId = 'b' . self::generateRandomId();
$basket = new Basket($orderId, 119.0, 'EUR');
$basket->setAmountTotalVat(19.0);
$basket->setNote('This basket is creatable!');
Expand Down
12 changes: 6 additions & 6 deletions test/integration/BasketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function minBasketShouldBeCreatableAndFetchable()
*/
public function maxBasketShouldBeCreatableAndFetchableWorkAround()
{
$basket = new Basket(self::generateRandomId(), 123.4, 'EUR', []);
$basket = new Basket('b' . self::generateRandomId(), 123.4, 'EUR', []);
$basket->setNote('This basket is creatable!');
$basketItem = (new BasketItem('myItem', 1234, 2345, 12))
->setBasketItemReferenceId('refId')
Expand Down Expand Up @@ -116,7 +116,7 @@ public function maxBasketShouldBeCreatableAndFetchableWorkAround()
*/
public function basketItemWithInvalidUrlWillThrowAnError($expectException, $imageUrl, $exceptionCode = null)
{
$basket = new Basket(self::generateRandomId(), 123.4, 'EUR', []);
$basket = new Basket('b' . self::generateRandomId(), 123.4, 'EUR', []);
$basketItem = (new BasketItem('myItem', 1234, 2345, 12))->setImageUrl($imageUrl);
$basket->addBasketItem($basketItem);

Expand All @@ -143,7 +143,7 @@ public function basketItemWithInvalidUrlWillThrowAnError($expectException, $imag
*/
public function basketShouldBeUpdateable()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = new Basket($orderId, 123.4, 'EUR', []);
$basket->setNote('This basket is creatable!');
$basketItem = (new BasketItem('myItem', 1234, 2345, 12))->setBasketItemReferenceId('refId');
Expand Down Expand Up @@ -175,7 +175,7 @@ public function basketShouldBeUpdateable()
*/
public function authorizeTransactionsShouldPassAlongTheBasketIdIfSet()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = new Basket($orderId, 123.4, 'EUR', []);
$basket->setNote('This basket is creatable!');
$basketItem = (new BasketItem('myItem', 123.4, 234.5, 12))->setBasketItemReferenceId('refId');
Expand Down Expand Up @@ -224,7 +224,7 @@ public function chargeTransactionsShouldPassAlongTheBasketIdIfSet()
*/
public function authorizeTransactionsShouldCreateBasketIfItDoesNotExistYet()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = new Basket($orderId, 123.4, 'EUR', []);
$basket->setNote('This basket is creatable!');
$basketItem = (new BasketItem('myItem', 1234, 2345, 12))->setBasketItemReferenceId('refId');
Expand All @@ -250,7 +250,7 @@ public function authorizeTransactionsShouldCreateBasketIfItDoesNotExistYet()
*/
public function chargeTransactionsShouldCreateBasketIfItDoesNotExistYet()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = new Basket($orderId, 123.4, 'EUR', []);
$basket->setNote('This basket is creatable!');
$basket->setAmountTotalVat(10.9);
Expand Down
6 changes: 3 additions & 3 deletions test/integration/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function customerCanBeFetchedById(Customer $customer)
*/
public function customerCanBeFetchedByCustomerId()
{
$customerId = str_replace([' ', '.'], '', microtime());
$customerId = 'c' . self::generateRandomId();
$customer = $this->getMaximumCustomer()->setCustomerId($customerId);
$this->heidelpay->createCustomer($customer);

Expand Down Expand Up @@ -173,7 +173,7 @@ public function customerCanBeFetchedByObjectWithData(Customer $customer)
*/
public function transactionShouldCreateAndReferenceCustomerIfItDoesNotExistYet()
{
$customerId = 'customer' . self::generateRandomId();
$customerId = 'c' . self::generateRandomId();
$customer = $this->getMaximumCustomerInclShippingAddress()->setCustomerId($customerId);

/** @var Paypal $paypal */
Expand Down Expand Up @@ -379,7 +379,7 @@ public function customerShouldBeFetchedByCustomerIdAndUpdatedIfItAlreadyExists()
*/
public function addressNameCanHoldFirstAndLastNameConcatenated()
{
$customerId = 'customer' . self::generateRandomId();
$customerId = 'c' . self::generateRandomId();
$customer = $this->getMaximumCustomerInclShippingAddress()->setCustomerId($customerId);
$longName = 'firstfirstfirstfirstfirstfirstfirstfirst lastlastlastlastlastlastlastlastlastlast';
$customer->getShippingAddress()->setName($longName);
Expand Down
6 changes: 3 additions & 3 deletions test/integration/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function paymentChargeOnAuthorizeShouldTakeResourceIds()
{
$card = $this->heidelpay->createPaymentType($this->createCardObject());
$authorization = $this->heidelpay->authorize(100.00, 'EUR', $card, 'http://heidelpay.com', null, null, null, null, false);
$charge = $this->heidelpay->chargePayment($authorization->getPaymentId(), null, 'order-' . self::generateRandomId(), 'invoice-' . self::generateRandomId());
$charge = $this->heidelpay->chargePayment($authorization->getPaymentId(), null, 'EUR', 'o' . self::generateRandomId(), 'i' . self::generateRandomId());

$this->assertNotEmpty($charge->getId());
}
Expand Down Expand Up @@ -228,7 +228,7 @@ public function paymentShouldBeFetchedByOrderIdIfIdIsNotSet()
*/
public function shouldAllowNonUniqueOrderId()
{
$orderId = self::generateRandomId();
$orderId = 'o' . self::generateRandomId();

/** @var Card $card */
$card = $this->heidelpay->createPaymentType($this->createCardObject());
Expand All @@ -254,7 +254,7 @@ public function shouldAllowNonUniqueOrderId()
*/
public function shouldAllowNonUniqueInvoiceId()
{
$invoiceId = self::generateRandomId();
$invoiceId = 'i' . self::generateRandomId();

/** @var Card $card */
$card = $this->heidelpay->createPaymentType($this->createCardObject());
Expand Down
4 changes: 2 additions & 2 deletions test/integration/PaymentTypes/InvoiceGuaranteedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function verifyInvoiceGuaranteedShipment()
$this->assertNotEmpty($charge->getHolder());
$this->assertNotEmpty($charge->getDescriptor());

$shipment = $this->heidelpay->ship($charge->getPayment(), self::generateRandomId(), self::generateRandomId());
$shipment = $this->heidelpay->ship($charge->getPayment(), 'i' . self::generateRandomId(), 'o' . self::generateRandomId());
$this->assertTransactionResourceHasBeenCreated($shipment);
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public function verifyInvoiceIdInShipmentWillOverrideTheOneFromCharge()
$invoiceGuaranteed = $this->heidelpay->createPaymentType(new InvoiceGuaranteed());
$customer = $this->getMaximumCustomerInclShippingAddress()->setShippingAddress($this->getBillingAddress());

$invoiceId = self::generateRandomId();
$invoiceId = 'i' . self::generateRandomId();
$charge = $invoiceGuaranteed->charge(100.0, 'EUR', self::RETURN_URL, $customer, null, null, null, null, $invoiceId);
$chargeInvoiceId = $charge->getPayment()->getInvoiceId();

Expand Down
8 changes: 4 additions & 4 deletions test/integration/PaymentTypes/PaypageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public function minimalPaypageChargeShouldBeCreatableAndFetchable()
*/
public function maximumPaypageChargeShouldBeCreatable()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = $this->createBasket();
$customer = CustomerFactory::createCustomer('Max', 'Mustermann');
$invoiceId = self::generateRandomId();
$invoiceId = 'i'. self::generateRandomId();
$paypage = (new Paypage(119.0, 'EUR', self::RETURN_URL))
->setLogoImage('https://dev.heidelpay.com/devHeidelpay_400_180.jpg')
->setFullPageImage('https://www.heidelpay.com/fileadmin/content/header-Imges-neu/Header_Phone_12.jpg')
Expand Down Expand Up @@ -120,10 +120,10 @@ public function minimalPaypageAuthorizeShouldBeCreatableAndFetchable()
*/
public function maximumPaypageAuthorizeShouldBeCreatable()
{
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$basket = $this->createBasket();
$customer = CustomerFactory::createCustomer('Max', 'Mustermann');
$invoiceId = self::generateRandomId();
$invoiceId = 'i'. self::generateRandomId();
$paypage = (new Paypage(119.0, 'EUR', self::RETURN_URL))
->setLogoImage('https://dev.heidelpay.com/devHeidelpay_400_180.jpg')
->setFullPageImage('https://www.heidelpay.com/fileadmin/content/header-Imges-neu/Header_Phone_12.jpg')
Expand Down
4 changes: 2 additions & 2 deletions test/integration/TransactionTypes/AuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ public function authorizeShouldAcceptAllParameters()
/** @var Card $card */
$card = $this->heidelpay->createPaymentType($this->createCardObject());
$customer = $this->getMinimalCustomer();
$orderId = self::generateRandomId();
$orderId = 'o' . self::generateRandomId();
$metadata = (new Metadata())->addMetadata('key', 'value');
$basket = $this->createBasket();
$invoiceId = self::generateRandomId();
$invoiceId = 'i' . self::generateRandomId();
$paymentReference = 'paymentReference';

$authorize = $card->authorize(119.0, 'EUR', self::RETURN_URL, $customer, $orderId, $metadata, $basket, true, $invoiceId, $paymentReference);
Expand Down
8 changes: 4 additions & 4 deletions test/integration/TransactionTypes/ChargeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ public function chargeShouldAcceptAllParameters()
/** @var Card $paymentType */
$paymentType = $this->heidelpay->createPaymentType($this->createCardObject());
$customer = $this->getMinimalCustomer();
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$metadata = (new Metadata())->addMetadata('key', 'value');
$basket = $this->createBasket();
$invoiceId = self::generateRandomId();
$invoiceId = 'i'. self::generateRandomId();
$paymentReference = 'paymentReference';

// perform request
Expand Down Expand Up @@ -148,10 +148,10 @@ public function chargeWithCustomerShouldAcceptAllParameters()
$ivg = $this->heidelpay->createPaymentType(new InvoiceGuaranteed());
$customer = $this->getMaximumCustomer();
$customer->setShippingAddress($customer->getBillingAddress());
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$metadata = (new Metadata())->addMetadata('key', 'value');
$basket = $this->createBasket();
$invoiceId = self::generateRandomId();
$invoiceId = 'i'. self::generateRandomId();
$paymentReference = 'paymentReference';

// perform request
Expand Down
4 changes: 2 additions & 2 deletions test/integration/TransactionTypes/PayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ public function payoutShouldAcceptAllParameters()
/** @var Card $card */
$card = $this->heidelpay->createPaymentType($this->createCardObject());
$customer = $this->getMinimalCustomer();
$orderId = self::generateRandomId();
$orderId = 'o'. self::generateRandomId();
$metadata = (new Metadata())->addMetadata('key', 'value');
$basket = $this->createBasket();
$invoiceId = self::generateRandomId();
$invoiceId = 'i'. self::generateRandomId();
$paymentReference = 'paymentReference';

$payout = $card->payout(119.0, 'EUR', self::RETURN_URL, $customer, $orderId, $metadata, $basket, $invoiceId, $paymentReference);
Expand Down
8 changes: 4 additions & 4 deletions test/integration/TransactionTypes/ShipmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function shipmentShouldBeCreatableAndFetchable()
$this->assertNotNull($charge->getId());
$this->assertNotNull($charge);

$shipment = $this->heidelpay->ship($charge->getPayment(), self::generateRandomId(), self::generateRandomId());
$shipment = $this->heidelpay->ship($charge->getPayment(), 'i'. self::generateRandomId(), 'i'. self::generateRandomId());
$this->assertNotNull($shipment->getId());
$this->assertNotNull($shipment);

Expand All @@ -72,7 +72,7 @@ public function shipmentCanBeCalledOnThePaymentObject()
$charge = $this->heidelpay->charge(100.0, 'EUR', $invoiceGuaranteed, self::RETURN_URL, $customer);

$payment = $charge->getPayment();
$shipment = $payment->ship(self::generateRandomId(), self::generateRandomId());
$shipment = $payment->ship('i'. self::generateRandomId(), 'o'. self::generateRandomId());
$this->assertNotNull($shipment);
$this->assertNotEmpty($shipment->getId());
$this->assertNotEmpty($shipment->getUniqueId());
Expand Down Expand Up @@ -102,7 +102,7 @@ public function shipmentShouldBePossibleWithPaymentObject()
$charge = $this->heidelpay->charge(100.0, 'EUR', $invoiceGuaranteed, self::RETURN_URL, $customer);

$payment = $charge->getPayment();
$shipment = $this->heidelpay->ship($payment, self::generateRandomId(), self::generateRandomId());
$shipment = $this->heidelpay->ship($payment, 'i'. self::generateRandomId(), 'o'. self::generateRandomId());
$this->assertNotNull($shipment->getId());
$this->assertNotNull($shipment);
}
Expand All @@ -122,7 +122,7 @@ public function shipmentStatusIsSetCorrectly()
$charge = $this->heidelpay->charge(100.0, 'EUR', $invoiceGuaranteed, self::RETURN_URL, $customer);

$payment = $charge->getPayment();
$shipment = $this->heidelpay->ship($payment, self::generateRandomId(), self::generateRandomId());
$shipment = $this->heidelpay->ship($payment, 'i'. self::generateRandomId(), 'o'. self::generateRandomId());
$this->assertSuccess($shipment);
}
}

0 comments on commit 977062d

Please sign in to comment.