Incorrect cache files

Open
#184 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
php
Domain
testing

Research direction

Start with the cacheDir configured in bootstrap.php and inspect the generated cache files after running the tests. Compare the cache output with the TestCase.php cleanup flow and reproduce the ParseError; done means the test run no longer creates invalid PHP cache files.

Written by the indexing model from the issue text.

Description

Invalid cache files creating when I run tests. In directory file looks like:

class Settings { if (($__am_res = __amock_before($this, __CLASS__, __FUNCTION__, array(), false)) !== __AM_CONTINUE__) return $__am_res;
...

After the test run I get the error message:

[ParseError] syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) or const (T_CONST)

Environment

  • Codeception 4.1
  • PHP7.2
  • Aspect Mock 3.1

bootstrap.php

use AspectMock\Kernel;

define( 'PLUGIN_NAME_PATH', realpath( __DIR__ . '/../../../' ) . '/' );

$kernel = Kernel::getInstance();
$kernel->init(
	[
		'cacheDir'     => PLUGIN_NAME_PATH . '.codeception/_cache/',
		'debug'        => true,
		'includePaths' => [ PLUGIN_NAME_PATH . 'src/' ],
	]
);

TestCase.php

use AspectMock\Test;
use Codeception\Test\Unit;
use AspectMock\Core\Registry;

abstract class TestCase extends Unit {
	protected function _after(): void {
		if ( Registry::$mocker ) {
			Test::clean();
		}
		parent::_after();
	}
}
Dominant language
PHP
Stars
784
Forks
130
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Codeception/AspectMock

All issues in Codeception/AspectMock

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.