https://github.com/backendtea/assert-object-same-state
Check if two objects have the same state
https://github.com/backendtea/assert-object-same-state
Last synced: about 2 months ago
JSON representation
Check if two objects have the same state
- Host: GitHub
- URL: https://github.com/backendtea/assert-object-same-state
- Owner: BackEndTea
- License: mit
- Created: 2019-12-08T18:21:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-09T07:59:45.000Z (over 5 years ago)
- Last Synced: 2025-02-17T23:48:17.630Z (5 months ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Assert objects have same state

PHPUnit assertion helper to check if two objects have the same state.
Please note that same state only refers to the state of the properties.
If you use the `static` keyword inside of functions, and they have their own state, then you are on your own.## Install
Use [composer](https://getcomposer.org/):
```bash
$ composer require backendtea/assert-object-same-state --dev
```### Usage
This package is compatible with phpunit 8.
```php
assertObjectHasSameSate($one, $two);
}
}
```### Outside of PHPUnit
```php
haveSameState($objectOne, $objectTwo);
```## Why
`assertSame()` or `===` checks if the two variables are refferencing the same object,
which may not be always what you need.
But `assertEquals` or `==` is too loose a comparison, as it suffers from the same issues as other loose comparisons.For example:
```php
prop = $prop;
}
}
new Thing(10) == new Thing('10'); // true
new Thing(10) === new Thing('10'); // false
new Thing(10) === new Thing(10); // false
```## Limitations
Same state only refers to the state of the properties.
If you use the `static` keyword inside of methods, and they have their own state,
then you are on your own.