samedi 19 septembre 2015

Why doesn't work the module REST in method _beforeSuite?

I am using Codeception to learn to create tests in PHP. I want to test my REST API, and I need get an access token for use with all my tests.

I created a helper:

namespace Helper;

/**
 * Class Oauth2
 * @package Helper
 */
class Oauth2 extends \Codeception\Module
{
    public function _before()
    {
        $I = $this->getModule('REST');

        $I->sendPOST("http://ift.tt/1Pe3RSa", [
            'username' => 'admin',
            'password' => 'admin',
        ]);

        $I->seeResponseCodeIs(200);
        $I->seeResponseIsJson();

        $token = $I->grabDataFromResponseByJsonPath('$..access_token');
        $token = $token[0];

        $I->amBearerAuthenticated($token);
    }

}

It works! But the _before() method is performed before each test.

I tried to use the _beforeSuite() method (this method is performed only once), but it throws an error:

PHP Fatal error: Call to a member function request() on null in phar:///usr/local/bin/codecept/src/Codeception/Module/REST.php on line 476

Why is this happening?

Aucun commentaire:

Enregistrer un commentaire