Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rdohms/phpunit-arraysubset-asserts
Provides assertArraySubset for use in PHPunit
https://github.com/rdohms/phpunit-arraysubset-asserts
hacktoberfest php phpunit phpunit-extension
Last synced: 1 day ago
JSON representation
Provides assertArraySubset for use in PHPunit
- Host: GitHub
- URL: https://github.com/rdohms/phpunit-arraysubset-asserts
- Owner: rdohms
- License: mit
- Created: 2019-02-16T22:24:07.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-17T13:53:49.000Z (8 months ago)
- Last Synced: 2024-10-29T17:33:58.099Z (3 months ago)
- Topics: hacktoberfest, php, phpunit, phpunit-extension
- Language: PHP
- Homepage:
- Size: 170 KB
- Stars: 134
- Watchers: 11
- Forks: 23
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHPUnit AssertArraySubset Extension
In PHPUnit 8 the function `assertArraySubset` was [deprecated](https://github.com/sebastianbergmann/phpunit/issues/3494). 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](https://github.com/marcioAlmada).## 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
0];$content = ['bar' => '0'];
self::assertArraySubset($expectedSubset, $content, true);
$content = ['foo' => '1'];
$this->assertArraySubset($expectedSubset, $content, true);
}
}
```### Static class method example
```php
0];$content = ['bar' => '0'];
Assert::assertArraySubset($expectedSubset, $content, true);
}
}
```