Skip to content

Commit 7f798b6

Browse files
authored
Ensure that State::make calls the State's constructor (#112)
* Delete update-discord.yml * Call constructor when making state * Add test for State::make
1 parent e7392c7 commit 7f798b6

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

.github/workflows/update-discord.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/State.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function make(...$args): static
3030
$args = $args[0];
3131
}
3232

33-
$state = app(Serializer::class)->deserialize(static::class, $args);
33+
$state = app(Serializer::class)->deserialize(static::class, $args, call_constructor: true);
3434

3535
app(StateManager::class)->register($state);
3636

tests/Unit/StateManagerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@
3232
app(StoresSnapshots::class)->assertNothingWritten();
3333
});
3434

35+
test('it calls the state constructor on make', function () {
36+
$state = StateManagerTestState::make();
37+
expect($state->constructed)->toBeTrue();
38+
});
39+
3540
class StateManagerTestState extends State
3641
{
42+
public bool $constructed = false;
43+
44+
public function __construct()
45+
{
46+
parent::__construct();
47+
$this->constructed = true;
48+
}
3749
}

0 commit comments

Comments
 (0)