From c8045565e5a17231fd1abe79f285a7165cd18c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yunus=20Emre=20Delig=C3=B6z?= Date: Tue, 5 Nov 2024 20:29:36 +0300 Subject: [PATCH] WB-623: test(invokablebehaviorfaketest): add tests for resetting fakes with trait instances Add new test to ensure resetting fakes with different trait instances works consistently. Enhances coverage for behavior isolation. --- tests/InvokableBehaviorFakeTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/InvokableBehaviorFakeTest.php b/tests/InvokableBehaviorFakeTest.php index 14762c9..90563af 100644 --- a/tests/InvokableBehaviorFakeTest.php +++ b/tests/InvokableBehaviorFakeTest.php @@ -320,6 +320,7 @@ public function __invoke(ContextManager $context): bool TestCountGuard::shouldRun()->never(); TestCountGuard::assertNotRan(); }); + it('maintains behavior isolation after resetting all fakes', function (): void { // 1. Arrange TestIncrementAction::shouldRun()->once(); @@ -334,4 +335,27 @@ public function __invoke(ContextManager $context): bool TestIncrementAction::assertRan(); expect(TestCountGuard::isFaked())->toBeFalse(); }); + +it('can reset fakes with different trait instances consistently', function (): void { + // 1. Arrange + TestIncrementAction::shouldRun()->once(); + TestCountGuard::shouldRun()->twice(); + + // 2. Act + TestIncrementAction::resetAllFakes(); + + // Try to create new fakes + TestIncrementAction::shouldRun()->once(); + TestCountGuard::shouldRun()->once(); + + // Reset using another instance + TestCountGuard::resetAllFakes(); + + // 3. Assert + expect(TestIncrementAction::isFaked())->toBeFalse() + ->and(TestCountGuard::isFaked())->toBeFalse() + ->and(TestIncrementAction::getFake())->toBeNull() + ->and(TestCountGuard::getFake())->toBeNull(); +}); + // endregion