Updating snapshots renders error on PHPUnit v8.0
Closed this issue · 1 comments
Update: This is most likely a issue with phpunit where the ini_set signature typehints string but phpunit sets boolean.
I have created an issue at phpunit
sebastianbergmann/phpunit#3535
Hello,
Thank you for an awesome library, I use it in many projects and I love it! Great job!
I have however encountered an error and I'm not sure if it is me or an actual bug but I thought I would share it here and see if you have an idea.
I started out with this configuration (from composer.json):
"require-dev": {
"phpunit/phpunit": "^7.1",
"spatie/phpunit-snapshot-assertions": "^1.3"
}
Updating snapshots works just fine:
$ vendor/bin/phpunit tests/src/MyClassTest.php -d --update-snapshots
1) MyClassTest::testResult
Snapshot updated for MyClassTest__testResult__1
...
However, after upgrading to newest version of phpunit and the snapshot assertion library (composer.json):
"require-dev": {
"phpunit/phpunit": "^8.0",
"spatie/phpunit-snapshot-assertions": "^2.1"
}
I got this error:
$ vendor/bin/phpunit tests/src/MyClassTest.php -d --update-snapshots
PHP Fatal error: Uncaught TypeError: ini_set() expects parameter 2 to be string, boolean given in /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/src/TextUI/Command.php:379
Stack trace:
#0 /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/src/TextUI/Command.php(379): ini_set('--update-snapsh...', true)
#1 /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/src/TextUI/Command.php(175): PHPUnit\TextUI\Command->handleArguments(Array)
#2 /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/src/TextUI/Command.php(164): PHPUnit\TextUI\Command->run(Array, true)
#3 /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#4 {main}
thrown in /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/src/TextUI/Command.php on line 379
Fatal error: Uncaught TypeError: ini_set() expects parameter 2 to be string, boolean given in /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/src/TextUI/Command.php on line 379
TypeError: ini_set() expects parameter 2 to be string, boolean given in /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/src/TextUI/Command.php on line 379
Call Stack:
0.0005 395656 1. {main}() /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/phpunit:0
0.0038 853360 2. PHPUnit\TextUI\Command::main() /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/phpunit:61
0.0038 853472 3. PHPUnit\TextUI\Command->run() /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/src/TextUI/Command.php:164
0.0038 853472 4. PHPUnit\TextUI\Command->handleArguments() /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/src/TextUI/Command.php:175
0.0041 881392 5. ini_set() /Users/oli/PhpstormProjects/refactoring/vendor/phpunit/phpunit/src/TextUI/Command.php:379
Variables in local scope (#4):
$argv = array (0 => 'vendor/bin/phpunit', 1 => 'tests/src/MyClassTest.php', 2 => '-d', 3 => '--update-snapshots')
$bootstrapScript = *uninitialized*
$configuration = *uninitialized*
$configurationFile = *uninitialized*
$file = *uninitialized*
$generator = *uninitialized*
$handler = *uninitialized*
$includePath = *uninitialized*
$ini = array (0 => '--update-snapshots')
$option = array (0 => 'd', 1 => '--update-snapshots')
$optionName = *uninitialized*
$phpunitConfiguration = *uninitialized*
$src = *uninitialized*
$t = *uninitialized*
$test = *uninitialized*
$testSuite = *uninitialized*
$testsDirectory = *uninitialized*
Tried on two PHP versions (7.2.9) and (7.3.2), both throw the same error.
I also set the second parameter to string in phpunit (/TextUI/Command.php:379)
\ini_set($ini[0], "");
That solved the problem, although I'm not sure where in the problem lies since looking at the source in phpunit reveals this portion of the code hasn't been changed for years.
https://github.com/sebastianbergmann/phpunit/blame/master/src/TextUI/Command.php#L373
Fixed in sebastianbergmann/phpunit@adfe5c2