dms / phpunit-arraysubset-asserts
This package provides ArraySubset and related asserts once deprecated in PHPUnit 8
Installs: 1 357 013
Dependents: 140
Suggesters: 0
Security: 0
Stars: 95
Watchers: 6
Forks: 14
Open Issues: 7
Requires
- php: ^7.3|^8.0
- phpunit/phpunit: ^9.0
Requires (Dev)
- dms/coding-standard: ^1.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2021-02-13 13:59:21 UTC
README
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); } }