# Add Missing Tests to Every Pull Request in a Laravel App

An agent finds what a Laravel pull request leaves untested in koel's API controllers, writes PHPUnit feature tests, runs them, and reviews with a patch.

[Run this on Rush](https://cloud.getrush.ai/run/test-every-pull-request/laravel/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the diff and, for each changed action in a controller such as `app/Http/Controllers/API/PlaylistController.php` or `PlaylistSongController.php`, works out the request and the user that reach the new code, then looks in `tests/Feature/` for a test that makes that request.

It writes the missing ones into the matching file, `tests/Feature/PlaylistTest.php` or `SongTest.php`, in the style there: `#[Test]` methods, `create_user` and `create_playlist` from `tests/Helpers.php`, `getAs` and `postAs` as that user, and `PlaylistResource::JSON_STRUCTURE` for the response shape. `phpunit.xml.dist` runs the suites on in-memory SQLite, so `php artisan test --compact` needs no database server. Each behavior gets its failure path too: a collaborator who is not the owner, or a private song another user asks for.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Review this pull request for untested behavior. Check it out and read its diff against the base branch. List each new or changed behavior in app/Http/Controllers/API (the song and playlist controllers), their form requests and the services they call that no existing test covers. Write PHPUnit feature tests for each in the matching file under tests/Feature (PlaylistTest.php, PlaylistSongTest.php, SongTest.php and so on), in the existing style: #[Test] methods, create_user and create_playlist from tests/Helpers.php, model factories, getAs and postAs, and the resource JSON_STRUCTURE constants. Cover failure paths as well as the happy path. Run php artisan test --compact on the files you changed, then the feature suite, until the new tests pass. Do not change application code: if a test fails because the code is wrong, keep it out of the patch and describe the failure. Do not push commits, commit to the branch or open a pull request. Post one review on the pull request that lists each untested behavior with file and line, each test you wrote, the php artisan test results for those files and the feature suite, and the new tests as one patch. If this run names no pull request, in resources or after this prompt, stop and say so.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app/pull/123"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

One review on the pull request: each untested behavior with the controller file and line, the `#[Test]` methods that cover it, and the `php artisan test` result for the touched files and for the `feature` suite. The patch changes only files under `tests/`, nothing in `app/`, `routes/` or `database/`. No commit reaches the branch.

A reviewer decides whether to apply the patch, and whether an authorization test the agent left out, such as a non-owner allowed to change a playlist, points at a real bug in the controller.

## Run it on every pull request opened against master

Save this request as an automation's prompt with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` and `branch_patterns` `master`, koel's default branch. Owners, members and collaborators fire it; a contributor's pull request from a fork never does. The event names the pull request's URL, author and base branch but not its commits, so the agent reads the head SHA from that URL before it diffs the controllers.

## Why run it on Rush?

koel's `AGENTS.md` says every change must be programmatically tested and that most tests should be feature tests. This review holds a pull request to that rule at the endpoint: it names the controller line no request in `tests/Feature/` reaches, and hands over the test that reaches it, already passing on SQLite.

## Frequently asked questions

### Why a patch in a review rather than a commit?

The review recipe never pushes, so a contributor's branch changes only when they choose. `git apply` takes the patch as it is, and the review shows which `artisan test` command proved it.

### Will it write Pest tests?

Not in koel. Its `AGENTS.md` says to convert any Pest test to PHPUnit, so the agent writes PHPUnit classes with `#[Test]` methods.

## More Laravel jobs

- [Upgrade Laravel Dependencies Every Week](https://getrush.ai/run/upgrade-dependencies-weekly/laravel/)
- [Upgrade Laravel 11 to Laravel 13](https://getrush.ai/run/upgrade-framework-major/laravel/)
- [Write Playwright Tests for a Laravel App](https://getrush.ai/run/write-playwright-tests/laravel/)

## The same job on other stacks

- [Add Missing Tests to Every Pull Request in a NestJS API](https://getrush.ai/run/test-every-pull-request/nestjs/)
- [Add Missing Tests to Every Pull Request in a Next.js App](https://getrush.ai/run/test-every-pull-request/nextjs/)
- [Add Missing Tests to Every Pull Request in a Nuxt App](https://getrush.ai/run/test-every-pull-request/nuxt/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
