Download the PHP package alexskrypnyk/phpunit-helpers without Composer

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

Helpers to work with PHPUnit

[![GitHub Issues](https://img.shields.io/github/issues/AlexSkrypnyk/phpunit-helpers.svg)](https://github.com/AlexSkrypnyk/phpunit-helpers/issues) [![GitHub Pull Requests](https://img.shields.io/github/issues-pr/AlexSkrypnyk/phpunit-helpers.svg)](https://github.com/AlexSkrypnyk/phpunit-helpers/pulls) [![Test PHP](https://github.com/AlexSkrypnyk/phpunit-helpers/actions/workflows/test-php.yml/badge.svg)](https://github.com/AlexSkrypnyk/phpunit-helpers/actions/workflows/test-php.yml) [![codecov](https://codecov.io/gh/AlexSkrypnyk/phpunit-helpers/graph/badge.svg?token=7WEB1IXBYT)](https://codecov.io/gh/AlexSkrypnyk/phpunit-helpers) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/AlexSkrypnyk/phpunit-helpers) ![LICENSE](https://img.shields.io/github/license/AlexSkrypnyk/phpunit-helpers) ![Renovate](https://img.shields.io/badge/renovate-enabled-green?logo=renovatebot)

🧩 Features

Name Source Description
UnitTestCase src Base test class that includes essential traits for PHPUnit testing
AssertArrayTrait src Custom assertions for arrays
ApplicationTrait src Test Symfony Console applications with assertions
EnvTrait src Manage environment variables during tests
LocationsTrait src Manage file system locations and directories for tests
ProcessTrait src Run and assert on command line processes during tests
SerializableClosureTrait src Make closures serializable for use in data providers
ReflectionTrait src Access protected and private methods and properties
TuiTrait src Interact with and test Textual User Interfaces
StringTrait src String assertions with exact and substring matching
LoggerTrait src Hierarchical logging with step tracking for test debugging

📋 Requirements

Two traits need a package that this library does not require itself, so add it to your own project when you use them:

Trait Additional package
ApplicationTrait symfony/console
SerializableClosureTrait laravel/serializable-closure

📦 Installation

composer require --dev alexskrypnyk/phpunit-helpers

🚀 Usage

This package provides a collection of traits that can be used in your PHPUnit tests to make testing easier. Below is a description of each trait and how to use it.

UnitTestCase

The UnitTestCase class is the base class for unit tests. It includes the ReflectionTrait and LocationsTrait to provide useful methods for testing.

setUp() initialises the test locations and tearDown() removes the workspace directory again. The workspace is kept when the test failed or errored, or when debug mode is on, so the produced files can be inspected.

The class also provides an info() method that collects additional information about the test from methods whose name ends with Info. Methods containing test in their name are excluded to avoid conflicts with test methods. The collected information is also appended to the message of any failing assertion, so a failure report carries the test's context without any extra call. Appending relies on a hook that PHPUnit added in 12.5.24; on earlier versions info() still works but failure messages are left untouched.

Debug mode is enabled by the DEBUG environment variable or the --debug argument, and is readable with UnitTestCase::isDebug():

DEBUG=1 vendor/bin/phpunit

AssertArrayTrait

The AssertArrayTrait provides custom assertions for arrays.

ApplicationTrait

The ApplicationTrait provides methods to test Symfony Console applications and their commands with comprehensive assertions.

EnvTrait

The EnvTrait helps manage environment variables during tests. Every method is static, so it is also usable from data providers.

LocationsTrait

The LocationsTrait provides methods to manage file system locations during tests. It maintains a set of predefined directories as static properties, so they are also reachable from data providers.

ProcessTrait

The ProcessTrait provides methods to run command line processes and assert on their output and exit codes. It integrates with the Symfony Process component for safe and controlled command execution.

SerializableClosureTrait

The SerializableClosureTrait makes closures serializable so they can be used in data providers. It works with both traditional closures and arrow functions, and requires the laravel/serializable-closure package.

ReflectionTrait

The ReflectionTrait provides methods to access and manipulate protected or private members of classes or objects.

TuiTrait

The TuiTrait provides constants and methods for interacting with a Textual User Interface (TUI) during tests, handling keystroke simulation and input entries. It supports both full-string input and character-by-character input simulation.

A "keystroke" is a single key or special key, while an "entry" is one or more keystrokes forming a complete input.

StringTrait

The StringTrait provides the assertStringContainsOrNot() assertion used by the ApplicationTrait and ProcessTrait prefix assertions. Four single-character prefixes control how each expected value is matched:

Prefix Meaning Compared against
+ Exact match present The entire haystack
* Substring present Any position
- Exact match absent The entire haystack
! Substring absent Any position

+ and - compare the value against the whole haystack, not against a word inside it, so they are only useful for short, single-line strings.

There are two modes. In shortcut mode no value carries a prefix and all of them are treated as "substring present". In mixed mode at least one value carries a prefix, and then every value must carry one.

All four prefixes must be single, unique characters, and a value that is empty after its prefix is stripped raises a RuntimeException.

LoggerTrait

The LoggerTrait provides a hierarchical logging system for test debugging, with step tracking, timing and nested workflows. Output is written to STDERR and is suppressed unless verbose mode is enabled, so the default test output stays clean.

Available logging methods:

Example step summary output:

Using multiple traits

Traits can be combined in a single test class:

Or extend UnitTestCase, which already includes the LocationsTrait and ReflectionTrait:

Every trait declares @mixin \PHPUnit\Framework\TestCase, so it must be used inside a PHPUnit test class.

🤝 Contributing

See CONTRIBUTING.md for local development setup and the linting and testing commands.

🔄 Updating

To pull the latest infrastructure from the template into this project, ask Claude Code to "update scaffold" - see AGENTS.md for details.


This repository was created using the Scaffold project template


All versions of phpunit-helpers with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
phpunit/phpunit Version ^11.4 || ^12 || ^13
symfony/filesystem Version ^6.4 || ^7.2 || ^8.0
symfony/finder Version ^6.4 || ^7.2 || ^8.0
symfony/process Version ^6.4 || ^7.2 || ^8.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 alexskrypnyk/phpunit-helpers contains the following files

Loading the files please wait ...