This repository has been archived by the owner on Sep 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Conversation
This file contains 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
It is like `when` but it expects the result of the callable to be `void`.
The `assert` asserter helps to test a piece of code using the `assert` intrinsic.
The `hoa test:generate` command was obselete. It is rewritten to: 1. Generate unit test suites based on contracts written in Praspel, 2. Generate integration test suites based on examples in the API documentations. The Praspel supports is not implemented yet. The API documentation supports is implemented. `hoa test:generate …` to generate the test suites, and then `hoa test:run` to run them. This is the current workflow.
Deduce generator directory and generator namespace from the `composer.json` file if it exists. If no `composer.json` file is found, do not generate doc tests.
A code block has a type t and a content c: ```t c ``` The type can be optional. In our contexte, a missing type is equivalent to the `php` type. The generator only handles the `php` type, in order to compile them into test cases.
Each code block must has the type `php`. However, the type is a list of verbs, separated by a comma. So `php,ignore` is valid, and contains two verbs: `php`, and `ignore`. If the verb `ignore` is present, then the code block is compiled into a test case but it is marked as `skip`.
Just type `ignore`, `must_throw` is a new verb that can be used in a code block type. Thus `php,must_throw` represents an code block that is a PHP program but it must throw an exception. So far, exceptions must be of kind `Exception`. It restricts exceptions to the runtime exception category.
New verb `must_throw` for the code block type has been introduced recently. This patch enhances it by adding a parameter to this verb: `must_throw(E)` where `E` is a class name, expecting to be an exception. Thus, the following example will fail: /** * # Examples * * ```php,must_throw(ErrorException) * throw new \RuntimeException(); * ``` */
Code block can have comments. If the comment starts with `#` (shell style), then the whole comment is removed for the HTML API browser, but they are kept when compiling examples into test cases. So the following example: # $a = 1; $b = 2; assert(3 === $a + $b); will be compiled as the following test case: $a = 1; $b = 2; assert(3 === $a + $b); and will be displayed as follows for the HTML version: $b = 2; assert(3 === $a + $b); This is useful when we would like to add `use` statements in comments. In our context, we cannot use `use` because test cases are methods, and the syntax of PHP does not allow `use` statements inside methods. So we must expanded `use` statements to remove them. To address that, the new `unfoldCode` method lexes and expands `use` statements. For instance: # use Foo\Bar; new Bar\Baz(); will be unfolded as: # use Foo\Bar; new \Foo\Bar\Baz(); To achieve this, first, the comments are removed, and, second, `<?php` is prepended: <?php use Foo\Bar; new Bar\Baz(); Then, third, we use the `token_get_all` native lexer to lex the code block, and rewrite it. Finally, when rewriting, the `use` statements are put in comments (of kinds `#`), even if they were not in comments before. The `<?php` opening tag is removed too. The result is: # use Foo\Bar; new \Foo\Bar\Baz();
vonglasow
suggested changes
Mar 27, 2017
Bin/Generate.php
Outdated
$generator = new \Atoum\PraspelExtension\Praspel\Generator(); | ||
$generator->setTestNamespacer(function ($namespace) { | ||
$parts = explode('\\', $namespace); | ||
var_dump($generateDocumentation, $directoryToScan, $namespaceToScan); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove the var_dump
Generator/Documentation.php
Outdated
|
||
return array_reduce( | ||
token_get_all($code), | ||
function ($accumulator, $token) use (&$buffer, &$state, &$aliases) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe separate the function definition to this usage to improve code clarity ?
$reducing = function (...
return array_reduce(token_get_all($code), $reducing...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we will gain a lot, bu why not 🙂.
Ease code readability.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Address hoaproject/Central#52.