Skip to content

Errors during write of phpunit.xml are not handled correctly when --generate-configuration is used #5892

Closed
@JustasBalciunas

Description

@JustasBalciunas
Q A
PHPUnit version 11.2.6
PHP version 8.3.8
Installation Method Composer

Summary

After executed --generate-configuration shows Warning about Permission denied but shows message that Generated phpunit.xml in /var/www/html although file was not generated in /var/www/html.

Current behavior

docker@numbers:/var/www/html$ ./vendor/bin/phpunit --generate-configuration
PHPUnit 11.2.6 by Sebastian Bergmann and contributors.

Generating phpunit.xml in /var/www/html

Bootstrap script (relative to path shown above; default: vendor/autoload.php): vendor/testings.php
Tests directory (relative to path shown above; default: tests): testings
Source directory (relative to path shown above; default: src): .
Cache directory (relative to path shown above; default: .phpunit.cache):

Warning: file_put_contents(phpunit.xml): Failed to open stream: Permission denied in /var/www/html/vendor/phpunit/phpunit/src/TextUI/Command/Commands/GenerateConfigurationCommand.php on line 61

Generated phpunit.xml in /var/www/html.
Make sure to exclude the .phpunit.cache directory from version control.

docker@numbers:/var/www/html$ ls -l phpunit.xml
ls: cannot access 'phpunit.xml': No such file or directory

docker@numbers:/var/www/html$ ls -ld
drwxrwxr-x 12 root root 4096 Jul 8 08:22 .

How to reproduce

phpunit/phpunit/src/TextUI/Command/Commands/GenerateConfigurationCommand.php:61

<..>
		if(!file_put_contents(
			'phpunit.xml',
			$generator->generateDefaultConfiguration(
				Version::series(),
				$bootstrapScript,
				$testsDirectory,
				$src,
				$cacheDirectory,
			)
		)) {
			print PHP_EOL . "Unable to generate phpunit.xml in " . getcwd() . '.' . PHP_EOL;
			
			return Result::from();
		}
<...>

Expected behavior

Unable to generate phpunit.xml in /var/www/html.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions