PHP code example of fruitcake / phpunit-tia-laravel

1. Go to this page and download the library: Download fruitcake/phpunit-tia-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fruitcake / phpunit-tia-laravel example snippets


namespace Tests;

use Fruitcake\PhpUnitTia\Laravel\RunWithLaravelTia;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use RunWithLaravelTia;
}



return [
    'resolvers' => [
        Fruitcake\PhpUnitTia\Laravel\LaravelResolver::class,
    ],
];

abstract class TestCase extends BaseTestCase
{
    use RunWithLaravelTia {
        RunWithLaravelTia::setUp as tiaSetUp;
    }

    protected function setUp(): void
    {
        $this->tiaSetUp();

        // ...
    }
}

abstract class TestCase extends BaseTestCase
{
    use RunWithLaravelTia;

    protected function refreshApplication(): void
    {
        $this->withoutBootCoverage(function (): void {
            $this->app = $this->createApplication();

            // ...
        });
    }
}

return [
    'resolvers' => [
        new Fruitcake\PhpUnitTia\Laravel\LaravelResolver(
            migrationPaths: ['database/migrations', 'modules/*/database/migrations'],
        ),
    ],
];

use Fruitcake\PhpUnitTia\Laravel\Recorder;

abstract class TestCase extends BaseTestCase
{
    use RunWithLaravelTia;

    private static ?array $collectors = null;

    protected function usedFileCollectors(): array
    {
        return self::$collectors ??= [...Recorder::defaultCollectors(), new FixtureFiles];
    }
}

use Fruitcake\PhpUnitTia\Laravel\Collectors\Collector;
use Fruitcake\PhpUnitTia\Laravel\UsedFiles;
use Illuminate\Contracts\Foundation\Application;

final class FixtureFiles implements Collector
{
    public function register(Application $app, UsedFiles $files): void
    {
        $app->make('events')->listen(FixtureLoaded::class, fn (FixtureLoaded $event) => $files->add($event->path));
    }
}

use Fruitcake\PhpUnitTia\Laravel\LaravelResolver;
use Fruitcake\PhpUnitTia\Laravel\Resolvers\ApplicationResolver;

return [
    'resolvers' => [
        new LaravelResolver(applicationPaths: [...ApplicationResolver::PATHS, 'scripts/*']),
    ],
];

use Fruitcake\PhpUnitTia\Laravel\Resolvers\ApplicationResolver;
use Fruitcake\PhpUnitTia\Laravel\Resolvers\ClassResolver;
use Fruitcake\PhpUnitTia\Laravel\Resolvers\MigrationResolver;
use Fruitcake\PhpUnitTia\Laravel\Resolvers\ViewResolver;

return [
    'resolvers' => [
        ApplicationResolver::class,
        new MigrationResolver(['database/migrations', 'modules/*/database/migrations']),
        App\Testing\TranslationResolver::class,
        ViewResolver::class,
        ClassResolver::class,
    ],
];
shell
PHPUNIT_TIA=0 php artisan test        # run everything, ignore TIA
PHPUNIT_TIA_FRESH=1 php artisan test  # rebuild the baseline
PHPUNIT_TIA_DEBUG=1 php artisan test  # explain why each test ran