Download the PHP package fruitcake/phpunit-tia-laravel without Composer

On this page you can find all versions of the php package fruitcake/phpunit-tia-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phpunit-tia-laravel

phpunit-tia for Laravel

Laravel support for phpunit-tia, the test impact analysis extension that skips the PHPUnit tests a change cannot affect.

Line coverage only sees PHP that runs inside <source>. It misses the views a Laravel test renders (Blade runs a compiled copy in storage/) and the migrations of the tables it queries. Without this package, phpunit-tia can skip a test that a view or migration change affects. Or it falls back to a directory guess that reruns far more than needed.

With this package, each test is linked to:

New files no test has used yet are resolved too. A new migration runs the tests that use the tables it changes. A new partial or component runs the tests of the views that use it.

phpunit-tia is an in-between step until PHPUnit ships test impact analysis of its own; see PHPUnit's own test impact analysis.

Requirements

Setup

Four steps cover a regular Laravel app, including Livewire and Inertia.

1. Install the package together with phpunit-tia:

2. Register the extension in phpunit.xml:

3. Add the trait to tests/TestCase.php:

4. Add a phpunit-tia.php next to phpunit.xml, so new files are resolved:

That's it. The first run records a baseline. After that, a run only executes the tests your changes can affect and marks the rest as skipped (S). Locally the baseline lives in ~/.phpunit-tia; to use TIA in CI, persist it between runs as described in phpunit-tia's CI docs.

Useful switches, all from phpunit-tia:

What runs after a change

A changed file that a test is already linked to runs that test. For new files, the resolver answers only when it is sure. Otherwise it leaves the file to phpunit-tia's fallback, which runs the tests linked to other files in the same directory.

Change Runs
A view, component or migration a test used That test
New migration that alters invoices The tests that use invoices
New migration with ->constrained('users') or ->on('users') Also the tests that use users
New migration that only creates a new table Nothing; no test can use that table yet
New migration that alters a table with no earlier migration (such as a package's table) Fallback
New migration it cannot fully read: Schema::connection(), Schema::table($this->table), concatenated SQL, a model, app('db') Fallback
New partial, Blade component or Livewire component The tests of the views, app/ classes and route files that use it, directly or through other views
New view that nothing uses yet Fallback
Any new view, while some view picks one at runtime (@include($name), <x-dynamic-component :component="$name">, @livewire($name)) Fallback
A class with no executable lines (an enum with only cases, an interface, a class with only constants) The tests of the files that name it: through use, its full name (also as a string), or its short name in the same namespace
A new class that nothing names yet Fallback
A class that only runs while the application boots, such as the route registration of a Filament resource The tests that use it after booting
A service provider Every test
A config or route file, bootstrap/app.php, a factory, a seeder, a schema dump, a translation or .env.testing Every test
Any other test code, such as the base TestCase, a trait or a fixture Every test

Everything from setUp() to tearDown() counts, so a request, factory or seeder in setUp() links its views and tables too.

Booting the application is the exception. Every test boots it, and booting registers the routes of every Filament resource and page, so coverage would link each test to each of them, and a change to one resource would run the whole suite. The package leaves the boot out of the coverage and links the service providers it loaded instead.

Customizing

None of this is needed for a regular setup.

Your TestCase already has setUp()

The trait brings its own setUp(). Alias it and call it first:

A test that phpunit-tia skips never gets past that call, but tearDown() still runs. Guard any of your own teardown that needs the application with if (! $this->skippedByTia()).

Your TestCase already has refreshApplication()

The trait brings its own refreshApplication(), which boots the application without its coverage (see What runs after a change). Yours replaces it, so wrap your boot in withoutBootCoverage():

Without it, every test is linked again to each class the boot runs, such as every Filament resource.

You already use RunWithTia

Swap it for RunWithLaravelTia, which includes it. Use RunWithLaravelTia rather than its parts, so that moving to PHPUnit's own test impact analysis does not touch your TestCase.

Migrations outside database/migrations

Recording follows every directory the migrator runs, loadMigrationsFrom() paths included. The resolver treats any file that extends Migration as a migration. It looks for the earlier migrations of its tables in database/migrations and in its own directory. When a module alters a table created elsewhere, pass those paths (globs work):

Choosing what is recorded

Recording is done by four collectors in Fruitcake\PhpUnitTia\Laravel\Collectors: Views, Queries, Livewire and Inertia. Livewire and Inertia do nothing when the package isn't installed. To leave one out or add your own, override usedFileCollectors():

A collector implements Collector. register() runs once per test with that test's application; add each file the test uses to $files, as an absolute or project-relative path:

Return the same collector instances every time, as above, so a collector can keep what it reads between tests.

Files of your own that every test depends on

Coverage doesn't see files outside <source>, so no test is linked to them. ApplicationResolver runs every test for the ones every Laravel app has (ApplicationResolver::PATHS), and for test code that is not a test itself: any other file in the test suite directories of your phpunit.xml or the autoload-dev paths of your composer.json, such as tests/TestCase.php beside tests/Unit and tests/Feature. Add paths of your own, such as a script that tests run:

Choosing how new files are resolved

LaravelResolver combines ApplicationResolver, MigrationResolver, ViewResolver and ClassResolver from Fruitcake\PhpUnitTia\Laravel\Resolvers, in that order. Register them separately to leave one out or to put a resolver of your own between them. Each implements phpunit-tia's EdgeAwareResolver:

A resolver returns the test files a changed path affects, an empty list when it affects none, or null to leave the path to the next resolver.

PHPUnit's own test impact analysis

phpunit-tia is an in-between step. sebastianbergmann/phpunit#6919 adds test impact analysis to PHPUnit itself, and this package will move to it once that is released. What changes for an app:

Caveats

Testing

The end-to-end tests run the fixture app in tests/Fixtures/app with the real extension, so they need pcov or Xdebug. Without a coverage driver they are skipped.

License

MIT


All versions of phpunit-tia-laravel with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
illuminate/contracts Version ^13.0
illuminate/support Version ^13.0
jasonmccreary/phpunit-tia Version ^0.5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package fruitcake/phpunit-tia-laravel contains the following files

Loading the files please wait ...