Artjom Kurapov
Artjom Kurapov

Reputation: 6155

PHPUnit - get test pass status + name in tearDown()

In PHPUnit, how can I get info in tearDown() if my test passed or not, and what its name? I've tried looking into $this->getTestResultObject()->topTestSuite(), but not luck - tests seem like they are fresh with no ok/failure in them.

As output I want my custom tearDown() to have something like:

TESTCLASSNAME::TESTMETHOD - ok
TESTCLASSNAME::TESTMETHOD2 - failed

Upvotes: 1

Views: 736

Answers (1)

Artjom Kurapov
Artjom Kurapov

Reputation: 6155

Class name = explode('::',$this->toString())[0]

Test name = $this->getName()

Status = $this->hasFailed()

Upvotes: 4

Related Questions