解码示例到数组
codeception Example to Array
是否有将示例转换为数组的实现方法,以便我可以将其作为参数直接传递给 post 请求。现在我必须做:
/**
* @dataprovider invalidUserActivityRequestProvider
*/
public function it_does_not_get_tracked_for_an_invalid_request(ApiTester $I, Example $example)
{
$userActivity = [
'timestamp' => isset($example['timestamp']) ? $example['timestamp'] : null ,
'email' => isset($example['email']) ? $example['email'] : null ,
'type' => isset($example['type']) ? $example['type'] : null ,
'duration' => isset($example['duration']) ? $example['duration'] : null ,
'distance' => isset($example['distance']) ? $example['distance'] : null ,
'repetitions' => isset($example['repetitions']) ? $example['repetitions'] : null ,
];
$I->sendPOST('/useractivity', $userActivity);
$I->seeResponseCodeIs(422);
}
protected function invalidUserActivityRequestProvider () : array {
return [
[
'timestamp' => Carbon::now()->toDateTimeString(),
'email' => 'invalidUser@example.com',
'type' => 'run',
'duration' => 300,
'distance' => 1000,
'repetitions' => 1
],
[
'timestamp' => Carbon::now()->toDateTimeString(),
'email' => 'user@example.com',
'type' => 'invalidType',
'duration' => 300,
'distance' => 1000,
'repetitions' => 1
],
[
'timestamp' => Carbon::now()->toDateTimeString(),
'email' => 'user@example.com',
'type' => 'run'
],
];
}
但我想要这样的东西:
public function it_does_not_get_tracked_for_an_invalid_request(ApiTester $I, Example $example)
{
$I->sendPOST('/useractivity', $example->toArray());
$I->seeResponseCodeIs(422);
}
我不知道 Codeception,但转换是一个选项:
$I->sendPOST('/useractivity', (array)$example);
对不起,它真的不行!...
尝试 assertEqual 一个 (array) $example
和一个数组导致:
- Expected | + Actual
@@ @@
Array (
- Binary String: 0x002a0064617461 => Array (...)
+ 'id' => 6
+ 'unique_id' => '2199033651380'
+ 'data' => Array (...)
+ 'user_id' => 1
+ 'brand_id' => 1
+ 'infrastructure' => 'AT'
)
是否有将示例转换为数组的实现方法,以便我可以将其作为参数直接传递给 post 请求。现在我必须做:
/**
* @dataprovider invalidUserActivityRequestProvider
*/
public function it_does_not_get_tracked_for_an_invalid_request(ApiTester $I, Example $example)
{
$userActivity = [
'timestamp' => isset($example['timestamp']) ? $example['timestamp'] : null ,
'email' => isset($example['email']) ? $example['email'] : null ,
'type' => isset($example['type']) ? $example['type'] : null ,
'duration' => isset($example['duration']) ? $example['duration'] : null ,
'distance' => isset($example['distance']) ? $example['distance'] : null ,
'repetitions' => isset($example['repetitions']) ? $example['repetitions'] : null ,
];
$I->sendPOST('/useractivity', $userActivity);
$I->seeResponseCodeIs(422);
}
protected function invalidUserActivityRequestProvider () : array {
return [
[
'timestamp' => Carbon::now()->toDateTimeString(),
'email' => 'invalidUser@example.com',
'type' => 'run',
'duration' => 300,
'distance' => 1000,
'repetitions' => 1
],
[
'timestamp' => Carbon::now()->toDateTimeString(),
'email' => 'user@example.com',
'type' => 'invalidType',
'duration' => 300,
'distance' => 1000,
'repetitions' => 1
],
[
'timestamp' => Carbon::now()->toDateTimeString(),
'email' => 'user@example.com',
'type' => 'run'
],
];
}
但我想要这样的东西:
public function it_does_not_get_tracked_for_an_invalid_request(ApiTester $I, Example $example)
{
$I->sendPOST('/useractivity', $example->toArray());
$I->seeResponseCodeIs(422);
}
我不知道 Codeception,但转换是一个选项:
$I->sendPOST('/useractivity', (array)$example);
对不起,它真的不行!...
尝试 assertEqual 一个 (array) $example
和一个数组导致:
- Expected | + Actual
@@ @@
Array (
- Binary String: 0x002a0064617461 => Array (...)
+ 'id' => 6
+ 'unique_id' => '2199033651380'
+ 'data' => Array (...)
+ 'user_id' => 1
+ 'brand_id' => 1
+ 'infrastructure' => 'AT'
)