Parse Error

Open
#134 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Reproduce the transformation using the reported loadConfiguration($configFile) example and PHP 7.0.10, then inspect the FilterInjectorTransformer::rewrite entry point mentioned in the generated code. The fix is complete when the transformed foreach/require expression parses successfully and preserves the original iteration behavior.

Written by the indexing model from the issue text.

Description

Case:
Framework: Yii2 2.0.11.2
PHP: 7.0.10
AspeckMock 2.0.1
info On ver. 1.0.0 works fine

AspectMock wrong parsing, convert and write to temporary storage this piece of code:

original code

protected function loadConfiguration($configFile)
    {
        $this->stdout("Loading configuration from '{$configFile}'...\n");
        foreach (require($configFile) as $name => $value) {
            if (property_exists($this, $name) || $this->canSetProperty($name)) {
                $this->$name = $value;
            } else {
                throw new Exception("Unknown configuration option: $name");
            }
        }

        $this->getAssetManager(); // check if asset manager configuration is correct
    }

after convert with AspeckMock

protected function loadConfiguration($configFile)
    { if (($__am_res = __amock_before($this, __CLASS__, __FUNCTION__, array($configFile), false)) !== __AM_CONTINUE__) return $__am_res; 
        $this->stdout("Loading configuration from '{$configFile}'...\n");
        foreach (require \Go\Instrument\Transformer\FilterInjectorTransformer::rewrite(($configFile) as $name => $value, '<dirPath>')) {
            if (property_exists($this, $name) || $this->canSetProperty($name)) {
                $this->$name = $value;
            } else {
                throw new Exception("Unknown configuration option: $name");
            }
        }

        $this->getAssetManager(); // check if asset manager configuration is correct
    }

Problem with parse:

foreach (require \Go\Instrument\Transformer\FilterInjectorTransformer::rewrite(($configFile) as $name => $value, '<dirPath>'))

Error

Exception 'ParseError' with message 'syntax error, unexpected 'as' (T_AS), expecting ',' or ')''
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.