Download the PHP package dave-liddament/phpstan-rule-test-helper without Composer

On this page you can find all versions of the php package dave-liddament/phpstan-rule-test-helper. 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 phpstan-rule-test-helper

PHPStan rule testing helper

This library offers a couple of improvements to PHPStan's custom rule test harness.

This library provides AbstractRuleTestCase, which extends PHPStan's RuleTestCase.

It offers a simpler way to write tests for custom rules. Specifically:

  1. No need to specify line numbers in the test code.
  2. You can specify the expected error message once.

Improvement 1: No more line numbers in tests

The minimal test case specifies the Rule being tested and at least one test. Each test must call the assertIssuesReported method, which takes the path of one or more fixture files.

Test code:

The fixture file contains the expected error message.

Fixture:

Every line that contains // ERROR is considered an issue that should be picked up by the rule. The text after // ERROR is the expected error message.

With this approach you don't need to work out the line number of the error. This is particularly handy when you update the Fixture file, you no longer have to update all the line numbers in the test.

Improvement 2: Specify the expected error message once

Often you end up writing the same error message for every violation. To get round this use the getErrorFromatter method to specify the error message.

Test code:

The fixture file is simplified as there is no need to specify the error message. Any lines where an error is expected need to end with // ERROR, the expected error message is taken from the getErrorFormatter method.

Fixture:

The expected error messages would be:

The benefits of this approach are no duplication of the error message text. Any changes to the error message only need to be made in one place in the test case.

Adding context to error messages

Good error message require context. The context is added to the fixture file after // ERROR. Multiple pieces of context can be added by separating them with the | character.

Test code:

Fixture:

The expected error messages would be:

More flexible error messages

If you need more flexibility in the error message, you can return an object that implements the ErrorMessageFormatter interface.

In the example below the message changes depending on the number of parts in the error context.

NOTE: This is a contrived example, but it shows how you can use ErrorMessageFormatter to create more flexible error messages.

Fixture:

The expected error messages would be:

Installation


All versions of phpstan-rule-test-helper with dependencies

PHP Build Version
Package Version
Requires php Version ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0
phpstan/phpstan Version ^1.6
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 dave-liddament/phpstan-rule-test-helper contains the following files

Loading the files please wait ....