From 01b73e7ecaca60d4c4b93a8c5b3fe854de1c6349 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 27 Feb 2024 13:24:50 +0000 Subject: [PATCH 1/2] Addon Testing docs --- content/collections/extending-docs/addons.md | 59 ++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/content/collections/extending-docs/addons.md b/content/collections/extending-docs/addons.md index c32af1e5e..5f9850cec 100644 --- a/content/collections/extending-docs/addons.md +++ b/content/collections/extending-docs/addons.md @@ -542,6 +542,65 @@ The `update()` method is where your custom data migration logic happens. Feel fr That's it! Statamic should now automatically run your update script as your users update their addons. +## Testing + +When you create an addon with the `make:addon` command, Statamic will automatically scaffold the necessary files for a PHPUnit test suite. + +``` files theme:serendipity-light +tests/ + ExampleTest.php + TestCase.php +phpunit.xml +``` + +The `TestCase` class extends Statamic's built-in `AddonTestCase` which is responsible for booting your addon's service provider, amoungst other things. Under the hood, your addon's tests use [Orchestra Testbench](https://github.com/orchestral/testbench) which provides a layer allowing you to write tests against a *real* Laravel application. + +### Writing Tests + +All of your tests should extend your addon's `TestCase` class, like so: + +```php +assertTrue(true); + } +} +``` + +For more information on writing tests, please review the [Laravel Testing Documentation](https://laravel.com/docs/10.x/testing). + +### Running Tests + +Once you've written some tests, you can run them using `phpunit`: + +```bash +./vendor/bin/phpunit +``` + +You may run a specific test by passing the `--filter` argument: + +```bash +# Runs all tests in the CheckoutTest +./vendor/bin/phpunit --filter=CheckoutTest + +# Runs the specific user_cant_checkout_without_payment test +./vendor/bin/phpunit --filter=user_cant_checkout_without_payment + +# Runs all tests with checkout in their name. +./vendor/bin/phpunit --filter=checkout +``` + ## Publishing to the Marketplace From 5f2437cfd941d4d3c21196b099277139a46f361c Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 13 Mar 2024 16:12:53 +0000 Subject: [PATCH 2/2] Fix tyyo --- content/collections/extending-docs/addons.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/collections/extending-docs/addons.md b/content/collections/extending-docs/addons.md index 5f9850cec..244ee6bd5 100644 --- a/content/collections/extending-docs/addons.md +++ b/content/collections/extending-docs/addons.md @@ -553,7 +553,7 @@ tests/ phpunit.xml ``` -The `TestCase` class extends Statamic's built-in `AddonTestCase` which is responsible for booting your addon's service provider, amoungst other things. Under the hood, your addon's tests use [Orchestra Testbench](https://github.com/orchestral/testbench) which provides a layer allowing you to write tests against a *real* Laravel application. +The `TestCase` class extends Statamic's built-in `AddonTestCase` which is responsible for booting your addon's service provider, amongst other things. Under the hood, your addon's tests use [Orchestra Testbench](https://github.com/orchestral/testbench) which provides a layer allowing you to write tests against a *real* Laravel application. ### Writing Tests