Codeception / Codeception/AspectMock
Error: Using $this when not in object context
- Langage dominant
- PHP
- Étoiles
- 784
- Forks
- 132
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
```php
namespace app\aspectmockexample;
class AdminUserModel extends UserModel
{
public function save()
{
$this->name = "Admin_111";
parent::save();
}
}
```
```php
testing:
public function testMagicStaticInherited()
{
double::registerClass('app\aspectmockexample\AdminUserModel', ['defaultRole' => 'admin']);
TestCase::assertEquals('admin', AdminUserModel::defaultRole());
}
```
```php
cache file generic:
public static function __callStatic($name, $args)
{
if ($name == 'defaultRole') { if (($__am_res = __amock_before($this, __CLASS__, __FUNCTION__, array(), false)) !== __AM_CONTINUE__) return $__am_res;
return "member";
}
}
```
Error message:
```text
1) StubTest::testMagicStaticInherited
Error: Using $this when not in object context
```
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Start with StubTest::testMagicStaticInherited and reproduce the error using the AdminUserModel example. Then inspect the generated cache file's __callStatic method and the __amock_before call shown in the report. Done means the test completes without “Using $this when not in object context” and still returns the expected admin role.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- php
- Domaine
- testing
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100