[4.x] Github Workflow crashes: Could not read XML from file "--cache-directory"
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- github-actions, php
- Domain
- ci-cd, testing-qa
Research direction
Start by reproducing the GitHub Actions workflow with ./vendor/bin/pest --ci and inspect how the generated .pest.xml is handled. Compare the workflow environment with local execution, focusing on the reported --cache-directory XML error. Done means the workflow runs successfully or reports a clear, actionable error.
Written by the indexing model from the issue text.
Description
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.
name: Test backend
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- pre-main
workflow_dispatch:
concurrency:
group: ${{ github.event_name == 'pull_request' && 'pr-test-' || 'dispatch-test-' }}${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.workflow_run.id }}
cancel-in-progress: true
jobs:
run-backend-tests:
name: Run backend tests
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.4
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: ci_test
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: pcov
ini-values: memory_limit=512M, upload_max_filesize=64M, post_max_size=80M, max_execution_time=90
tools: composer, phpstan
env:
fail-fast: true
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist --optimize-autoloader --classmap-authoritative
- name: Run migrations
run: |
php bin/console doctrine:migrations:migrate --no-interaction --env test
env:
# Suffix _test is automatically appended for test environment. See config/doctrine.yaml
DATABASE_URL: mysql://root:root@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/ci
- name: Run tests
run: |
./vendor/bin/pest --ci
env:
# Suffix _test is automatically appended for test environment. See config/doctrine.yaml
DATABASE_URL: mysql://root:root@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/ci
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:
<?php
declare(strict_types=1);
use App\Tests\Api\BaseApiCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\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';
}
(new Dotenv())->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.
|
*/
- Dominant language
- PHP
- Stars
- 11.7k
- Forks
- 538
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pestphp/pest
-
[Bug]: [mutate] Windows: @pest-mutate-ignore comments land on line 1 in files with LF line endings Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
getgrav/grav-plugin-api#45 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
RSS-Bridge/rss-bridge#5098 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
phingofficial/phing#2025 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
silverstripe/developer-docs#911 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100