Skip to content

Commit

Permalink
[docs] Migrate Writing PHPUnit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Ziegenberg <[email protected]>
  • Loading branch information
ziegenberg committed May 3, 2024
1 parent d4af469 commit 780eb2a
Show file tree
Hide file tree
Showing 7 changed files with 619 additions and 6 deletions.
3 changes: 3 additions & 0 deletions data/migratedPages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,9 @@ Web_services_API:
Web_services_files_handling:
- filePath: "/docs/apis/subsystems/external/files.md"
slug: "/docs/apis/subsystems/external/files"
Writing_PHPUnit_tests:
- filePath: "/general/development/tools/phpunit/write.md"
slug: "/general/development/tools/phpunit/write"
Writing_acceptance_tests:
- filePath: "/general/development/tools/behat/writing.md"
slug: "/general/development/tools/behat/writing"
Expand Down
4 changes: 2 additions & 2 deletions general/development/policies/codingstyle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1765,8 +1765,8 @@ This tag is valid and can be used optionally to indicate the method or function
There are some tags that are only allowed within some contexts and not globally. More precisely:

- `@Given`, `@When`, `@Then`, within the [behat steps definitions](../../tools/behat/writing.md#writing-new-acceptance-test-step-definitions).
- `@covers`, `@coversDefaultClass`, `@coversNothing`, `@uses` to better control coverage within [unit tests](https://docs.moodle.org/dev/Writing_PHPUnit_tests#Generators).
- `@dataProvider` and `@testWith`, to provide example data and expectations, within [unit tests](https://docs.moodle.org/dev/Writing_PHPUnit_tests#Generators).
- `@covers`, `@coversDefaultClass`, `@coversNothing`, `@uses` to better control coverage within [unit tests](/general/development/tools/phpunit/write#generators).
- `@dataProvider` and `@testWith`, to provide example data and expectations, within [unit tests](/general/development/tools/phpunit/write#generators).
- `@depends`, to express dependencies between tests, where each producer returned data in passed to consumers. See [`@depends` examples](https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#writing-tests-for-phpunit-examples-stacktest2-php) for more information.
- `@group`, for easier collecting unit tests together, following the guidelines in the [PHPUnit MoodleDocs](../../tools/phpunit.md#using-the-group-annotation).
- `@requires`, to specify unit test requirements and skip if not fulfilled. See [`@requires` usages](https://docs.phpunit.de/en/9.6/incomplete-and-skipped-tests.html#incomplete-and-skipped-tests-requires-tables-api) for more information.
Expand Down
2 changes: 1 addition & 1 deletion general/development/tools/behat/writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ new behat step definitions for your plugin, and allows you to re-use data genera

Full documentation of this process and all available options can be found in the [PHPDoc for behat_generator_base](https://github.com/moodle/moodle/blob/1d4fdb0d1c60448104bc9eac79b5123863c67cbd/lib/behat/classes/behat_generator_base.php#L33). A core example of this can be found in [/mod/quiz/tests/generator](https://github.com/moodle/moodle/tree/main/mod/quiz/tests/generator) and [quiz_reset.feature](https://github.com/moodle/moodle/blob/1d4fdb0d1c60448104bc9eac79b5123863c67cbd/mod/quiz/tests/behat/quiz_reset.feature#L51). What follows is a simple example.

To begin, you need a [generator](https://docs.moodle.org/dev/Writing_PHPUnit_tests#Generators) in `/*your*/*plugin*/tests/generator/lib.php`. If you are generating a type of entity called "thing", your generator will need a method called create_thing, which accepts an object:
To begin, you need a [generator](/general/development/tools/phpunit/write#generators) in `/*your*/*plugin*/tests/generator/lib.php`. If you are generating a type of entity called "thing", your generator will need a method called create_thing, which accepts an object:

```php
class local_myplugin_generator extends component_generator_base {
Expand Down
2 changes: 1 addition & 1 deletion general/development/tools/phpunit.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ define('TEST_EXTERNAL_FILES_HTTP_URL', 'http://localhost/moodle-exttests');
## Writing new tests

- read [official PHPUnit online documentation](https://docs.phpunit.de/en/9.6/)
- see [Writing PHPUnit tests](https://docs.moodle.org/dev/Writing_PHPUnit_tests)
- see [Writing PHPUnit tests](/general/development/tools/phpunit/write)

## PHPUnit support in IDEs

Expand Down
Loading

0 comments on commit 780eb2a

Please sign in to comment.