Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vielhuber/comparehelper
📑 Small php helper for comparing api responses. 📑
https://github.com/vielhuber/comparehelper
Last synced: 19 days ago
JSON representation
📑 Small php helper for comparing api responses. 📑
- Host: GitHub
- URL: https://github.com/vielhuber/comparehelper
- Owner: vielhuber
- Created: 2018-07-25T13:08:18.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-21T19:40:42.000Z (about 6 years ago)
- Last Synced: 2024-11-18T10:53:50.035Z (about 1 month ago)
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 📑 comparehelper 📑
comparehelper is a small php helper for comparing api responses in your tests.
## installation
install once with composer:
```
composer require vielhuber/comparehelper
```then add this to your files:
```php
require __DIR__.'/vendor/autoload.php';
use vielhuber\comparehelper\comparehelper;
```## usage
```php
CompareHelper::compare($var1, $var2); // true|false
```you can use the following placeholders:
- ```*```: any datatype
- ```#STR#```: any string
- ```#INT#```: any numeric value## examples
```php
CompareHelper::compare('foo','foo'); // trueCompareHelper::compare(42,42); // true
CompareHelper::compare(
[
'foo' => 'bar'
],
[
'foo' => 'bar',
'foo2' => 'bar'
]
); // falseCompareHelper::compare(
[
'foo' => 'bar',
'bar' => [
'baz',
42
]
],
[
'#STR' => '*',
'bar' => [
'#STR#',
'#INT#'
]
]
); // true// ordering is lazy
CompareHelper::compare(['foo','bar'],['bar','foo']); // true
CompareHelper::compare(['#INT#','#STR#'],[42,'foo']); // true
CompareHelper::compare(['#INT#','#STR#'],['foo',42]); // false
CompareHelper::compare(['foo' => 7,'bar' => 42],['bar' => 42,'foo' => 7,]); // true
CompareHelper::compare(['#INT#' => 7,'#STR#' => 42],[7 => 7,'foo' => 42]); // true
CompareHelper::compare(['#INT#' => 7,'#STR#' => 42],['foo' => 42,7 => 7]); // false// datatypes are strict
CompareHelper::compare(42,'42'); // false
```