本文整理汇总了PHP中ApiTester::grabRecord方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiTester::grabRecord方法的具体用法?PHP ApiTester::grabRecord怎么用?PHP ApiTester::grabRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiTester
的用法示例。
在下文中一共展示了ApiTester::grabRecord方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ApiTester
<?php
$I = new ApiTester($scenario);
$I->wantTo('poke the server with an existing device and a new IP');
$initial_created_at = \Carbon\Carbon::now()->subHour();
$initial_updated_at = \Carbon\Carbon::now()->subHour();
$I->haveRecord('devices', ['ip' => '192.168.1.123', 'mac' => '00:19:20:A1:B4:FC', 'name' => 'Manuel', 'created_at' => $initial_created_at, 'updated_at' => $initial_updated_at]);
$I->sendPOST('devices/poke', ['ip' => '192.168.1.100', 'mac' => '00:19:20:A1:B4:FC', 'name' => 'Manuel']);
$I->seeResponseCodeIs(200);
$I->seeHttpHeader('Location', 'http://localhost/api/v1/devices/1');
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['data' => ['ip' => '192.168.1.100', 'name' => 'Manuel', 'on_home_page' => 'auto', 'group' => null]]);
$I->seeResponseJsonMatchesXpath('//data//device_added');
$I->seeResponseJsonMatchesXpath('//data//last_contact');
$I->seeRecord('devices', ['ip' => '192.168.1.100', 'mac' => '00:19:20:A1:B4:FC', 'name' => 'Manuel', 'public' => 'auto', 'group' => null]);
$I->seeRecord('pokes', ['ip' => '192.168.1.100', 'mac' => '00:19:20:A1:B4:FC']);
$device = $I->grabRecord('devices', ['mac' => '00:19:20:A1:B4:FC']);
$created_at_after_poke = $I->carbonize($device->created_at);
$updated_at_after_poke = $I->carbonize($device->updated_at);
$I->assertTrue($updated_at_after_poke->gt($initial_updated_at), 'The updated_at timestamp after the poke is greater than the initial updated_at timestamp');
$I->assertTrue($updated_at_after_poke->gt($initial_created_at), 'The updated_at timestamp after the poke is greater than the initial created_at timestamp');
$I->assertTrue($created_at_after_poke->eq($initial_created_at), 'The created_at timestamp after the poke is equal to the initial created_at timestamp');
示例2: ApiTester
<?php
$I = new ApiTester($scenario);
$I->wantTo('list all devices');
$I->haveRecord('devices', ['ip' => '192.168.1.101', 'mac' => '11:22:33:44:55:66', 'name' => 'Public Pi', 'public' => 'true', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]);
$piOne = $I->grabRecord('devices', ['ip' => '192.168.1.101']);
$piTwo = $I->haveRecord('devices', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Private Pi', 'public' => 'false', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]);
$piTwo = $I->grabRecord('devices', ['ip' => '192.168.1.102']);
$piThree = $I->haveRecord('devices', ['ip' => '192.168.1.103', 'mac' => 'AA:11:BB:22:CC:33', 'name' => 'Auto Pi without group', 'public' => 'auto', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]);
$piThree = $I->grabRecord('devices', ['ip' => '192.168.1.103']);
$piFour = $I->haveRecord('devices', ['ip' => '192.168.1.104', 'mac' => 'DD:44:EE:55:FF:66', 'name' => 'Auto Pi with group', 'public' => 'auto', 'group' => 'my-group', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]);
$piFour = $I->grabRecord('devices', ['ip' => '192.168.1.104']);
$I->sendGET('devices');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['data' => ['ip' => '192.168.1.101', 'name' => 'Public Pi', 'on_home_page' => 'true', 'group' => null, 'device_added' => \Carbon\Carbon::parse($piOne->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piOne->updated_at)->toIso8601String()]]);
$I->dontSeeResponseContainsJson(['data' => ['ip' => '192.168.1.102', 'name' => 'Private Pi', 'on_home_page' => 'false', 'group' => null, 'device_added' => \Carbon\Carbon::parse($piTwo->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piTwo->updated_at)->toIso8601String()]]);
$I->seeResponseContainsJson(['data' => ['ip' => '192.168.1.103', 'name' => 'Auto Pi without group', 'on_home_page' => 'auto', 'group' => null, 'device_added' => \Carbon\Carbon::parse($piTwo->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piTwo->updated_at)->toIso8601String()]]);
$I->dontSeeResponseContainsJson(['data' => ['ip' => '192.168.1.104', 'name' => 'Auto Pi with group', 'on_home_page' => 'auto', 'group' => 'my-group', 'device_added' => \Carbon\Carbon::parse($piTwo->created_at)->toIso8601String(), 'last_contact' => \Carbon\Carbon::parse($piTwo->updated_at)->toIso8601String()]]);
$I->sendGET('devices/@my-group');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['data' => ['name' => 'Auto Pi with group']]);
$I->dontSeeResponseContainsJson(['data' => ['name' => 'Auto Pi without group']]);
$I->dontSeeResponseContainsJson(['data' => ['name' => 'Private Pi']]);
$I->dontSeeResponseContainsJson(['data' => ['name' => 'Public Pi']]);
示例3: ApiTester
<?php
$I = new ApiTester($scenario);
$I->wantTo('update a device');
$user = $I->haveAnAccount();
$I->amHttpAuthenticated($user['email'], $user['password']);
$created_at = \Carbon\Carbon::now()->subHour();
$updated_at = \Carbon\Carbon::now()->subHour();
$I->haveRecord('devices', ['ip' => '192.168.1.101', 'mac' => '11:22:33:44:55:66', 'name' => 'Awesome Pi One', 'created_at' => $created_at, 'updated_at' => $updated_at]);
$I->sendPATCH('devices/1', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Updated Awesome Pi One']);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['ip' => '192.168.1.102', 'name' => 'Updated Awesome Pi One', 'on_home_page' => 'auto', 'group' => null]);
$I->seeResponseJsonMatchesXpath('//data//device_added');
$I->seeResponseJsonMatchesXpath('//data//last_contact');
$I->canSeeRecord('devices', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Updated Awesome Pi One', 'public' => 'auto', 'group' => null]);
$updatedDevice = $I->grabRecord('devices', ['ip' => '192.168.1.102']);
$I->cantSeeRecord('devices', ['ip' => '192.168.1.101', 'mac' => '11:22:33:44:55:66', 'name' => 'Awesome Pi One']);
$updated_created_at_timestamp = $I->carbonize($updatedDevice->created_at);
$updated_updated_at_timestamp = $I->carbonize($updatedDevice->updated_at);
$I->assertTrue($updated_created_at_timestamp->eq($created_at), 'Updated created_at timestamp is equal to the initial created_at timestamp');
$I->assertTrue($updated_updated_at_timestamp->gt($updated_at), 'Updated updated_at timestamp is greater than the initial updated_at timestamp');
$I->assertTrue($updated_updated_at_timestamp->gt($created_at), 'Updated updated_at timestamp is greater than the initial created_at timestamp');
$I->sendPATCH('devices/100', ['ip' => '192.168.1.102', 'mac' => 'AA:BB:CC:DD:EE:FF', 'name' => 'Updated Awesome Pi One']);
$I->seeResponseCodeIs(404);
$I->seeResponseIsJson();