Codeception / Codeception/AspectMock

Error: Using $this when not in object context

Ouverte
#187 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
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

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.