Download the PHP package zenstruck/assert without Composer

On this page you can find all versions of the php package zenstruck/assert. 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 assert

zenstruck/assert

CI Status Code Coverage

This library allows dependency-free test assertions. When using a PHPUnit-based test library (PHPUnit itself, Pest, Codeception), failed assertions are automatically converted to PHPUnit failures and successful assertions are added to PHPUnit's successful assertion count.

This library differs from other popular assertion libraries (webmozart/assert & beberlei/assert) in that it is purely for test assertions opposed to what these libraries provide: type safety assertions.

With the exception of the Expectation API (specifically, the Throws Expectation which provides a nice API for making exception assertions), this library is really only useful for 3rd party libraries that would like to provide test assertions but not have a direct dependency on a specific test library.

Installation

Zenstruck\Assert

This is the main entry point for making assertions. When the methods on this class are called, they throw a Zenstruck\Assert\AssertionFailed on failure. If they do not throw this exception, they are considered successful.

When using a PHPUnit-based framework, failed assertions are auto-converted to PHPUnit test failures and successful assertions are added to PHPUnit's successful assertion count.

True/False Assertions

Generic Fail/Pass

Try

Attempt to run a callback and return the result. If an exception is thrown while running, a fail is triggered. If run successfully, a pass is triggered.

Run Assertions

Assert::run() executes a callable. A successful execution is considered a pass and if Zenstruck\Assert\AssertionFailed is thrown, it is a fail.

Expectation API

While the above assertions can be used to create any assertion, a simple, fluent, readable, expectation API is provided. This API is heavily inspired by Pest PHP.

Type Expectations

Throws Expectation

This expectation provides a nice API for exceptions. It is an alternative to PHPUnit's expectException() which has the following limitations:

  1. Can only assert 1 exception is thrown per test.
  2. Cannot make assertions on the exception itself (other than the message).
  3. Cannot make post-exception assertions (think side effects).

Fluent Expectations

AssertionFailed Exception

When triggering a failed assertion, it is important to provide a useful failure message to the user. The AssertionFailed exception has some features to help.

NOTES:

  1. When the message is constructed with context, non-scalar values are run through get_debug_type() and strings longer than 100 characters are trimmed. The full context is available via AssertionFailed::context().
  2. When using with PHPUnit, the full context is exported with the failure message if in verbose-mode (--verbose|-v).

Assertion Objects

Since Zenstruck\Assert::run() accepts any callable, complex assertions can be wrapped up into invokable objects:

Negatable Assertion Objects

Zenstruck\Assert has a not() method that can be used with Negatable Assertion Objects. This can be helpful to create custom assertions that can be easily negated. Let's convert the example above into a Negatable Assertion Object:


All versions of assert with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
symfony/polyfill-php81 Version ^1.23
symfony/var-exporter Version ^5.4|^6.0|^7.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 zenstruck/assert contains the following files

Loading the files please wait ....