mardi 24 octobre 2017

codeception Example to Array

Is there an implemented method to convert an Example to an Array so I can pass it right to a post request as parameters. Right now I have to do:

/**
     * @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'
            ],
        ];
    }

but I would like something like:

public function it_does_not_get_tracked_for_an_invalid_request(ApiTester $I, Example $example)
    {
        $I->sendPOST('/useractivity', $example->toArray());
        $I->seeResponseCodeIs(422);
    }

Aucun commentaire:

Enregistrer un commentaire