Skip to content

Commit 8e23c5d

Browse files
committed
test(multiprovider): improve ComparisonStrategy test coverage
Add edge case tests: - Test single provider scenario - Test mismatch without onMismatch callback - Test getter methods for fallbackProvider and onMismatch - Test getOnMismatch returns null when not provided Signed-off-by: tmakinde <makindet74@gmail.com>
1 parent 8ac9e86 commit 8e23c5d

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

tests/unit/ComparisonStrategyTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,55 @@ public function testOnMismatchCallbackErrorsAreIgnored(): void
203203
$res = $mp->resolveBooleanValue('flag', false, new EvaluationContext());
204204
$this->assertFalse($res->getValue());
205205
}
206+
207+
public function testSingleProviderReturnsItsValue(): void
208+
{
209+
$strategy = new ComparisonStrategy($this->providerA);
210+
$this->providerA->shouldReceive('resolveBooleanValue')->andReturn($this->details(true));
211+
212+
$mp = new MultiProvider(
213+
[
214+
['name' => 'a', 'provider' => $this->providerA],
215+
],
216+
$strategy,
217+
);
218+
219+
$res = $mp->resolveBooleanValue('flag', false, new EvaluationContext());
220+
$this->assertTrue($res->getValue());
221+
}
222+
223+
public function testMismatchWithoutCallbackSucceeds(): void
224+
{
225+
// Test mismatch path when no callback is provided
226+
$strategy = new ComparisonStrategy($this->providerB, null);
227+
$this->providerA->shouldReceive('resolveBooleanValue')->andReturn($this->details(true));
228+
$this->providerB->shouldReceive('resolveBooleanValue')->andReturn($this->details(false));
229+
230+
$mp = new MultiProvider(
231+
[
232+
['name' => 'a', 'provider' => $this->providerA],
233+
['name' => 'b', 'provider' => $this->providerB],
234+
],
235+
$strategy,
236+
);
237+
238+
$res = $mp->resolveBooleanValue('flag', false, new EvaluationContext());
239+
$this->assertFalse($res->getValue()); // fallback provider's value
240+
}
241+
242+
public function testGettersReturnCorrectValues(): void
243+
{
244+
$callback = fn () => null;
245+
$strategy = new ComparisonStrategy($this->providerA, $callback);
246+
247+
$this->assertSame($this->providerA, $strategy->getFallbackProvider());
248+
$this->assertSame($callback, $strategy->getOnMismatch());
249+
}
250+
251+
public function testGetOnMismatchReturnsNullWhenNotProvided(): void
252+
{
253+
$strategy = new ComparisonStrategy($this->providerA);
254+
255+
$this->assertNull($strategy->getOnMismatch());
256+
}
206257
}

0 commit comments

Comments
 (0)