本文整理汇总了PHP中ApiTester::amGoingTo方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiTester::amGoingTo方法的具体用法?PHP ApiTester::amGoingTo怎么用?PHP ApiTester::amGoingTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiTester
的用法示例。
在下文中一共展示了ApiTester::amGoingTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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)]);
示例2: 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');
示例3: ApiTester
<?php
use Codeception\Util\Fixtures;
/** @var Faker\Generator $faker */
$faker = Fixtures::get('faker');
$devs = Fixtures::get('devs');
$I = new ApiTester($scenario);
$I->wantTo('get the user price based on the GitHub API');
$I->amGoingTo('Get a non-existent user');
$I->sendGET('dev/' . $faker->lexify('??????????'));
$I->seeResponseCodeIs(404);
$I->amGoingTo('Get an existent user');
$I->sendGET('dev/' . $devs[array_rand($devs)]);
$I->seeResponseCodeIs(200);
$dev = json_decode($I->grabResponse());
$I->assertTrue(is_numeric($dev->rate), 'rate is numeric');
$I->assertTrue(is_string($dev->username) && strlen($dev->username) != 0, 'username is present and is string');
示例4: ApiTester
<?php
$I = new ApiTester($scenario);
$I->wantToTest('Users');
$I->amGoingTo('modify user data (not auth)');
$I->sendPUT("/users/0");
$I->seeResponseCodeIs(401);
示例5: ApiTester
$I = new ApiTester($scenario);
$I->wantTo('Use a coupon in my cart');
/**
* @var array $item1
* @var array $item2
* @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);
示例6: ApiTester
<?php
use Codeception\Util\Fixtures;
/** @var Faker\Generator $faker */
$faker = Fixtures::get('faker');
$orgs = Fixtures::get('orgs');
$sm_orgs = Fixtures::get('small_orgs');
$I = new ApiTester($scenario);
$I->wantTo('list of developers of an organization');
$I->amGoingTo('Get a non-existent organization');
$I->sendGET('dev/organization/' . $faker->lexify('??????????'));
$I->seeResponseCodeIs(404);
$I->amGoingTo('Get an existent organization on different information levels');
$get_org = function ($level, $orgs) use($I) {
$I->amGoingTo("Request Org {$level} information");
$query = $level ? '?level=' . $level : '';
$I->sendGET('dev/organization/' . $orgs[array_rand($orgs)] . $query);
$I->seeResponseCodeIs(200);
$org = json_decode($I->grabResponse(), true);
$I->assertTrue(is_numeric($org['size']), 'has total of members');
$I->assertTrue(is_array($org['members']), 'has list of members');
$I->assertGreaterThanOrEqual(1, $org['size'], 'organization has at least one member');
$I->assertEquals(sizeof($org['members']), $org['size'], 'total is correctly calculated');
$I->assertTrue(is_string($org['members'][0]['username']), 'first member has "username"');
return $org;
};
$org = $get_org('basic', $orgs);
$I->assertEmpty($org['members'][0]['name']);
$I->assertEmpty($org['members'][0]['repos']);
$I->assertEmpty($org['members'][0]['rate']);
$org = $get_org(null, $orgs);