Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpunit Arraysubset Asserts Laravel Package

dms/phpunit-arraysubset-asserts

Polyfill for PHPUnit’s deprecated/removed assertArraySubset. Adds Assert::assertArraySubset() and a trait to keep existing tests working. Uses native PHPUnit behavior when available; provides the missing assertion for PHPUnit 8+ while supporting older versions.

View on GitHub
Deep Wiki
Context7

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

:bulb: The package can be safely required on PHP 5.4 to current in combination with PHPUnit 4.8.36/5.7.21 to current.

When the PHPUnit assertArraySubset() method is natively available and not deprecated (PHPUnit 4.x - 7.x), the PHPUnit native functionality will be used. For PHPUnit 8 and higher, the extension will kick in and polyfill the functionality which was removed from PHPUnit.

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.

Trait use example

<?php

namespace Your\Package\Tests;

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

final class ExampleTest extends TestCase
{
    use ArraySubsetAsserts;

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

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

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

        $content = ['foo' => '1'];

        $this->assertArraySubset($expectedSubset, $content, true);
    }
}

Static class method example

<?php

namespace Your\Package\Tests;

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

final class ExampleTest extends TestCase
{
    public function testWithDirectCall(): void
    {
        $expectedSubset = ['bar' => 0];

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

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

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport