Codeception / Codeception/AspectMock

Mocking with a Closure

オープン
#131 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
PHP
スター
784
フォーク
132
PR マージ指標
30日以内にマージされた PR はありません

説明

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?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。