Studyon Minte9.com
ZCE 5.3




PHPUnit-4.8.21




<?php include("PHPUnit-4.8.21phpunit-4.8.21.phar"); include("PHPUnit-4.8.21TestSuite.php"); class TestCase extends PHPUnit_Framework_TestCase { public function test() { $this->assertTrue(isEven(2)); $this->assertFalse(isEven(3)); $this->assertTrue(isEven(43)); } } function isEven($n) { return $n % 2 == 0; } $test = new TestSuite("TestCase"); $result = $test->run(); echo $result->getMessage();
  TestSuite.php
<?php class TestSuite extends PHPUnit_Framework_TestSuite { protected $result; public function run(PHPUnit_Framework_TestResult $result = NULL) { $this->result = parent::run($result); //var_dump($result); return $this; // retrun (TestSuite) object } public function getMessage() { $failures = $this->getNodeValue($this->result, "failures"); $message = isset($failures[0]) ? $this->getNodeValue($failures[0], "failedTest/statusMessage") : key($this->getNodeValue($this->result, "passed")) . " passed"; return $message; } protected function getNodeValue($obj, $path) { foreach(explode("/", $path) as $node) { $reflector = new ReflectionObject($obj); // use Reflection to get nodes from object try { $node = $reflector->getProperty($node); } catch (Exception $e) { $node = $reflector->getParentClass()->getProperty($node); } $node->setAccessible(true); $obj = $node->getValue($obj); } return $obj; } }