mirror of
https://github.com/pestphp/pest.git
synced 2026-04-21 06:27:28 +02:00
82 lines
3.1 KiB
PHP
82 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pest\Plugins\Tia\WatchDefaults;
|
|
|
|
use Composer\InstalledVersions;
|
|
|
|
/**
|
|
* Watch patterns for Laravel projects.
|
|
*
|
|
* Laravel boots the entire application inside `setUp()` (before PHPUnit's
|
|
* `Prepared` event where TIA's coverage window opens). That means PHP files
|
|
* loaded during boot — config, routes, service providers, migrations — are
|
|
* invisible to the coverage driver. Watch patterns are the only way to
|
|
* track them.
|
|
*
|
|
* @internal
|
|
*/
|
|
final readonly class Laravel implements WatchDefault
|
|
{
|
|
public function applicable(): bool
|
|
{
|
|
return class_exists(InstalledVersions::class)
|
|
&& InstalledVersions::isInstalled('laravel/framework');
|
|
}
|
|
|
|
public function defaults(string $projectRoot, string $testPath): array
|
|
{
|
|
$featurePath = is_dir($projectRoot.DIRECTORY_SEPARATOR.$testPath.'/Feature')
|
|
? $testPath.'/Feature'
|
|
: $testPath;
|
|
|
|
return [
|
|
// Config — loaded during app boot (setUp), invisible to coverage.
|
|
// Affects both Feature and Unit: Pest.php commonly binds fakes
|
|
// and seeds DB based on config values.
|
|
'config/*.php' => [$testPath],
|
|
'config/**/*.php' => [$testPath],
|
|
|
|
// Routes — loaded during boot. HTTP/Feature tests depend on them.
|
|
'routes/*.php' => [$featurePath],
|
|
'routes/**/*.php' => [$featurePath],
|
|
|
|
// Service providers / bootstrap — loaded during boot, affect
|
|
// bindings, middleware, event listeners, scheduled tasks.
|
|
'bootstrap/app.php' => [$testPath],
|
|
'bootstrap/providers.php' => [$testPath],
|
|
|
|
// Migrations — run via RefreshDatabase/FastRefreshDatabase in
|
|
// setUp. Schema changes can break any test that touches DB.
|
|
'database/migrations/**/*.php' => [$testPath],
|
|
|
|
// Seeders — often run globally via Pest.php beforeEach.
|
|
'database/seeders/**/*.php' => [$testPath],
|
|
|
|
// Factories — loaded lazily but still PHP that coverage may miss
|
|
// if the factory file was already autoloaded before Prepared.
|
|
'database/factories/**/*.php' => [$testPath],
|
|
|
|
// Blade templates — compiled to cache, source file not executed.
|
|
'resources/views/**/*.blade.php' => [$featurePath],
|
|
|
|
// Translations — JSON translations read via file_get_contents,
|
|
// PHP translations loaded via include (but during boot).
|
|
'lang/**/*.php' => [$featurePath],
|
|
'lang/**/*.json' => [$featurePath],
|
|
'resources/lang/**/*.php' => [$featurePath],
|
|
'resources/lang/**/*.json' => [$featurePath],
|
|
|
|
// Build tool config — affects compiled assets consumed by
|
|
// browser and Inertia tests.
|
|
'vite.config.js' => [$featurePath],
|
|
'vite.config.ts' => [$featurePath],
|
|
'webpack.mix.js' => [$featurePath],
|
|
'tailwind.config.js' => [$featurePath],
|
|
'tailwind.config.ts' => [$featurePath],
|
|
'postcss.config.js' => [$featurePath],
|
|
];
|
|
}
|
|
}
|