Download the PHP package savage-days/phpunit-case-coverage without Composer

On this page you can find all versions of the php package savage-days/phpunit-case-coverage. 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-case-coverage

PHPUnit Case Coverage

PHPUnit Case Coverage is an opt-in extension that makes meaningful, developer-declared outcomes of a dependency visible in consumer tests.

PHPUnit remains responsible for correctness: assertions and mock expectations still prove the behaviour of the system under test. Case Coverage answers a complementary question: which declared dependency outcomes has this consumer scope exercised?

It is deliberately test-layer only. Production classes do not receive attributes, interfaces, or other metadata from this package.

Requirements

Installation

Install from a published repository:

Register the extension in the consuming project's phpunit.xml:

For PHPUnit 9.6, use its legacy listener configuration instead; the event extension API used by PHPUnit 10/11 does not exist in PHPUnit 9:

Define cases

A CaseSet is a test-side catalogue for one target class or interface. Every public static method returning CaseDefinition declares exactly one outcome for exactly one target method.

Supported outcomes are deliberately small:

completes() is valid only for a target method declared with void. Case definitions are validated when the catalogue is used: the target type and target method must exist.

Apply one case

Use case() in an ordinary PHPUnit test. A case becomes covered only when apply() runs; merely creating a case does not affect the report.

apply() checks that the PHPUnit double implements or extends the CaseSet target, configures the declared return/throw outcome, and records coverage. It does not configure call counts, arguments, or expectations; keep those as normal PHPUnit mock setup:

Run a group without a provider method in the test class

Groups collect semantically equivalent cases. Declare membership with #[Group], then expose one public static provider method on the CaseSet. PHPUnit's DataProviderExternal keeps the test method focused on the test itself:

PHPUnit invokes PaymentClientCases::temporaryFailures(), which delegates to forGroup('temporaryFailures'). The resulting datasets are named after their cases, for example timeout and connectionError.

When a new case is added to temporaryFailures, this test automatically gains a new PHPUnit dataset. DataProviderExternal requires a real public static method, so that small provider method is necessary; it belongs beside the group, not in every test class.

For a one-case data provider, use CaseSet::forCase('approved'). Most one-case tests are simpler with CaseSet::case('approved')->apply($double).

PHPUnit 9.6 does not support DataProviderExternal attributes. It supports the same external static provider with its legacy annotation:

Coverage semantics

Coverage is aggregated by PHPUnit test class. It begins only when apply() is called.

Once any case for a target method is applied, all declared cases of that same target method become the denominator for that test class. Cases for other methods in the same CaseSet are not shown unless one of their cases is applied.

For example, if a UserCases catalogue declares four outcomes for User::getIdentity() and a UserTest applies only exception and id, the report is:

This is behavioural coverage of the declared space, not proof that the catalogue contains every possible real-world outcome.

Run the report

Normal PHPUnit execution is unchanged and produces no Case Coverage output:

Use the package wrapper and --case-coverage to request the report:

All other arguments are forwarded to PHPUnit:

The wrapper is necessary because PHPUnit parses command-line options before extensions load; an integration cannot directly add a new native vendor/bin/phpunit option. It enables the PHPUnit 9 listener and PHPUnit 10/11 extension alike.

What the package does not do

The package stays intentionally small: cases declare what a dependency produces; PHPUnit tests declare how the consumer uses it.


All versions of phpunit-case-coverage with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
phpunit/phpunit Version ^9.6 || ^10.5 || ^11.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 savage-days/phpunit-case-coverage contains the following files

Loading the files please wait ...