本文整理汇总了PHP中ApiTester::seeCodeAndJson方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiTester::seeCodeAndJson方法的具体用法?PHP ApiTester::seeCodeAndJson怎么用?PHP ApiTester::seeCodeAndJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiTester
的用法示例。
在下文中一共展示了ApiTester::seeCodeAndJson方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ApiTester
<?php
$I = new ApiTester($scenario);
$I->wantTo('Insert items and checkout');
/**
* @var array $item1
* @var array $item2
* @var int $order
*/
require "_AddItems.php";
$I->amGoingTo('checkout');
$I->sendPATCH('cart');
$I->seeCodeAndJson(200, ['id' => $order, 'total' => floatify($item1['final_price'] + $item2['final_price'])]);
$I->amGoingTo('verify the order was really ~closed~');
$I->sendGET('cart');
$I->assertEquals(sizeof(json_decode($I->grabResponse())->items), 0, 'verify the cart is now empty');
示例2: ApiTester
<?php
$I = new ApiTester($scenario);
$I->wantTo('Test the cart behaviour with items');
$I->amGoingTo('confirm the cart is empty');
$I->sendGET('cart');
$I->seeCodeAndJson(200, ['items' => [], 'total' => floatify(0)]);
/**
* @var array $item1
* @var array $item2
* @var int $item_id
*/
require "_AddItems.php";
$I->amGoingTo('Verify order');
$I->sendGET('cart');
$I->expectTo('see items in order');
$I->seeCodeAndJson(200, ['items' => [$item1, $item2]]);
$I->expectTo('see correct total');
$I->seeResponseContainsJson(['total' => floatify($item1['final_price'] + $item2['final_price'])]);
$I->amGoingTo('delete an item');
$I->sendDELETE('cart/item/' . $item_id);
$I->seeResponseCodeIs(204);
$I->seeResponseEquals('');
$I->sendGET('cart');
$I->seeCodeAndJson(200, ['items' => [$item2], 'total' => floatify($item2['final_price'])]);
$I->amGoingTo('clear the cart');
$I->sendDELETE('cart');
$I->seeResponseCodeIs(204);
$I->seeResponseEquals('');
$I->sendGET('cart');
$I->seeCodeAndJson(200, ['items' => [], 'total' => floatify(0)]);
示例3: function
* @var int $order
* @var callable $gen_item
*/
require "_AddItems.php";
$calculate_discount = function ($discount, ...$items) {
$mult = 1 - $discount;
return array_reduce($items, function ($total, $item) use($mult) {
return floatify($total + floatify($item['final_price'] * $mult));
}, 0);
};
$I->amGoingTo('use an invalid coupon code');
$I->sendPOST('cart/coupon', ['code' => 'XXX']);
$I->seeResponseCodeIs(HTTP_NOT_FOUND);
$set_coupon = function ($coupon) use($I, $item1, $item2, $calculate_discount) {
$I->sendPOST('cart/coupon', ['code' => $coupon['code']]);
$I->seeCodeAndJson(HTTP_OK, $coupon);
$I->sendGET('cart');
$I->seeResponseContainsJson(['total' => $calculate_discount($coupon['discount'], $item1, $item2)]);
};
$I->amGoingTo('use a valid coupon code');
$set_coupon($coupons[0]);
$I->amGoingTo('change the coupon');
$set_coupon($coupons[1]);
$I->amGoingTo('add a new item to see the price discount');
$item3 = $gen_item();
$I->sendPUT('cart', $item3);
$item3['final_price'] = $item3['price'] * $item3['qty'];
$I->sendGET('cart');
$I->seeResponseContainsJson(['total' => $calculate_discount($coupons[1]['discount'], $item1, $item2, $item3)]);
$I->amGoingTo('remove the wrong coupon');
$I->sendDELETE('cart/coupon?code=' . $coupons[0]['code']);