Skip to content
Provides assertArraySubset for use in PHPunit
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests/Unit
.gitignore
.travis.yml
LICENSE
README.md
composer.json
composer.lock
phpcs.xml.dist
phpunit.xml.dist

README.md

PHPUnit AssertArraySubset Extension

In PHPUnit 8 the function assertArraySubset was deprecated. This function was often misunderstood and thus removed, but it still holds true as a very useful tool, hence it was extracted here.

Disclaimer: The initial version contained here is copied over from phpunit and is heavily based on the original work by Márcio Almada.

Installation

Simply use it by importing it with Composer

composer require --dev dms/phpunit-arraysubset-asserts

Usage

You have two options to use this in your classes: either directly as a static call or as a trait if you wish to keep existing references working.

<?php
declare(strict_types=1);

namespace DMS\Tests;

use DMS\PHPUnitExtensions\ArraySubset\Assert;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use PHPUnit\Framework\TestCase;


final class AssertTest extends TestCase
{
    use ArraySubsetAsserts;
    
    public function testWithTrait(): void
    {
        self::assertArraySubset(['bar' => 0], ['bar' => '0'], true);
    }

    public function testWithDirectCall(): void
    {
        Assert::assertArraySubset(['bar' => 0], ['bar' => '0'], true);
    }
}
You can’t perform that action at this time.