coders-tm/laravel-core / .agents/skills/testbench-docs
testbench-package-testing
VerifiedDevelops and tests Laravel packages using Orchestra Testbench. Activates when writing package tests, configuring testbench.yaml, managing migrations, defining routes/environment for tests, using Testbench Dusk for browser tests, or working with Workbench for package preview.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.2 KB |
| api-examples.md | markdown | 907 B |
| getting-started.md | markdown | 3.2 KB |
| getting-started/configuration.md | markdown | 5.2 KB |
| markdown-examples.md | markdown | 1.0 KB |
| testbench-dusk.md | markdown | 3.3 KB |
| testbench-dusk/the-basic.md | markdown | 3.3 KB |
| testbench-dusk/troubleshooting.md | markdown | 1.7 KB |
| testbench.md | markdown | 2.7 KB |
| testbench/cli.md | markdown | 1.9 KB |
| testbench/integrations.md | markdown | 2.0 KB |
| testbench/the-basic.md | markdown | 6.4 KB |
| testbench/the-basic/databases.md | markdown | 5.0 KB |
| testbench/the-basic/environment.md | markdown | 4.9 KB |
| testbench/the-basic/routes.md | markdown | 2.3 KB |
| testbench/troubleshooting.md | markdown | 3.5 KB |
| workbench.md | markdown | 1.2 KB |
testbench/troubleshooting.md
View on GitHub---
next: false
---
# Troubleshooting
[[toc]]
## No supported encrypter found. The cipher and / or key length are invalid.
RuntimeException: No supported encrypter found. The cipher and / or key length are invalid.
This error would only occur if your test suite requires the encrypter. To solve this you can add a dummy `APP_KEY` or use a specific key to your application/package `phpunit.xml`.
```xml
<phpunit>
// ...
<php>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/> # [!code ++] # [!code focus]
</php>
</phpunit>
```
## Why Testbench doesn't include any of the `App` classes.
The reason Testbench remove all the classes is to make sure that you would never depend on it when developing Laravel Packages. Classes such as `App\Http\Controllers\Controller` and `App\User` are simple to be added but the problem with these classes is that they can be either:
* Removed, moved to another location such as `App\Models\User`, or
* Renamed using `php artisan app:name Acme` which would rename `App\User` to `Acme\User`.
## Class `GuzzleHttp\Client` not found
If you plan to use the new **HTTP Client** in Laravel 7, you need to include `guzzlehttp/guzzle` to your package's `composer.json`:
```bash
composer require "guzzlehttp/guzzle"
```
::: warning
We can't guarantee that any requirements in `laravel/laravel` will always be maintained as it is. A developer may remove any of the optional requirements such as `guzzlehttp/guzzle`, `fideloper/proxy`, `fruitcake/laravel-cors` or `laravel/tinker`.
:::
## Class `Illuminate\Database\Eloquent\Factory` not found
Starting from Laravel 8, `Illuminate\Database\Eloquent\Factory` has been pushed to `laravel/legacy-factories` package in favor of class based Factories.
As package developers, you have the option to either split the package version for Laravel 8 from the previous Laravel version and use the new class-based Factories or require `laravel/legacy-factories` to make a release while supporting lower versions as well. In both cases, the packages will need to require PHP 7.3 and above.
::: tip
The minimum PHP requirements are due to `laravel/legacy-factories` depending on `illuminate/macroable`.
:::
In order to use legacy factories on packages development supporting Laravel 8 and below without splitting the release you can opt to use the following:
```bash
composer require --dev "laravel/legacy-factories:^1.0.4"
```
Next, you need to ensure `orchestra/testbench` uses the minimum version supporting `laravel/legacy-factories` to avoid issues on the CI environment (if you're running tests on each version of Laravel or using `--prefer-lowest`).
| Laravel | Minimum Versions
|:--------|:---------------
| 5.5 | `3.5.6`
| 5.6 | `3.6.7`
| 5.7 | `3.7.8`
| 5.8 | `3.8.6`
| 6.x | `4.8.0`
| 7.x | `5.2.0`
E.g: If you need to support minimum Laravel 5.6 here how the requirement should look like in `composer.json`:
```json
{
"require-dev": {
"orchestra/testbench": "~3.6.7 || ~3.7.8 || ~3.8.6 || ^4.8 || ^5.2 || ^6.0"
}
}
```
### Converted to new class based factories but still facing this error
You need to check all your TestCase and ensure that there is no call to `$this->withFactories()`, autoloading class-based factories are handled by Composer, and `withFactories()` is only needed for legacy-based factories.
## Missing Browser Kit support after testing on Laravel 5.4
Replace `orchestra/testbench` with `orchestra/testbench-browser-kit` and follow [the installation guide](https://github.com/orchestral/testbench-browser-kit#installation).
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |