You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a CI pipeline set up in GitHub Actions to run my Pest tests. While everything works as expected on my local machine, the pipeline fails with the following error:
INFO Could not read XML from file "--cache-directory".
The pipeline exits immediately after this error. I have attempted to change the cache directory and disable the cache altogether, but neither approach resolved the issue.
From my observations, when Pest is executed, it generates a configuration file .pest.xml in the current directory, containing the PHPUnit configuration in use. After the tests are completed, Pest deletes this file.
In the GitHub Action environment, it seems that Pest cannot generate or access this file, leading to the error mentioned above.
Is there a known workaround to ensure Pest can generate and use the .pest.xml file in the pipeline environment? If this behavior is intentional (i.e., not a bug but a feature), a more descriptive error message would be very helpful to guide users toward a resolution.
For further reference, here's my Pest configuration:
<?phpdeclare(strict_types=1);
useApp\Tests\Api\BaseApiCase;
useSymfony\Bundle\FrameworkBundle\Test\KernelTestCase;
useSymfony\Component\Dotenv\Dotenv;
if (method_exists(Dotenv::class, 'bootEnv')) {
if (is_array($_ENV) && array_key_exists('APP_ENV', $_ENV) === false) {
$_ENV['APP_ENV'] = 'test';
}
if (is_array($_SERVER) && array_key_exists('APP_ENV', $_SERVER) === false) {
$_SERVER['APP_ENV'] = 'test';
}
(newDotenv())->bootEnv(dirname(__DIR__).'/.env');
}
/*|--------------------------------------------------------------------------| Test Case|--------------------------------------------------------------------------|| The closure you provide to your test functions is always bound to a specific PHPUnit test| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may| need to change it using the "uses()" function to bind a different classes or traits.|*/pest()
->extends(KernelTestCase::class)
->in('Unit');
pest()
->extends(KernelTestCase::class)
->in('Integration');
pest()
->extends(BaseApiCase::class)
->in('Api');
/*|--------------------------------------------------------------------------| Functions|--------------------------------------------------------------------------|| While Pest is very powerful out-of-the-box, you may have some testing code specific to your| project that you don't want to repeat in every file. Here you can also expose helpers as| global functions to help you to reduce the number of lines of code in your test files.|*/
The text was updated successfully, but these errors were encountered:
Hi @Mareddie , I am experiencing the same issue on a project using Pest with GitHub Actions. Interestingly, I have other projects with a similar structure where the GitHub Actions workflow works fine.
To troubleshoot the problem, I am currently analyzing the PHP configuration of the runner and the PHP extensions being used. My initial thought was that the runner's PHP environment might be missing the XML extension, which could explain the issue.
I will also explore other configurations to better understand the root cause. My current approach is to align the configuration as closely as possible with my other projects where the GitHub Actions workflows are working as expected.
I will update here in case I will be able to find a proper configuration.
I am sharing some feedback here since I experienced the same issue.
Maybe my solution can help you solve it or at least better understand the problem.
I was a bit hesitant to share my solution at first because it turned out to be my own mistake 🤣 due to a configuration oversight in phpunit.xml and .gitignore. However, if it helps someone, I’m happy to share.
In my case, I had a phpunit.xml file locally that was ignored by Git due to .gitignore. Locally, the tests ran fine because they were automatically reading the local phpunit.xml. However, in the workflow that checked out the repository, the phpunit.xml file was missing, resulting in that "cryptic" error.
What I did to fix it was:
Create a phpunit.xml.dist file (with public configuration details suitable for the repository).
Commit this file to the repository.
Update the action to explicitly specify the configuration file using the --configuration option:
What Happened
I have a CI pipeline set up in GitHub Actions to run my Pest tests. While everything works as expected on my local machine, the pipeline fails with the following error:
INFO Could not read XML from file "--cache-directory".
The pipeline exits immediately after this error. I have attempted to change the cache directory and disable the cache altogether, but neither approach resolved the issue.
How to Reproduce
Run pest in Github Action
Sample Repository
No response
Pest Version
3.6.0
PHP Version
8.3.14
Operation System
Linux
Notes
From my observations, when Pest is executed, it generates a configuration file .pest.xml in the current directory, containing the PHPUnit configuration in use. After the tests are completed, Pest deletes this file.
In the GitHub Action environment, it seems that Pest cannot generate or access this file, leading to the error mentioned above.
Is there a known workaround to ensure Pest can generate and use the .pest.xml file in the pipeline environment? If this behavior is intentional (i.e., not a bug but a feature), a more descriptive error message would be very helpful to guide users toward a resolution.
For further reference, here's my Pest configuration:
The text was updated successfully, but these errors were encountered: