Created
November 19, 2014 12:26
-
-
Save paulodiovani/5a19d886be3afcf54977 to your computer and use it in GitHub Desktop.
Proposal for a new PHP Spec Test framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * This is a proposal for a new PHP test framework, | |
| * based on the Mocha (http://mochajs.org/) dsl | |
| * | |
| * ## Features | |
| * | |
| * * Simple, easy to read | |
| * * Non object oriented tests | |
| * * Extensible | |
| */ | |
| /** | |
| * The `describe()` function describes the entity or feature to be tested. | |
| * | |
| * The function receives a description string as the first argument and | |
| * a Closure as the second. | |
| */ | |
| describe("Stupid test", function() { | |
| /** | |
| * Each test is encapsulated on a new Closure, passed | |
| * as the second argument for the `id()` function. | |
| * | |
| * The First argument is a test description. "it" references | |
| * the entity or feature previously described. | |
| */ | |
| it("pass", function() { | |
| $result = 1; | |
| /** | |
| * Here goes the assertion library. | |
| * The idea is to start using PHPUnit assertions | |
| */ | |
| assertEquals($result, 1); | |
| /** | |
| * The framework should accept additional | |
| * assertions libraries. Here goes and example using expect | |
| * and chaining. | |
| * | |
| * Note that property chaining is possible with PHP by using | |
| * Magic Methods (http://php.net/manual/en/language.oop5.magic.php). | |
| */ | |
| expect($result)->to->be->equal(1); | |
| /** | |
| * If no assertion libreary is used, | |
| * the test should pass by returning true | |
| */ | |
| return $result === 1; | |
| }); | |
| /** | |
| * Hooks could be called with description + Closure, | |
| * or just a Closure | |
| */ | |
| before(function() { | |
| //hook code will run here, | |
| //before the next tests | |
| }); | |
| beforeEach("each test starts", function() { | |
| //hook code will run, starting from here, | |
| //before each of the next tests | |
| }); | |
| after("all test ends", function() { | |
| //hook will run after all tests pass | |
| }); | |
| afterEach(function() { | |
| //hook runs after each test pass | |
| }); | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mjacobus remembered me that there is already https://github.com/davedevelopment/dspec for this.
I shall be looking on it's source.