PHP Classes

InlineTesting: Test classes and fuctions using docblock comments

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 286 All time: 7,543 This week: 455Up
Version License PHP version Categories
inline-testing 0.1.0GNU General Publi...5.4PHP 5, Testing
Description 

Author

This class can test classes and fuctions using docblock comments.

It can test given classes or functions by parsing docblock sections of the code scripts to be tested to extract the definition of assert conditions for the tests that need to be performed.

The packages comes with special traits definitions that are necessary to use this class with the classes that are meant to be tested.

Innovation Award
PHP Programming Innovation award nominee
November 2012
Number 5


Prize: One subscription to the PDF edition of the PHP Architect magazine
Test driven development is an approach that can help minimizing the bugs software applications.

However, for many developers writing code for implementing tests is a boring task, so many of them end up not doing it.

This class can help minimizing the effort necessary to write tests for classes.

It lets developers insert some testing conditions in the comments of their classes, so this class can do the actual testing without further effort from the developer.

Manuel Lemos
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: 170 Up1 in Moldova Moldova Equal
Innovation award
Innovation award
Nominee: 3x

Details

=== What are you doing here? === [?] What are lnline tests? [!] That's an simple test case that is done directly at the runtime(certainly must be only in dev environment). Test data is parsed from docblock === The goal === Except expensive unit tests, you can also test in very simple way without running any daemon or even console application. You should only use docblock sections and add class testing to your autoloader or use testable trait. $inlineTester = Testing\InlineTesting::getInstance(/* false to avoid testing, for ex. in prod environment */); $inlineTester->testClass("Foo"); // this will test all methods from the class where are docblock @assert sections found $inlineTester->testFunction("myFunc"); // this will test the function if any docblock entry there In order to use Testable trait you have to add it o_O: class Foo { use Testing\Traits\Testable; /** * This method will be tested * Note: the inline test will pass, but if not it will trigger an informative error * * @param int $foo * @param int $bar * @param array $things * @return int * * @assert 2 and "2" and [1, 2, 3] equals 7 */ private /* or protected even public */ function myMethod($foo, $bar, array $things = []){ return (int) $foo + (int) $bar + count($things); } private /* or public, does not matter */ function onAfterDestruct(){ // that is your destructor from now, because __destruct() is preserved by the Testable trait // now you do not have to call testClass method each time you wanna test your classes } }

  Files folder image Files (4)  
File Role Description
Files folder imageTraits (2 files)
Plain text file InlineTesting.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (4)  /  Traits  
File Role Description
  Plain text file Singleton.php Class Class source
  Plain text file Testable.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:286
This week:0
All time:7,543
This week:455Up