From 421a2393d0f5118cb69132d1be0fa8a7aae52546 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Fri, 15 Oct 2021 23:18:08 +0100 Subject: [PATCH] StateBearer must be constructable from State --- src/State.php | 6 ++++++ src/StateBearer.php | 2 ++ tests/src/StateTest.php | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/src/State.php b/src/State.php index 532a287..55792c3 100644 --- a/src/State.php +++ b/src/State.php @@ -107,6 +107,12 @@ final class State implements StateBearer return $this; } + /** @return self */ + public static function fromState(State $State) + { + return $State; + } + public function isolatedCopy(): self { return new self(\array_map( diff --git a/src/StateBearer.php b/src/StateBearer.php index f0f9190..dc29cf3 100644 --- a/src/StateBearer.php +++ b/src/StateBearer.php @@ -5,4 +5,6 @@ namespace Erusev\Parsedown; interface StateBearer { public function state(): State; + /** @return static */ + public static function fromState(State $State); } diff --git a/tests/src/StateTest.php b/tests/src/StateTest.php index babb419..b9631f6 100644 --- a/tests/src/StateTest.php +++ b/tests/src/StateTest.php @@ -39,4 +39,16 @@ final class StateTest extends TestCase { $this->assertInstanceOf(State::class, clone(new State)); } + + /** + * @return void + * @throws \PHPUnit\Framework\Exception + * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + */ + public function testStateFromStateIdentical() + { + $State = new State; + + $this->assertSame($State, State::fromState($State)); + } }