Friday 15 July 2011

php - PhpUnit and string -



php - PhpUnit and string -

i started learning phpunit , testing. have method returns string, how can write test check if method returns string. here code have @ moment:

method:

/** * @return string */ public function living() { homecoming 'happy!'; }

test:

public $real; public $expected; public function testliving() { $this->expected = 'happy'; $this->real = 'speechless'; $this->asserttrue($this->expected == $this->real); }

$this->asserttrue($this->expected == $this->real);

is same as

$this->assertequals($this->expected, $this->real);

see https://phpunit.de/manual/current/en/appendixes.assertions.html#appendixes.assertions.assertequals

both check if given variables equal.

you check if variable string

$this->asserttrue(is_string($this->real));

php unit-testing phpunit

No comments:

Post a Comment