TKF-Kusht-Federasiya/vendor/dms/phpunit-arraysubset-asserts
Kerim 13e5a2029c first commit 2022-07-14 16:32:26 +05:00
..
.github first commit 2022-07-14 16:32:26 +05:00
src first commit 2022-07-14 16:32:26 +05:00
tests/Unit first commit 2022-07-14 16:32:26 +05:00
.gitignore first commit 2022-07-14 16:32:26 +05:00
LICENSE first commit 2022-07-14 16:32:26 +05:00
README.md first commit 2022-07-14 16:32:26 +05:00
composer.json first commit 2022-07-14 16:32:26 +05:00
composer.lock first commit 2022-07-14 16:32:26 +05:00
phpcs.xml.dist first commit 2022-07-14 16:32:26 +05:00
phpunit.xml.dist first commit 2022-07-14 16:32:26 +05:00

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
    {
        $expectedSubset = ['bar' => 0];

        $content = ['bar' => '0'];

        self::assertArraySubset($expectedSubset, $content, true);
    }

    public function testWithDirectCall(): void
    {
        $expectedSubset = ['bar' => 0];

        $content = ['bar' => '0'];

        Assert::assertArraySubset($expectedSubset, $content, true);
    }
}