Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 17 days ago
JSON representation

Check if two objects have the same state

Awesome Lists containing this project

README

        

# Assert objects have same state

![travis status](https://travis-ci.org/BackEndTea/assert-object-same-state.svg?branch=master)

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.