PHPackages                             darling/php-unit-test-utilities - 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. darling/php-unit-test-utilities

ActiveLibrary

darling/php-unit-test-utilities
===============================

A collection of Traits that define methods to aide in the implementation of phpunit tests.

v1.0.9(2y ago)21.8k↓86.4%[1 issues](https://github.com/sevidmusic/PHPUnitTestUtilities/issues)11MITPHPPHP ^8.1

Since Feb 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/sevidmusic/PHPUnitTestUtilities)[ Packagist](https://packagist.org/packages/darling/php-unit-test-utilities)[ RSS](/packages/darling-php-unit-test-utilities/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (11)

PHPUnitTestUtilities
====================

[](#phpunittestutilities)

The PHPUnitTestUtilities library provides traits that define methods to aide in the implementation of `phpunit` tests.

Overview
========

[](#overview)

- [Installation](#installation)
- [Traits](#traits)

    - [Darling\\PHPUnitTestUtilities\\traits\\PHPUnitConfigurationTests](#darlingphpunittestutilitiestraitsphpunitconfigurationtests)
    - [Darling\\PHPUnitTestUtilities\\traits\\PHPUnitTestMessages](#darlingphpunittestutilitiestraitsphpunittestmessages)
    - [Darling\\PHPUnitTestUtilities\\traits\\PHPUnitRandomValues](#darlingphpunittestutilitiestraitsphpunitrandomvalues)

Installation
============

[](#installation)

```
composer require darling/php-unit-test-utilities
```

Traits
======

[](#traits)

### Darling\\PHPUnitTestUtilities\\traits\\PHPUnitConfigurationTests

[](#darlingphpunittestutilitiestraitsphpunitconfigurationtests)

This trait defines the following test methods:

```
    /**
     * Test that phpunit tests run.
     *
     * If this test does not run then phpunit is not set up
     * correctly.
     *
     */
    public function test_php_unit_tests_are_run(): void;
```

Note: More detailed documentation can be found in the trait itself:

[tests/PHPUnitTestUtilities/traits/PHPUnitConfigurationTests.php](https://github.com/sevidmusic/PHPUnitTestUtilities/blob/main/src/traits/PHPUnitConfigurationTests.php)

### Darling\\PHPUnitTestUtilities\\traits\\PHPUnitTestMessages

[](#darlingphpunittestutilitiestraitsphpunittestmessages)

This trait defines the following methods to return formatted strings that can be used to output messages from `phpunit` tests,for example, when a test fails.

```
    /**
     * Return a message that indicates the failure of a test.
     *
     */
    protected function testFailedMessage(
        object $testedInstance,
        string $testedMethod,
        string $expectation
    ): void;
```

Note: More detailed documentation can be found in the trait itself:

[tests/PHPUnitTestUtilities/traits/PHPUnitTestMessages.php](https://github.com/sevidmusic/PHPUnitTestUtilities/blob/main/src/traits/PHPUnitTestMessages.php)

### Darling\\PHPUnitTestUtilities\\traits\\PHPUnitRandomValues

[](#darlingphpunittestutilitiestraitsphpunitrandomvalues)

The `PHPUnitRandomValues` trait defines the following methods that return random values of various types.

```
    /**
     * Return a string composed of a random number of randomly
     * generated characters.
     *
     */
    protected function randomChars(): string

    /**
     * Return a random float.
     *
     */
    protected function randomFloat(): float

    /**
     * Return a random fully qualified class name, or object instance.
     *
     */
    protected function randomClassStringOrObjectInstance(): string|object

    /**
     * Return a random object instance.
     *
     */
    protected function randomObjectInstance(): object
```

Note: More detailed documentation can be found in the trait itself:

[tests/PHPUnitTestUtilities/traits/PHPUnitRandomValues.php](https://github.com/sevidmusic/PHPUnitTestUtilities/blob/main/src/traits/PHPUnitRandomValues.php)

Example
=======

[](#example)

The following is a hypothetical example of how the traits provided by the PHPUnitTestUtilities library can be used in a class that implements `phpunit` tests.

```
