PHPackages                             raptor/test-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. raptor/test-utils

ActiveLibrary[Testing &amp; Quality](/categories/testing)

raptor/test-utils
=================

Testing utils for PHP

v1.5.1-stable(6y ago)01121[1 PRs](https://github.com/raptor-mvk/test-utils/pulls)1MITPHPPHP &gt;=7.3.0

Since Sep 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/raptor-mvk/test-utils)[ Packagist](https://packagist.org/packages/raptor/test-utils)[ RSS](/packages/raptor-test-utils/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (9)Versions (4)Used By (1)

Raptor Test Utils
=================

[](#raptor-test-utils)

[![Build Status](https://camo.githubusercontent.com/c0ff7e92605fa11991ab5ab784ceba821165d686da364cc9c43c0af262a47fff/68747470733a2f2f7472617669732d63692e6f72672f726170746f722d6d766b2f746573742d7574696c732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/raptor-mvk/test-utils)[![Code Coverage](https://camo.githubusercontent.com/d204be33a7ec40be4c0564f7cdf6584ccf3673b1f3bfa75695ee10e5be739c40/68747470733a2f2f636f6465636f762e696f2f67682f726170746f722d6d766b2f746573742d7574696c732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/raptor-mvk/test-utils)[![Codacy Badge](https://camo.githubusercontent.com/bcfea3df85b722f778a2ce571104784cac407a543f9c6dc78c55f00fc5baae71/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6661643632333139623661663439326238373166313138636464656636343031)](https://www.codacy.com/app/raptor-mvk/test-utils)[![Latest Stable Version](https://camo.githubusercontent.com/a6424bffd04d800782df5965824459dae7b4b45ec1c9a33c04ebc366591b41b2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f726170746f722d6d766b2f746573742d7574696c732e737667)](https://github.com/raptor-mvk/test-utils/releases/latest)[![License](https://camo.githubusercontent.com/49886207c36bc973e2bb5b438256d397804ec4cd6d0d8a117c3920b425884c3f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f726170746f722d6d766b2f746573742d7574696c732e737667)](https://github.com/raptor-mvk/test-utils)

(c) Mikhail Kamorin aka raptor\_MVK

Overview
--------

[](#overview)

Package contains following components:

- trait `ExtraUtilsTrait` that contains set of service methods used to make testing easier
- trait `ExtraAssertionsTrait` that contains set of additional assertions
- trait `WithVFSTrait` that provides adapted interface for `mikey179/vfsstream` (virtual file system)
- test data loader from JSON files that wraps each test case into test data container
- command `generate-ide-test-containers` that generate service file for IDE used to autocomplete

Installation
------------

[](#installation)

The suggested installation method is via [composer](https://getcomposer.org/):

```
php composer.phar require raptor/test-utils:@stable
```

Usage
-----

[](#usage)

### Additional service methods

[](#additional-service-methods)

Add trait `ExtraUtilsTrait` to the class that contains tests or to the common base test class. After that the following static methods will be available:

- `invokeMethod(object $object, string $methodName, ?array $parameters = null)`invokes protected or private method with the given parameters
- `expectExceptionExactMessage(string $message)` checks that an exception is thrown with exact given message

### Additional assertions

[](#additional-assertions)

Add trait `ExtraAssertionsTrait` to the class that contains tests or to the common base test class. After that the following additional assertions will be available:

- `assertArraysAreSame(array $expected, array $actual, ?string $message = null)`checks the assertion that two arrays are same (order of elements, their types coincides at every level). Before checking, arrays are encoded as JSON strings, therefore you cannot use objects or functions as elements of an array.
- `assertArraysAreSameIgnoringOrder(array $expected, array $actual, ?string $message = null)`checks the assertion that two associative arrays contains same elements (at every level) ignoring their order at the top level. Before checking, arrays are encoded as JSON strings, therefore you cannot use objects or functions as elements of an array.
- `assertArraysAreSameIgnoringOrderRecursive(array $expected, array $actual, ?string $message = null)`checks the assertion that two associative arrays contains same elements ignoring their order at every level. Before checking, arrays are encoded as JSON strings, therefore you cannot use objects or functions as elements of an array.
- `assertReturnsCarbonNow(callable $func, ?string $message = null)` checks the assertion that the given function returns result of `Carbon::now()`, invoked while running
- `assertReturnsCarbonNowWithoutMicroseconds(callable $func, ?string $message = null)`checks the assertion that the given function returns result of `Carbon::now()`, invoked while running, with zeroed microseconds
- `assertStringsAreSameIgnoringEOL(string $expected, string $actual, ?string $message = null)`checks the assertion that two given strings are same ignoring the difference in EOL characters

### Virtual file system

[](#virtual-file-system)

Add trait `WithVFSTrait` to the class that contains tests or to the common base test class. Method `setupVFS` should be used in `setUp` method or in the test method just before using other methods of the trait. No tearDown actions is needed regarding virtual file system. After that the following additional methods will be available:

- `addFileToVFS(string $filename, ?int $permissions = null, ?string $content = null)`adds file with given permissions and content to virtual file system.
- `addDirectoryToVFS(string $dirname, ?int $permissions = null)` adds directory with given permissions to virtual file system
- `addStructure(array $structure)` adds directory structure to virtual file system. Structure is represented as a tree, where leaves are files with key as the file name and value as the file content
- `getFullPath(string $path)` returns full path to the file that is used outside virtual file system

### Test data loader

[](#test-data-loader)

Data loader allows you to extract test data from data provider into separate JSON file. As a result of data loading a set of test cases is formed, where data for each test case is wrapped into container object. Values of specific fields from file are returned by getters. Such an approach allows you to solve the following tasks:

- extract test data from code to separate JSON files
- pass into testing method many parameters without inflating method signature
- organize test data into hierarchical structure, when there is common data in several test cases

Requirements to JSON file:

- file should contain **array** of JSON objects, array may contain single object
- field names should not start with underscore except cases specifically noted below
- field names should contain only lowercase letters, digits and underscore
- each object of the array should belong to one of two types:

    1. Test case. Such objects **should not** contain service field `_children`and **should** contain service field `_name`
    2. Array of test cases with default values for some fields. Such objects **should** contain service field `_children` and **should not** contain service field `_name`
- service field `_name` should contain string, it is name of the test case
- values of service field `_name` should be unique and non-empty
- service field `_children` should contain array, that meets the same requirements as the root array of the file

Objects of first type are processed by following algorithm:

- if object being processed has parent object of second type, then:
- if parent object contains fields, that does not belong to the object being processed, then they are added to the object being processed with appropriate values
- if parent object has parent object of second type too, then procedure is repeated for its parent and so on

Intermediate result of data loader is an array of all objects of first type with values of service field `_name` as keys. Service field `_name` itself is excluded from the objects.

Then each array value is wrapped into TestDataContainer object. Values are retrieved from containers using getters. Name of getters follow standard agreements:

- if the name of field starts with 'is', then the getter name is field name converted to camel case
- otherwise, if the field is of bool type, then the getter name is field name converted to studly case and prefixed with 'is'
- otherwise, the getter name is field name converted to studly case and prefixed with 'get'

### Generator of service file for IDE

[](#generator-of-service-file-for-ide)

Service file for IDE is used for auto-completion when using container objects. Generator is called by following command:

```
    php vendor/raptor/test-utils/generate-ide-test-containers path
```

where `path` - path to directory with JSON files that contain test data. Directory is processed recursively. Requirements to JSON files:

- the name of each JSON file without an extension is converted to studly case, after that conversion all strings must be different. Duplicate names will not be processed
- each JSON file should meet the requirements from the section **[Test data loader](#test-data-loader)**

As a result of the command execution, the \_ide\_test\_containers.php file is generated in the project root. This file contains container class for each JSON file in the specified directory. Each container class is located in the root namespace and has the name obtained by converting the name of the JSON file to studly case and adding the suffix `DataContainer`. You can use auto-completion after adding a PHPDoc comment `@var` with appropriate class and variable.

### Data loader usage example with trait WithDataLoaderTrait

[](#data-loader-usage-example-with-trait-withdataloadertrait)

```
    use Raptor\Test\TestDataContainer\TestDataContainer;

    class someTests extends TestCase
    {
        use WithDataLoaderTrait;

        ...

        /**
         * @dataProvider someDataProvider
         */
        public function testSomething(TestDataContainer $dataContainer): void
        {
            /** @var \SomeTestsDataContainer $dataContainer */
            $value = $dataContainer->getValue();
            ...
        }

        public function someDataProvider(): array
        {
            return $this->loadFromFile('some_tests.json');
        }

        ...
    }
```

Authors
-------

[](#authors)

- Mikhail Kamorin aka raptor\_MVK
- Igor Vodka

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2429d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/202b30d6600c0a8c0f128ccb26d97e2e926039898db1fb364bf08759c15b7911?d=identicon)[raptor\_mvk](/maintainers/raptor_mvk)

---

Top Contributors

[![raptor-mvk](https://avatars.githubusercontent.com/u/8713227?v=4)](https://github.com/raptor-mvk "raptor-mvk (125 commits)")[![IgorVodka](https://avatars.githubusercontent.com/u/924977?v=4)](https://github.com/IgorVodka "IgorVodka (12 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/raptor-test-utils/health.svg)

```
[![Health](https://phpackages.com/badges/raptor-test-utils/health.svg)](https://phpackages.com/packages/raptor-test-utils)
```

###  Alternatives

[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[phan/phan

A static analyzer for PHP

5.6k11.2M1.1k](/packages/phan-phan)[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[phpbench/phpbench

PHP Benchmarking Framework

2.0k13.0M627](/packages/phpbench-phpbench)[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15511.5M30](/packages/magento-magento2-functional-testing-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
