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

[Bug]: Combining --parallel and --random-order-seed (with integer number) results in uncaught TypeError since 2.31.0 #1206

Open
DannyvdSluijs opened this issue Aug 26, 2024 · 0 comments
Labels

Comments

@DannyvdSluijs
Copy link
Contributor

What Happened

Running my test suite with a predefined random order seed in parallel results in an uncaught TypeError. Caused by changes made in f004591

With the following stacktrace

In WorkerCrashedException.php line 41:

  The test "PARATEST='1' TEST_TOKEN='1' UNIQUE_TEST_TOKEN='1_66cc83e74bff3' /private/tmp/repro/tests/Feature/ExampleTest.php" failed.

  Exit Code: 1(General error)

  Working directory: /private/tmp/repro

  Output:
  ================

     ERROR  Fatal error: Uncaught TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, int given i
  n /private/tmp/repro/vendor/pestphp/pest/src/Plugins/Concerns/HandleArguments.php on line 24


  TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, int given in /private/tmp/repro/vendor/pestphp/pest/src/Pl
  ugins/Concerns/HandleArguments.php on line 24

  Call Stack:
      0.0012     625992   1. {main}() /private/tmp/repro/vendor/pestphp/pest/bin/worker.php:0
      0.0012     627168   2. {closure:/private/tmp/repro/vendor/pestphp/pest/bin/worker.php:30-105}() /private/tmp/repro/vendor/pestphp/pe
  st/bin/worker.php:105
      0.0617    3983976   3. Pest\Plugins\Actions\CallsHandleArguments::execute($argv = [0 => 'vendor/bin/phpunit', 1 => '--cache-director
  y', 2 => '/private/tmp/repro/vendor/pestphp/pest/.temp', 3 => '--random-order-seed', 4 => '1', 5 => '--do-not-cache-result', 6 => '--no-
  logging', 7 => '--no-coverage', 8 => '--no-output']) /private/tmp/repro/vendor/pestphp/pest/bin/worker.php:74
      0.0625    4011640   4. Pest\Plugins\Help->handleArguments($arguments = [0 => 'vendor/bin/phpunit', 1 => '--cache-directory', 2 => '/
  private/tmp/repro/vendor/pestphp/pest/.temp', 3 => '--random-order-seed', 4 => 1, 5 => '--do-not-cache-result', 6 => '--no-logging', 7 =
  > '--no-coverage', 8 => '--no-output', 9 => '--cache-result']) /private/tmp/repro/vendor/pestphp/pest/src/Plugins/Actions/CallsHandleArg
  uments.php:29
      0.0625    4011640   5. Pest\Plugins\Help->hasArgument($argument = '--help', $arguments = [0 => 'vendor/bin/phpunit', 1 => '--cache-d
  irectory', 2 => '/private/tmp/repro/vendor/pestphp/pest/.temp', 3 => '--random-order-seed', 4 => 1, 5 => '--do-not-cache-result', 6 => '
  --no-logging', 7 => '--no-coverage', 8 => '--no-output', 9 => '--cache-result']) /private/tmp/repro/vendor/pestphp/pest/src/Plugins/Help
  .php:35
      0.0625    4011672   6. str_starts_with($haystack = 1, $needle = '--help=') /private/tmp/repro/vendor/pestphp/pest/src/Plugins/Concer
  ns/HandleArguments.php:24.

     Pest\Exceptions\FatalException

    Uncaught TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, int given in /private/tmp/repro/vendor/p
  estphp/pest/src/Plugins/Concerns/HandleArguments.php:24
  Stack trace:
  #0 /private/tmp/repro/vendor/pestphp/pest/src/Plugins/Concerns/HandleArguments.php(24): str_starts_with(1, '--help=')
  #1 /private/tmp/repro/vendor/pestphp/pest/src/Plugins/Help.php(35): Pest\Plugins\Help->hasArgument('--help', Array)
  #2 /private/tmp/repro/vendor/pestphp/pest/src/Plugins/Actions/CallsHandleArguments.php(29): Pest\Plugins\Help->handleArguments(Array)
  #3 /private/tmp/repro/vendor/pestphp/pest/bin/worker.php(74): Pest\Plugins\Actions\CallsHandleArguments::execute(Array)
  #4 /private/tmp/repro/vendor/pestphp/pest/bin/worker.php(105): {closure}()
  #5 {main}
    thrown

    at vendor/pestphp/pest/src/Plugins/Concerns/HandleArguments.php:24
       20▕             if ($arg === $argument) {
       21▕                 return true;
       22▕             }
       23▕
    ➜  24▕             if (str_starts_with($arg, "$argument=")) {
       25▕                 return true;
       26▕             }
       27▕         }
       28▕



  Error Output:
  ================
  PHP Fatal error:  Uncaught TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, int given in /private/tmp/repro
  /vendor/pestphp/pest/src/Plugins/Concerns/HandleArguments.php:24
  Stack trace:
  #0 /private/tmp/repro/vendor/pestphp/pest/src/Plugins/Concerns/HandleArguments.php(24): str_starts_with(1, '--help=')
  #1 /private/tmp/repro/vendor/pestphp/pest/src/Plugins/Help.php(35): Pest\Plugins\Help->hasArgument('--help', Array)
  #2 /private/tmp/repro/vendor/pestphp/pest/src/Plugins/Actions/CallsHandleArguments.php(29): Pest\Plugins\Help->handleArguments(Array)
  #3 /private/tmp/repro/vendor/pestphp/pest/bin/worker.php(74): Pest\Plugins\Actions\CallsHandleArguments::execute(Array)
  #4 /private/tmp/repro/vendor/pestphp/pest/bin/worker.php(105): {closure}()
  #5 {main}
    thrown in /private/tmp/repro/vendor/pestphp/pest/src/Plugins/Concerns/HandleArguments.php on line 24

How to Reproduce

cd /tmp && mkdir repro && cd repro
composer init --quiet --name pestphp/repro --require-dev pestphp/pest:^2.35 && composer config --quiet --no-plugins allow-plugins.pestphp/pest-plugin true && composer install --quiet
echo "no" | ./vendor/bin/pest --init
./vendor/bin/pest --parallel --random-order-seed=1 

Sample Repository

No response

Pest Version

2.35.1

PHP Version

8.3.9

Operation System

macOS

Notes

For some reason (I didn't dive any deeper) the HandleArguments plugin receives a different set of arguments when running single process (pest.php) compared to running in parallel processes (worker.php).
The latest receives --random-order-seed and the seed <N> as separate array items. Whereas the single process version it gets a single key --random-order-seed=<N>. This also explains the reason of the uncaught TypeError and why running with --random-order-seed=A12345 runs without the uncaught TypeError as the additional array item now is a string value.

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

No branches or pull requests

2 participants
@DannyvdSluijs and others