/** * @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); }
/** * @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))']); }
public static function initialize(Config $config) { ItemTrait::initialize($config); $config->addRels([new Rel\BelongsTo('basket', $config, Basket::getRepo(), ['inverseOf' => 'items']), new Rel\BelongsTo('product', $config, Product::getRepo())]); }
/** * @covers ::sendRequest */ public function testSendRequest() { $request = $this->getMock('Omnipay\\Dummy\\Message\\AuthorizeRequest', ['send'], [new HttpClient(), new HttpRequest()]); $response = $this->getMock('Omnipay\\Dummy\\Message\\Response', ['isRedirect', 'isSuccessful'], [$request, ['test']]); $request->expects($this->exactly(3))->method('send')->will($this->returnValue($response)); $response->expects($this->exactly(3))->method('isRedirect')->will($this->onConsecutiveCalls(true, false, false)); $response->expects($this->exactly(2))->method('isSuccessful')->will($this->onConsecutiveCalls(false, true)); $current = new DateTime(); $basket = new Basket(['currency' => 'BGN', 'id' => 20]); $result = $basket->sendRequest($request); $this->assertSame($response, $result); $this->assertEquals($response->getData(), $basket->responseData); $this->assertFalse($basket->isSuccessful); $this->assertTrue($current >= $basket->completedAt); $basket = new Basket(['currency' => 'BGN', 'id' => 20]); $basket->sendRequest($request); $this->assertSame($response, $result); $this->assertEquals($response->getData(), $basket->responseData); $this->assertFalse($basket->isSuccessful); $this->assertTrue($current >= $basket->completedAt); $basket = new Basket(['currency' => 'BGN', 'id' => 20]); $basket->sendRequest($request); $this->assertSame($response, $result); $this->assertEquals($response->getData(), $basket->responseData); $this->assertTrue($basket->isSuccessful); $this->assertTrue($current >= $basket->completedAt); }