本文整理汇总了PHP中ApiTester::getMongoId方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiTester::getMongoId方法的具体用法?PHP ApiTester::getMongoId怎么用?PHP ApiTester::getMongoId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiTester
的用法示例。
在下文中一共展示了ApiTester::getMongoId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: analytics
public function analytics(ApiTester $I)
{
$checkProbabilities = function ($probabilities, $requestsConditions, $requestsRule) use($I) {
$ruleIndex = 0;
foreach ($I->getResponseFields()->data->variants[0]->rules as $rule) {
$conditionIndex = 0;
foreach ($rule->conditions as $condition) {
$I->assertEquals($probabilities[$ruleIndex]['conditions'][$conditionIndex], $condition->probability, "Wrong probability for condition {$condition->field_key}:{$condition->condition}=" . var_export($condition->value, true));
$I->assertEquals(is_array($requestsConditions) ? $requestsConditions[$condition->field_key] : $requestsConditions, $condition->requests, "Wrong request amount for condition {$condition->field_key}");
$conditionIndex++;
}
$I->assertEquals($probabilities[$ruleIndex]['rule'], $rule->probability, "Wrong probability for rule {$rule->title}");
$I->assertEquals(is_array($requestsRule) ? $requestsRule[$ruleIndex] : $requestsRule, $rule->requests, "Wrong request amount for rule {$rule->title}");
$ruleIndex++;
}
};
$I->createAndLoginUser();
$I->createProjectAndSetHeader();
$variantId1 = $I->getMongoId();
$variantId2 = $I->getMongoId();
$tableData = $I->getTableShortData();
$tableData['variants'][0]['_id'] = $variantId1;
$tableData['variants'][] = ['_id' => $variantId2, 'default_decision' => 'Decline', 'rules' => [['than' => 'Approve', 'title' => 'Valid rule title', 'description' => 'Valid rule description', 'conditions' => [['field_key' => 'numeric', 'condition' => '$eq', 'value' => true], ['field_key' => 'string', 'condition' => '$eq', 'value' => 'Yes'], ['field_key' => 'bool', 'condition' => '$eq', 'value' => false]]]]];
$table = $I->createTable($tableData);
$checkData = [['numeric' => 340, 'string' => 'Bad', 'bool' => true], ['numeric' => 350, 'string' => 'Yes', 'bool' => false], ['numeric' => 360, 'string' => 'Not', 'bool' => false], ['numeric' => 370, 'string' => 'Yes', 'bool' => false], ['numeric' => 380, 'string' => 'Not', 'bool' => false], ['numeric' => 390, 'string' => 'Yes', 'bool' => true], ['numeric' => 400, 'string' => 'Bad', 'bool' => true], ['numeric' => 410, 'string' => 'Not', 'bool' => true], ['numeric' => 420, 'string' => 'Yes', 'bool' => false]];
foreach ($checkData as $data) {
$data['variant_id'] = $variantId1;
$I->makeDecision($table->_id, $data, 'decision');
}
$I->sendGET("api/v1/admin/tables/{$table->_id}/{$variantId1}/analytics");
$I->assertTableWithAnalytics();
$checkProbabilities([['rule' => round(1 / 9, 5), 'conditions' => [round(3 / 9, 5), round(4 / 9, 5), round(5 / 9, 5)]], ['rule' => 0, 'conditions' => [round(6 / 9, 5), round(3 / 9, 5), round(4 / 9, 5)]]], 9, 9);
$tableData['fields'][3] = ["key" => 'last', "title" => 'last', "source" => "request", "type" => 'numeric', 'preset' => null];
$tableData['variants'][0]['rules'][0]['conditions'][] = ['field_key' => 'last', 'condition' => '$lte', 'value' => 300];
$tableData['variants'][0]['rules'][1]['conditions'][] = ['field_key' => 'last', 'condition' => '$lt', 'value' => 500];
$tableData['variants'][1]['rules'][0]['conditions'][] = ['field_key' => 'last', 'condition' => '$lt', 'value' => 500];
sleep(1);
$I->sendPUT('api/v1/admin/tables/' . $table->_id, $tableData);
$I->seeResponseCodeIs(200);
$checkData = [['numeric' => 380, 'string' => 'Not', 'last' => 250, 'bool' => true], ['numeric' => 390, 'string' => 'Not', 'last' => 300, 'bool' => true], ['numeric' => 400, 'string' => 'Yes', 'last' => 450, 'bool' => false], ['numeric' => 410, 'string' => 'Bad', 'last' => 550, 'bool' => false], ['numeric' => 420, 'string' => 'Bad', 'last' => 650, 'bool' => true]];
foreach ($checkData as $data) {
$data['variant_id'] = $variantId1;
$I->makeDecision($table->_id, $data);
}
$I->sendGET("api/v1/admin/tables/{$table->_id}/{$variantId1}/analytics");
$I->assertTableWithAnalytics();
$checkProbabilities([['rule' => 0, 'conditions' => [round(3 / 5, 5), round(1 / 5, 5), round(2 / 5, 5), round(2 / 5, 5)]], ['rule' => round(2 / 5, 5), 'conditions' => [round(2 / 5, 5), round(2 / 5, 5), round(3 / 5, 5), round(3 / 5, 5)]]], 5, 5);
$I->sendGET("api/v1/admin/tables/{$table->_id}/{$variantId2}/analytics");
$I->assertTableWithAnalytics();
$checkProbabilities([['rule' => 0, 'conditions' => [0, 0, 0, 0]]], ['last' => 0, 'bool' => 0, 'string' => 0, 'numeric' => 0], 0);
$I->sendGET("api/v1/admin/tables/{$table->_id}/invalidId/analytics");
$I->seeResponseCodeIs(404);
}
示例2: checkManyVariants
public function checkManyVariants(ApiTester $I)
{
$I->createAndLoginUser();
$I->createProjectAndSetHeader();
$tableData = $I->getTableShortData();
$variantId1 = $I->getMongoId();
$variantId2 = $I->getMongoId();
$tableData['variants'][0]['_id'] = $variantId1;
$tableData['variants'][] = ['_id' => $variantId2, 'default_decision' => 'Decline', 'rules' => [['than' => 'Approve', 'title' => 'Valid rule title', 'description' => 'Valid rule description', 'conditions' => [['field_key' => 'numeric', 'condition' => '$eq', 'value' => true], ['field_key' => 'string', 'condition' => '$eq', 'value' => 'Variant'], ['field_key' => 'bool', 'condition' => '$eq', 'value' => true]]]]];
$table = $I->createTable($tableData);
$checkData = [['numeric' => 500, 'string' => 'Yes', 'bool' => false, 'variant_id' => $variantId1], ['numeric' => 500, 'string' => 'Variant', 'bool' => true, 'variant_id' => $variantId2]];
foreach ($checkData as $item) {
$decision = $I->makeDecision($table->_id, $item);
$I->assertTableDecisionsForConsumer();
$I->sendGET('api/v1/admin/decisions/' . $decision->_id);
$I->assertTableDecisionsForAdmin();
$I->assertResponseDataFields(['final_decision' => 'Approve', 'table' => ['_id' => $table->_id, 'variant' => ['_id' => $item['variant_id']]]]);
}
$decision = $I->makeDecision($table->_id, ['numeric' => 500, 'string' => 'Yes', 'bool' => false]);
$I->assertTableDecisionsForConsumer();
$I->sendGET('api/v1/admin/decisions/' . $decision->_id);
$I->assertTableDecisionsForAdmin();
$I->assertTrue(in_array($I->getResponseFields()->data->table->variant->_id, [$variantId1, $variantId2]));
foreach ([$variantId1, $variantId2] as $variantId) {
$I->sendGET('api/v1/admin/decisions?variant_id=' . $variantId);
$I->seeResponseCodeIs(200);
foreach ($I->getResponseFields()->data as $decision) {
$I->assertTrue($decision->table->variant->_id == $variantId, "Decision doesn't filtered by variant_id {$variantId}");
}
}
}