Codeception / Codeception/AspectMock
Mocking with a Closure
- Dominant language
- PHP
- Stars
- 784
- Forks
- 132
- PR merge metrics
- No merged PRs in 30d
Description
For the following class
```PHP
class Demo {
public function aFunc() {
return 'initialFunc';
}
}
```
I have written the following test that mocks the class replacing `aFunc` with a closure as follows
```PHP
class DemoTest extends PHPUnit_Framework_TestCase {
public function testWithClosure() {
\AspectMock\Test::double(Demo::class, [
'aFunc' => function($a) { return $a.$a; },
]);
$mockDemo = new Demo();
$this->assertEquals('abcabc', $mockDemo->aFunc('abc'));
}
}
```
When I run it, I get the following error
```SH
$ ../vendor/bin/phpunit .
PHPUnit 4.8.35 by Sebastian Bergmann and contributors.
E
Time: 222 ms, Memory: 7.25MB
There was 1 error:
1) DemoTest::testWithClosure
Missing argument 1 for Demo::{closure}()
dev/ez-mock/test/DemoTest.php:10
dev/ez-mock/vendor/codeception/aspect-mock/src/AspectMock/Core/Mocker.php:154
dev/ez-mock/vendor/codeception/aspect-mock/src/AspectMock/Core/Mocker.php:79
dev/ez-mock/vendor/codeception/aspect-mock/src/AspectMock/Core/Mocker.php:28
dev/ez-mock/vendor/codeception/aspect-mock/src/AspectMock/Intercept/before_mock.php:3
dev/ez-mock/test/Demo.php:4
dev/ez-mock/test/DemoTest.php:13
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
```
What am I doing wrong?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.