PHP Classes

ITest v2: Run tests on classes defined in comments

Recommend this page to a friend!
  Info   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (2 months ago) RSS 2.0 feedNot enough user ratingsTotal: 236 All time: 8,073 This week: 555Up
Version License PHP version Categories
itest_v2 2.0The PHP License5.4PHP 5, Testing
Description 

Author

This package can run tests on classes or functions defined in comments.

It can add a function or a class to the list of code be tested.

It can process the docblock comments in the code to extract the definitions of the class and functions to be tested, well any test parameters and conditions to see if the tests are passed.

Picture of AlexanderC
  Performance   Level  
Name: AlexanderC is available for providing paid consulting. Contact AlexanderC .
Classes: 13 packages by
Country: Moldova Moldova
Age: 34
All time rank: 7301 in Moldova Moldova
Week rank: 420 Up1 in Moldova Moldova Equal
Innovation award
Innovation award
Nominee: 3x

Details

Inline testing- Pyha Framework Component ======================================== Inline testing is a kick start for implementing TDD in your team(or for you if you are coding alone). You may understand all the thing by analyzing the following example: <?php /** * @author AlexanderC */ namespace Pyha\Libs\ITest; /** * This is an test example to test the * inline testing lib o_O * * @assert { * @params { * 'i like strings' * } * @assertions { * $result->foo == 'i like strings' * $result->foo->baz == 'hey, we do not have such property' * !is_string($result->foo) * $result instanceof Pyha\Libs\ITest\Example * } * } */ class Example { /** * @var mixed */ public $foo; /** * @param Application $foo */ public function __construct($foo) { $this->foo = $foo; } /** * Note that for the method testing is reused class * instance from the class test case if method cases * are added during the class test case(isset testMethods flag) * * @param mixed $a * @param callable $b * @param array $c * * @assert { * @params { * 2 * function(array $arr) { return $arr[0]; } * [2] * } * @assertions { * $result == 4 * segswegw // this is messed thing, but don't worry about!!! * is_int($result) * !is_scalar($result) * } * } */ public function simpleTest($a, callable $b, array $c) { return call_user_func($b, $c) + $a; } } /** * @param int $a * @param int $b * @param array $c * * @assert { * @params { * 2 * 2 * [2] * } * @assertions { * $result == 6 * segswegw // this is messed thing, but don't worry about!!! * !is_int($result) * is_scalar($result) * } * } */ function exampleTestFunction($a, $b, array $c) { return $a + $b + $c[0]; } How do i run my tests? ---------------------- The answer is in the code bellow: $tester = new Libs\ITest\Test(); $classes = get_declared_classes(); foreach($classes as $class) { $tester->addClass($class); } unset($classes); $functions = get_defined_functions()['user']; foreach($functions as $function) { $tester->addFunction($function); } unset($functions); $tester->run(); if(count($tester->getFails()) > 0) { exit(nl2br("\n\n{$tester}")); } This will run the tests for all your function and classes loaded in current session. This should be placed in an shutdown function or something like this. But of course you can add classes and function manually or even scan directories recursively and add your "things" to be tested by yourself Loading library ------------ If you are not using Composer you may add to autoloader the lib path or even include the files manualy Installing via Composer -------------------- To install it via composer just use following command: $ composer.phar install

  Files folder image Files  
File Role Description
Files folder imagelib (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  lib  
File Role Description
Files folder imageITest (3 files, 2 directories)

  Files folder image Files  /  lib  /  ITest  
File Role Description
Files folder imageParser (2 files)
Files folder imageTestCases (4 files)
  Plain text file AssertionFail.php Class Class source
  Accessible without login Plain text file Example.php Example Example script
  Plain text file Test.php Class Class source

  Files folder image Files  /  lib  /  ITest  /  Parser  
File Role Description
  Plain text file DocblockExtractor.php Class Class source
  Plain text file Tokens.php Class Class source

  Files folder image Files  /  lib  /  ITest  /  TestCases  
File Role Description
  Plain text file ClassCase.php Class Class source
  Plain text file FunctionCase.php Class Class source
  Plain text file ICase.php Class Class source
  Plain text file MethodCase.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:236
This week:0
All time:8,073
This week:555Up