{"id":18598476,"url":"https://github.com/backendtea/assert-object-same-state","last_synced_at":"2025-05-16T14:12:02.372Z","repository":{"id":62491036,"uuid":"226711576","full_name":"BackEndTea/assert-object-same-state","owner":"BackEndTea","description":"Check if two objects have the same state","archived":false,"fork":false,"pushed_at":"2019-12-09T07:59:45.000Z","size":6,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-17T23:48:17.630Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BackEndTea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-08T18:21:44.000Z","updated_at":"2020-05-11T08:34:53.000Z","dependencies_parsed_at":"2022-11-02T11:15:50.004Z","dependency_job_id":null,"html_url":"https://github.com/BackEndTea/assert-object-same-state","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BackEndTea%2Fassert-object-same-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BackEndTea%2Fassert-object-same-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BackEndTea%2Fassert-object-same-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BackEndTea%2Fassert-object-same-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BackEndTea","download_url":"https://codeload.github.com/BackEndTea/assert-object-same-state/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254544157,"owners_count":22088808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T01:32:53.640Z","updated_at":"2025-05-16T14:12:02.349Z","avatar_url":"https://github.com/BackEndTea.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Assert objects have same state\n\n![travis status](https://travis-ci.org/BackEndTea/assert-object-same-state.svg?branch=master)\n\nPHPUnit assertion helper to check if two objects have the same state.\n\nPlease note that same state only refers to the state of the properties. \nIf you use the `static` keyword inside of functions, and they have their own state, then you are on your own.\n\n\n## Install\n\nUse [composer](https://getcomposer.org/):\n\n```bash\n$ composer require backendtea/assert-object-same-state --dev\n```\n\n### Usage\n\nThis package is compatible with phpunit 8.\n\n```php\n\u003c?php\n\nuse BackEndTea\\SameObject\\ObjectHasSameStateAssertion;\nuse PHPUnit\\Framework\\TestCase;\n\nclass MyTest extends TestCase\n{\n    use ObjectHasSameStateAssertion;\n\n    public function testObjects(): void\n    {\n        $one = new class{public $a=3;};\n        $two = new class{public $a=3;};\n        $this-\u003eassertObjectHasSameSate($one, $two);\n    }\n}\n```\n\n### Outside of PHPUnit\n\n```php\n\u003c?php\n\n$comp = new \\BackEndTea\\SameObject\\ObjectComparator();\n\n$comp-\u003ehaveSameState($objectOne, $objectTwo);\n```\n\n\n## Why\n\n`assertSame()` or `===`  checks if the two variables are refferencing the same object, \nwhich may not be always what you need.\nBut `assertEquals` or `==` is too loose a comparison, as it suffers from the same issues as other loose comparisons.\n\nFor example:\n\n```php\n\u003c?php\nclass Thing\n{\n    public $prop;\n    public function __construct($prop)\n    {\n        $this-\u003eprop = $prop;\n    }\n}\nnew Thing(10) == new Thing('10'); // true\nnew Thing(10) === new Thing('10'); // false\nnew Thing(10) === new Thing(10); // false\n```\n\n## Limitations\n\nSame state only refers to the state of the properties. \nIf you use the `static` keyword inside of methods, and they have their own state, \nthen you are on your own.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbackendtea%2Fassert-object-same-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbackendtea%2Fassert-object-same-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbackendtea%2Fassert-object-same-state/lists"}