Ejemplo n.º 1
0
 /**
  * @covers ::getTransferParameters
  * @covers ::getRequestParameters
  */
 public function testGetRequestParameters()
 {
     $basket = new Basket(['currency' => 'BGN', 'id' => 20]);
     $basket->getItems()->add(new ProductItem(['id' => 1, 'value' => 1000, 'isFrozen' => true, 'quantity' => 2]))->add(new ProductItem(['id' => 2, 'value' => 2000, 'isFrozen' => true, 'quantity' => 3]));
     $expected = ['amount' => 80, 'currency' => 'BGN', 'transactionReference' => 20, 'cart' => ['test']];
     $params = $basket->getRequestParameters(['cart' => ['test']]);
     $this->assertEquals($expected, $params);
 }
Ejemplo n.º 2
0
 /**
  * @covers ::performUnfreeze
  * @covers ::unfreezeItems
  */
 public function testUnfreeze()
 {
     $basket = new Basket(['currency' => 'BGN', 'value' => 2000, 'isFrozen' => true]);
     $item1 = $this->getMock(__NAMESPACE__ . '\\ProductItem', ['unfreeze']);
     $item1->expects($this->once())->method('unfreeze');
     $item2 = $this->getMock(__NAMESPACE__ . '\\ProductItem', ['unfreeze']);
     $item2->expects($this->once())->method('unfreeze');
     $basket->getItems()->add($item1)->add($item2);
     $basket->unfreeze();
     $this->assertEquals(0, $basket->value);
 }
Ejemplo n.º 3
0
 /**
  * @covers ::testMethod
  */
 public function testTest()
 {
     $basket = new Basket();
     $product1 = Product::find(1);
     $product2 = Product::find(2);
     $item1 = new ProductItem(['quantity' => 2]);
     $item1->setProduct($product1);
     $item2 = new ProductItem(['quantity' => 4]);
     $item2->setProduct($product2);
     $basket->getItems()->add($item1)->add($item2);
     Basket::save($basket);
     $gateway = Omnipay::getFactory()->create('Dummy');
     $parameters = ['card' => ['number' => '4242424242424242', 'expiryMonth' => 12, 'expiryYear' => date('Y'), 'cvv' => 123], 'clientIp' => '192.168.0.1'];
     $basket->freeze();
     $response = $basket->purchase($gateway, $parameters);
     $this->assertTrue($response->isSuccessful());
     $this->assertTrue($basket->isSuccessful);
     $this->assertQueries(['SELECT Product.* FROM Product WHERE (id = 1) LIMIT 1', 'SELECT Product.* FROM Product WHERE (id = 2) LIMIT 1', 'INSERT INTO Basket (id, currency, isSuccessful, completedAt, responseData, deletedAt, isFrozen, value) VALUES (NULL, "GBP", , NULL, NULL, NULL, , 0)', 'INSERT INTO ProductItem (id, basketId, productId, quantity, deletedAt, isFrozen, value) VALUES (NULL, NULL, NULL, 2, NULL, , 0), (NULL, NULL, NULL, 4, NULL, , 0)', 'UPDATE ProductItem SET basketId = CASE id WHEN 1 THEN "1" WHEN 2 THEN "1" ELSE basketId END, productId = CASE id WHEN 1 THEN 1 WHEN 2 THEN 2 ELSE productId END WHERE (id IN (1, 2))', 'UPDATE Basket SET isSuccessful = 1, completedAt = "' . $basket->completedAt . '", responseData = "{"amount":"1000.00","reference":"' . $basket->responseData['reference'] . '","success":true,"message":"Success"}", isFrozen = 1, value = 100000 WHERE (id = "1")', 'UPDATE ProductItem SET isFrozen = CASE id WHEN 1 THEN 1 WHEN 2 THEN 1 ELSE isFrozen END, value = CASE id WHEN 1 THEN 10000 WHEN 2 THEN 20000 ELSE value END WHERE (id IN (1, 2))']);
 }