From ec72e1269dadab9a37c7464108ef3889100be9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Rozs=C3=ADval?= Date: Sat, 17 Apr 2021 12:01:25 +0200 Subject: [PATCH] Add ImmutableObject trait --- src/Utils/ImmutableObject.php | 23 +++++++++++++++++++ tests/UtilsTests/ImmutableObject.php | 29 ++++++++++++++++++++++++ tests/UtilsTests/ImmutableObjectTest.php | 17 ++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 src/Utils/ImmutableObject.php create mode 100644 tests/UtilsTests/ImmutableObject.php create mode 100644 tests/UtilsTests/ImmutableObjectTest.php diff --git a/src/Utils/ImmutableObject.php b/src/Utils/ImmutableObject.php new file mode 100644 index 0000000..b2c702b --- /dev/null +++ b/src/Utils/ImmutableObject.php @@ -0,0 +1,23 @@ +$property = $value; + return $object; + } + +} diff --git a/tests/UtilsTests/ImmutableObject.php b/tests/UtilsTests/ImmutableObject.php new file mode 100644 index 0000000..8c59782 --- /dev/null +++ b/tests/UtilsTests/ImmutableObject.php @@ -0,0 +1,29 @@ +prop = $prop; + } + + public function getProp(): string + { + return $this->prop; + } + + public function withProp(string $prop): self + { + return $this->withMutation('prop', $prop); + } + +} diff --git a/tests/UtilsTests/ImmutableObjectTest.php b/tests/UtilsTests/ImmutableObjectTest.php new file mode 100644 index 0000000..6d1e70d --- /dev/null +++ b/tests/UtilsTests/ImmutableObjectTest.php @@ -0,0 +1,17 @@ +assertSame('default', $object->getProp()); + $this->assertNotSame($object, $object->withProp('changed')); + } + +}