Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: preg_match(): Compilation failed: subpattern name is too long #872

Closed
ghost opened this issue Apr 5, 2016 · 7 comments
Closed

Comments

@ghost
Copy link

ghost commented Apr 5, 2016

There is my .feature file:

Feature: Education Calculator
    As a customer
    In order to count how much money to save in a period of time to get my kids the best education

    Scenario: Count how much to save
        Given My child age now is 7 years old
        And My child age when she/he will using the money is 19 years old
        And He/she will use the money for 12 years
        And I need totally 600000000 for his/him education
        And My saving for his/him education is 25000000
        And My monthly saving for his/him education is 0
        And the annual interest rate is 6%
        And the inflation rate per year is 4%
        When I calculate
        Then I should get 960619331 as my totally need (after adjusted with inflation)
        And I should get 40025805 as the Future Value of my current saving
        And I should get 0 as the Future Value of my educational monthly savings
        And I should get 40025805 as my total saving when the education start
        And I should get 920593526 more money to save
        And I should save more 5014346 monthly
        And I should save more 60172155 yearly

But when i run behat it gave me PHP warning:

PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 120

Is any one got similar problem? Or whats wrong with my feature file?

@stof
Copy link
Member

stof commented Apr 5, 2016

The issue seems to be with one of your step definition, not with your feature file.

Please run Behat in verbose mode (with -v), to get a stack trace for the error, and then paste it here

@ghost
Copy link
Author

ghost commented Apr 5, 2016

Thanks for replying @stof.
There is the console output when i run behat -v

Feature: Education Calculator
    As a customer
    In order to count how much money to save in a period of time to get my kids the best education

  Scenario: Count how much to save                                                 # htdocs/content/themes/Astralife/tests/features/educalc.feature:5
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    Given My child age now is 7 years old                                          # DomainContext::myChildAgeNowIsYearsOld()
      TODO: write pending definition
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And My child age when she/he will using the money is 19 years old              # DomainContext::myChildAgeWhenSheHeWillUsingTheMoneyIsYearsOld()
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And He/she will use the money for 12 years                                     # DomainContext::heSheWillUseTheMoneyForYears()
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And I need totally 600000000 for his/him education                             # DomainContext::iNeedTotallyForHisHimEducation()
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And My saving for his/him education is 25000000                                # DomainContext::mySavingForHisHimEducationIs()
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And My monthly saving for his/him education is 0                               # DomainContext::myMonthlySavingForHisHimEducationIs()
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And the annual interest rate is 6%
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And the inflation rate per year is 4%
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    When I calculate                                                               # DomainContext::iCalculate()
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    Then I should get 960619331 as my totally need (after adjusted with inflation)
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And I should get 40025805 as the Future Value of my current saving             # DomainContext::iShouldGetAsTheFutureValueOfMyCurrentSaving()
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And I should get 0 as the Future Value of my educational monthly savings       # DomainContext::iShouldGetAsTheFutureValueOfMyEducationalMonthlySavings()
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And I should get 40025805 as my total saving when the education start          # DomainContext::iShouldGetAsMyTotalSavingWhenTheEducationStart()
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And I should get 920593526 more money to save                                  # DomainContext::iShouldGetMoreMoneyToSave()
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And I should save more 5014346 monthly                                         # DomainContext::iShouldSaveMoreMonthly()
PHP Warning:  preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121

Warning: preg_match(): Compilation failed: subpattern name is too long (maximum 32 characters) at offset 56 in /home/baboon/.composer/vendor/behat/behat/src/Behat/Behat/Definition/Search/RepositorySearchEngine.php on line 121
    And I should save more 60172155 yearly                                         # DomainContext::iShouldSaveMoreYearly()

1 scenario (1 undefined)
16 steps (3 undefined, 1 pending, 12 skipped)
0m0.03s (5.90Mb)

--- DomainContext has missing steps. Define them with these snippets:

    /**
     * @Given the annual interest rate is :arg1%
     */
    public function theAnnualInterestRateIs2($arg1)
    {
        throw new PendingException();
    }

    /**
     * @Given the inflation rate per year is :arg1%
     */
    public function theInflationRatePerYearIs2($arg1)
    {
        throw new PendingException();
    }

    /**
     * @Then I should get :arg1 as my totally need (after adjusted with inflation)
     */
    public function iShouldGetAsMyTotallyNeedAfterAdjustedWithInflation2($arg1)
    {
        throw new PendingException();
    }

Is my step definition too long?

@pamil
Copy link
Member

pamil commented Apr 5, 2016

You are probably using a turnip notation (:argumentName), with argument name length over those 32 characters. It can be defined anywhere in the suite as Behat run preg_match for all possible step definitions to verify, that only one was matched.

@ghost
Copy link
Author

ghost commented Apr 5, 2016

@pamil so :argumentName can't be more than 32 character?
Hmm..
"It can be defined anywhere in the suite as Behat run preg_match for all possible step definitions to verify, that only one was matched."

There are any example to define it? or may be I should cut my :argumentName to be less than 32 character :D?

@pamil
Copy link
Member

pamil commented Apr 5, 2016

TurnipPatternPolicy defines the transformation of turnip notation into a regular expression. Eg. :foo becomes [\"']?(?P<foo>(?<=\")[^\"]*(?=\")|(?<=')[^']*(?=')|[\w\.\,]+)['\"]?.

And as the PHP documentation says:

It is possible to name a subpattern using the syntax (?P<name>pattern). This subpattern will then be indexed in the matches array by its normal numeric position and also by name. PHP 5.2.2 introduced two alternative syntaxes (?<name>pattern) and (?'name'pattern).

So the foo becomes a subpattern name and there's no easy way to deal with it right now. Keeping the name <=32 characters will help :)

@ciaranmcnulty
Copy link
Contributor

To address this we would need to internally generate shorter names (or use numeric indexes) and then maintain a mapping of these names to the longer placeholder name.

A short-term fix would be to throw a more verbose exception earlier before the regex is generated.

@ghost
Copy link
Author

ghost commented Apr 6, 2016

@pamil: I'll just simply keep the name <=32 :).
@ciaranmcnulty: It will be great, so we can have more verbose argumentName

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants