Skip to content

Commit

Permalink
WB-623: test(invokablebehaviorfaketest): add tests for resetting fake…
Browse files Browse the repository at this point in the history
…s with trait instances

Add new test to ensure resetting fakes with different trait instances
works consistently. Enhances coverage for behavior isolation.
  • Loading branch information
deligoez committed Nov 5, 2024
1 parent c270c68 commit c804556
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/InvokableBehaviorFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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

0 comments on commit c804556

Please sign in to comment.