Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .ai/guidelines/pest/core.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## Pest

### Testing
- If you need to verify a feature is working, write or update a Unit / Feature test.

### Pest Tests
- All tests must be written using Pest. Use `php artisan make:test --pest <name>`.
- You must not remove any tests or test files from the tests directory without approval. These are not temporary or helper files - these are core to the application.
- Tests should test all of the happy paths, failure paths, and weird paths.
- Tests live in the `tests/Feature` and `tests/Unit` directories.
- Pest tests look and behave like this:
<code-snippet name="Basic Pest Test Example" lang="php">
it('is true', function () {
expect(true)->toBeTrue();
});
</code-snippet>

### Running Tests

After you have made all changes to the code, be sure to perform the following steps in the order shown:

1. Delete the file `vendor/orchestra/testbench-core/laravel/storage/logs/laravel.log`.
2. Run the console command `php vendor/bin/pest`.
3. Run the console command `composer style:snippets`.
4. Run the console command `composer reset:snippets`.

If the tests fail, carefully review the output log as well as the contents of the created file `vendor/orchestra/testbench-core/laravel/storage/logs/laravel.log`.

Once you understand the problem, fix it.
- Run the minimal number of tests using an appropriate filter before finalizing code edits.
- To run all tests: `php vendor/bin/pest`.
- To run all tests in a file: `php vendor/bin/pest tests/Feature/ExampleTest.php`.
- To filter on a particular test name: `php vendor/bin/pest --filter=testName` (recommended after making a change to a related file).
- When the tests relating to your changes are passing, ask the user if they would like to run the entire test suite to ensure everything is still passing.

### Pest Assertions
- When asserting status codes on a response, use the specific method like `assertForbidden` and `assertNotFound` instead of using `assertStatus(403)` or similar, e.g.:
<code-snippet name="Pest Example Asserting postJson Response" lang="php">
it('returns all', function () {
$response = $this->postJson('/api/docs', []);

$response->assertSuccessful();
});
</code-snippet>

### Mocking
- Mocking can be very helpful when appropriate.
- When mocking, you can use the `Pest\Laravel\mock` Pest function, but always import it via `use function Pest\Laravel\mock;` before using it. Alternatively, you can use `$this->mock()` if existing tests do.
- You can also create partial mocks using the same import or self method.

### Datasets
- Use datasets in Pest to simplify tests which have a lot of duplicated data. This is often the case when testing validation rules, so consider going with this solution when writing tests for validation rules.

<code-snippet name="Pest Dataset Example" lang="php">
it('has emails', function (string $email) {
expect($email)->not->toBeEmpty();
})->with([
'james' => 'james@laravel.com',
'taylor' => 'taylor@laravel.com',
]);
</code-snippet>
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
* text=auto

.ai/ export-ignore
.junie/ export-ignore

docs/ export-ignore

.github/ export-ignore
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
.idea/
.cursor/
.vscode/

!.junie/guidelines.md
.junie/

_site/
build/
node_modules/
Expand Down
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"require-dev": {
"dragon-code/codestyler": "^6.3",
"dragon-code/laravel-deploy-operations": "^7.1",
"laravel/boost": "^1.1",
"mockery/mockery": "^1.6",
"orchestra/testbench": "^9.0 || ^10.0",
"pestphp/pest": "^3.0 || ^4.0",
Expand Down Expand Up @@ -60,14 +61,16 @@
},
"scripts": {
"post-update-cmd": [
"vendor/bin/codestyle pint 8.2 --ansi",
"vendor/bin/codestyle editorconfig --ansi",
"composer normalize --ansi"
"@php vendor/bin/codestyle pint 8.2 --ansi",
"@php vendor/bin/codestyle editorconfig --ansi",
"composer normalize --ansi",
"@ai"
],
"post-autoload-dump": [
"@clear",
"@prepare"
],
"ai": "@php vendor/bin/testbench boost:guidelines -n",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"migrate": "@php vendor/bin/testbench migrate:fresh --seed --ansi",
Expand Down
3 changes: 2 additions & 1 deletion testbench.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ laravel: '@testbench'

providers:
- Workbench\App\Providers\WorkbenchServiceProvider
- Workbench\App\Providers\BoostServiceProvider
- DragonCode\LaravelFeed\LaravelFeedServiceProvider
- Spatie\LaravelData\LaravelDataServiceProvider
- DragonCode\LaravelDeployOperations\ServiceProvider
Expand All @@ -16,7 +17,7 @@ workbench:
web: true
api: false
config: true
commands: false
commands: true
factories: true
views: false
build:
Expand Down
12 changes: 12 additions & 0 deletions workbench/app/Boost/GuidelineComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Workbench\App\Boost;

use Laravel\Boost\Install\GuidelineComposer as BaseComposer;

class GuidelineComposer extends BaseComposer
{
protected string $userGuidelineDir = '/../../../../.ai/guidelines';
}
Loading