Codeception / Codeception/AspectMock

Test::double doesn't work properly for static methods in parent

Offen
#120 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
PHP
Sterne
784
Forks
132
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I'm using Yii2, Codeception and AspectMock, when I'm trying to mock/double static method from parent class then original method is used instad of mocked one.

Below example:

class Yii extends \yii\BaseYii
class \yii\BaseYii has static method `error()`

```
public function testStaticMethodForParentIsMocked()
{
$appVerifier = AspectMock\Test::double(\yii\BaseYii::class, [
'error' => function () {
return 2;
}
]);

$test = \Yii::error('test'); // Original method were used
$this->assertEquals(2, $test); // this assert will fail - not correct
$appVerifier->verifyInvokedOnce('error'); // this will pass - correct
}
```

```
public function testStaticMethodForClassIsMocked()
{
$appVerifier = AspectMock\Test::double(\Yii::class, [
'error' => function () {
return 2;
}
]);

$test = \Yii::error('test'); // Mocked method were used
$this->assertEquals(2, $test); // this assert will pass - correct
$appVerifier->verifyInvokedOnce('error'); // this will pass - correct
}
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.