|
| 1 | +--- |
| 2 | +name: slic |
| 3 | +description: >- |
| 4 | + Guide for creating, modifying, and running WPUnit integration tests with |
| 5 | + slic (StellarWP Local Interactive Containers). Covers slic workflow, test |
| 6 | + structure, environment setup, HTTP mocking, WordPress factories, assertions, |
| 7 | + and Codeception/wp-browser patterns. Use when writing or debugging WordPress |
| 8 | + plugin integration tests. |
| 9 | +license: MIT |
| 10 | +compatibility: Requires Docker and slic CLI on PATH |
| 11 | +metadata: |
| 12 | + author: stellarwp |
| 13 | + version: "1.0" |
| 14 | +--- |
| 15 | + |
| 16 | +# slic — WPUnit Integration Testing Guide |
| 17 | + |
| 18 | +## When to use this skill |
| 19 | + |
| 20 | +Activate this skill when: |
| 21 | + |
| 22 | +- Writing new WPUnit integration tests for a WordPress plugin or theme |
| 23 | +- Modifying or debugging existing Codeception/wp-browser tests |
| 24 | +- Running test suites through slic (the `slic run` workflow) |
| 25 | +- Setting up a project for slic-based testing for the first time |
| 26 | +- Diagnosing flaky or order-dependent test failures |
| 27 | + |
| 28 | +## Quick-start workflow |
| 29 | + |
| 30 | +slic orchestrates Docker containers (MariaDB, Redis, WordPress, Chrome, and a Codeception runner) so you never configure a local test environment manually. |
| 31 | + |
| 32 | +### 1. Point slic at your code |
| 33 | + |
| 34 | +```bash |
| 35 | +# From a plugins directory (e.g. wp-content/plugins): |
| 36 | +slic here |
| 37 | + |
| 38 | +# Or from a full WordPress root (where wp-config.php lives): |
| 39 | +slic here |
| 40 | +``` |
| 41 | + |
| 42 | +### 2. Select the target project |
| 43 | + |
| 44 | +```bash |
| 45 | +slic use my-plugin |
| 46 | + |
| 47 | +# Subdirectory targets are supported: |
| 48 | +slic use event-tickets/common |
| 49 | +``` |
| 50 | + |
| 51 | +### 3. Initialize (first time only) |
| 52 | + |
| 53 | +```bash |
| 54 | +slic init my-plugin |
| 55 | +``` |
| 56 | + |
| 57 | +This generates three files in the plugin root: |
| 58 | + |
| 59 | +| File | Purpose | |
| 60 | +|------|---------| |
| 61 | +| `.env.testing.slic` | Database credentials, WordPress URL, container paths | |
| 62 | +| `codeception.slic.yml` | Loads `.env.testing.slic` as Codeception params | |
| 63 | +| `test-config.slic.php` | Optional WPLoader custom configuration | |
| 64 | + |
| 65 | +### 4. Run tests |
| 66 | + |
| 67 | +```bash |
| 68 | +slic run # all suites, sequentially |
| 69 | +slic run wpunit # one suite |
| 70 | +slic run tests/wpunit/FooTest.php # one file |
| 71 | +slic run tests/wpunit/FooTest::test_something # one method |
| 72 | +``` |
| 73 | + |
| 74 | +### 5. Interactive shell (optional) |
| 75 | + |
| 76 | +```bash |
| 77 | +slic shell |
| 78 | +# Inside the container: |
| 79 | +> cr wpunit # shorthand for codecept run |
| 80 | +``` |
| 81 | + |
| 82 | +## Test creation rules |
| 83 | + |
| 84 | +When creating or modifying a test file, follow these rules: |
| 85 | + |
| 86 | +1. **Extend `WPTestCase`** — every WPUnit test class extends `\Codeception\TestCase\WPTestCase` (wp-browser v3) or `lucatume\WPBrowser\TestCase\WPTestCase` (wp-browser v4). |
| 87 | +2. **Use the AAA pattern** — Arrange, Act, Assert. Keep each section visually distinct. |
| 88 | +3. **Name clearly** — file: `<DescriptiveName>Test.php`; methods: `test_<what_it_verifies>` (preferred over `@test` annotations). |
| 89 | +4. **Isolate** — every test must pass in any order. Clean up in `tearDown()`. |
| 90 | +5. **Use factories** — prefer `$this->factory()->post->create()` over raw SQL or `wp_insert_post()` in test setup. |
| 91 | +6. **Follow WordPress coding standards** — tabs for indentation, spaces inside parentheses. |
| 92 | + |
| 93 | +See [test-anatomy.md](test-anatomy.md) for the complete file skeleton and naming rules. |
| 94 | + |
| 95 | +## Environment setup tiers |
| 96 | + |
| 97 | +Choose the right level of setUp/tearDown for your test: |
| 98 | + |
| 99 | +| Tier | When to use | Guide | |
| 100 | +|------|------------|-------| |
| 101 | +| Minimal | Tests that only need WordPress loaded | [environment-setup.md](environment-setup.md#tier-1-minimal) | |
| 102 | +| Standard | Tests that create posts, users, or terms | [environment-setup.md](environment-setup.md#tier-2-standard-with-factories) | |
| 103 | +| Full isolation | Tests that mock HTTP, change globals, or modify options | [environment-setup.md](environment-setup.md#tier-3-full-isolation) | |
| 104 | + |
| 105 | +## Testing patterns |
| 106 | + |
| 107 | +| Pattern | Guide | |
| 108 | +|---------|-------| |
| 109 | +| HTTP mocking (3 approaches) | [http-mocking.md](http-mocking.md) | |
| 110 | +| Assertions and WordPress factories | [assertions.md](assertions.md) | |
| 111 | +| REST dispatch, Reflection, custom tables | [advanced-patterns.md](advanced-patterns.md) | |
| 112 | +| Test isolation checklist (11 items) | [test-isolation-checklist.md](test-isolation-checklist.md) | |
| 113 | + |
| 114 | +## Verification workflow |
| 115 | + |
| 116 | +After writing or modifying tests, follow this sequence: |
| 117 | + |
| 118 | +1. **Write the code** under test (or confirm it exists). |
| 119 | +2. **Create or update tests** following the patterns above. |
| 120 | +3. **Run the targeted test** — `slic run tests/wpunit/YourTest.php`. |
| 121 | +4. **Run the full suite** — `slic run wpunit` — to catch side effects. |
| 122 | +5. **Fix any failures** and re-run. |
| 123 | +6. **Verify isolation** — run the single test again to confirm it passes independently. |
| 124 | +7. **Check the [isolation checklist](test-isolation-checklist.md)** before committing. |
| 125 | + |
| 126 | +## Reference material |
| 127 | + |
| 128 | +| Topic | File | |
| 129 | +|-------|------| |
| 130 | +| Complete slic CLI command reference | [references/slic-commands.md](references/slic-commands.md) | |
| 131 | +| Installation, setup, env files, CI | [references/slic-setup.md](references/slic-setup.md) | |
| 132 | +| WPLoader config and WPTestCase API | [references/wp-browser-wploader.md](references/wp-browser-wploader.md) | |
| 133 | + |
| 134 | +## External resources |
| 135 | + |
| 136 | +- [slic repository](https://github.com/stellarwp/slic) |
| 137 | +- [wp-browser documentation](https://wpbrowser.wptestkit.dev/) |
| 138 | +- [Codeception documentation](https://codeception.com/docs/Introduction) |
| 139 | +- [WordPress PHPUnit test utilities](https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/) |
0 commit comments