Skip to content

Commit 18c062b

Browse files
committed
Use assertions
1 parent 3d1985f commit 18c062b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/StaticMethodMock.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public function expect(string $method, array $arguments, mixed $returns = null,
5656
];
5757
}
5858

59+
public function assertExpectationsMet(): void
60+
{
61+
if (!empty($this->expectations)) {
62+
$this->testCase->fail(sprintf('StaticMethodMock not all expectations met for %s, %d remaining', $this->className, count($this->expectations)));
63+
}
64+
}
65+
5966
/**
6067
* Handle a static call to a mocked class.
6168
* @param string $className The class name

tests/StaticMethodMockTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class StaticMethodMockTest extends TestCase
1010
{
11-
public function testStaticMethodMock(): void
11+
public function testUsingMockedAdder(): void
1212
{
1313
// Create a static method mock for the Adder class
1414
$mock = new StaticMethodMock(Adder::class, $this);
@@ -18,5 +18,7 @@ public function testStaticMethodMock(): void
1818
$result = Adder::add(1, 2);
1919
// Verify the result
2020
$this->assertEquals(3, $result);
21+
// Assert that all expectations were met
22+
$mock->assertExpectationsMet();
2123
}
2224
}

0 commit comments

Comments
 (0)