Skip to content

Conversation

@smirok
Copy link
Contributor

@smirok smirok commented Jan 14, 2026

What:

  • Bug Fix
  • New Feature

Description:

Problem:

When running Pest tests with --teamcity flag inside a describe block with datasets, the last 2 characters of the test suite name are incorrectly cut off.

Root Cause:

The Str::beforeLast() method in src/Support/Str.php has a byte/character position mismatch bug:

public static function beforeLast(string $subject, string $search): string
{
    // ...
    $pos = mb_strrpos($subject, $search);  // Returns CHARACTER position
    // ...
    return substr($subject, 0, $pos);       // Expects BYTE position
}

The describe block format uses the arrow character → (U+2192), which is:

  • 1 character in length
  • 3 bytes in UTF-8 encoding

When mb_strrpos finds the position of with data set in a string like my_block → my_test with data set "1", it returns a character position. But substr interprets this as a byte position, causing a 2-byte offset (3 bytes for → minus 1 character = 2 bytes difference).

Example:

  • Input: my_block → my_test with data set "1"
  • Expected output: my_block → my_test
  • Actual output: my_block → my_te

Solution

Change substr to mb_substr in Str::beforeLast() to ensure character-based substring operation matches the character based position from mb_strrpos.

Impact

It will allow to support navigation for such tests from the Test Results tool window in PhpStorm to source code in the file.

…ultibyte string compatibility and correct TeamCity test names for datasets in "describe" blocks
@nunomaduro nunomaduro merged commit dd01229 into pestphp:4.x Jan 15, 2026
0 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants