Codeception / Codeception/AspectMock

Error: Using $this when not in object context

Open
#187 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
784
Forks
132
PR merge metrics
No merged PRs in 30d

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

```

Contributor guide

No contributing guide indexed for this repository

Research direction

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.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.