Codeception / Codeception/AspectMock
Mocking with a Closure
- Lingua principale
- PHP
- Stelle
- 784
- Fork
- 132
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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?
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.