php - Using value from previous test case in PHPUnit -


i trying assign value variable inside first testing function , use in other testing functions inside class.

right in code second function fails due error:

   1) apiadtest::testapiad_postedadcreated guzzlehttp\exception\clientexception: client error: 404 

and dont know why. how code looks like:

 class apiadtest extends phpunit_framework_testcase     {         protected $adid;         private static $base_url = 'http://10.0.0.38/adserver/src/public/';         private static $path = 'api/ad/';          //start of expected flow          public function testapiad_postad()         {             $client = new client(['base_uri' => self::$base_url]);             $response = $client->post(self::$path, ['form_params' => [               'name' => 'bellow content - guzzle testing'               ]]);             $data = json_decode($response->getbody());             $this->adid = $data->id;              $code = $response->getstatuscode();             $this->assertequals($code, 200);         }          public function testapiad_postedadcreated()         {             $client = new client(['base_uri' => self::$base_url]);             $response = $client->get(self::$path.$this->adid);             $code = $response->getstatuscode();             $data = json_decode($response->getbody());              $this->assertequals($code, 200);             $this->assertequals($data->id, $this->adid);             $this->assertequals($data->name, 'bellow content - guzzle testing');         } 

in phpunit doumintation https://phpunit.de/manual/current/en/fixtures.html see can define variable inside setup method , use want in case know value after first post executes. idea how can use $this->adid in second function??

unit tests definition should not rely on 1 another. end unstable , fragile tests hard debug moment start failing, since cause in test case.

there no guarantee in order tests execute in phpunit default.

phpunit supports @depends annotation achieve want, docs have same warning though.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -