MemoryRefresh!

Various / PHPUNIT   PHPUNIT



Questions 1 Answers 0%

Pages   0 from 91
Questions   0 from 142

Reset



<?php function isEven($n) { return $n%2 == 0; } function isOdd($n) { return $n%2 != 0; } { ini_set("include_path", ini_get("include_path") . ";PHPUnit-1.3.2"); require "PHPUnit.php"; class TestCase extends PHPUnit_TestCase { public function testEven() { $this->assertEquals(isEven(2), true); $this->assertEquals(isEven(3), false); } public function testOdd() { $this->assertEquals(isOdd(2), false); $this->assertEquals(isOdd(3), true); } } $suite = new PHPUnit_TestSuite("TestCase"); // automaticaly add methods that starts with 'test' print PHPUnit::run($suite)->toHTML(); // TestCase TestCase->testEven() passed // TestCase TestCase->testOdd() passed } PHPUnit-4.8.21 (phar)
<?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; } } pear.php.net

Related Pages

SPL
XML
SOAP
JSON
PHPUNIT
PHAR


0% 100%
 
 
0 pages 91 pages
1) What is the new include_path?




2) What file to require?




3) Which class does myTestClass extends?








<?php function isEven($n) { return $n%2 == 0; } function isOdd($n) { return $n%2 != 0; } { ini_set("include_path", ini_get("include_path") . ";PHPUnit-1.3.2"); require "PHPUnit.php"; class TestCase extends PHPUnit_TestCase { public function testEven() { $this->assertEquals(isEven(2), true); $this->assertEquals(isEven(3), false); } public function testOdd() { $this->assertEquals(isOdd(2), false); $this->assertEquals(isOdd(3), true); } } $suite = new PHPUnit_TestSuite("TestCase"); // automaticaly add methods that starts with 'test' print PHPUnit::run($suite)->toHTML(); // TestCase TestCase->testEven() passed // TestCase TestCase->testOdd() passed } PHPUnit-4.8.21 (phar)
<?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; } } pear.php.net

References









Programming

Php
   
Regex
   
MySQL
   
Css
   
jQuery
   
Git
   


References