Summary
I have a package that needs to be wrapped by a real laravel app to be tested properly. Unfortunately I cant use the orchestra testbench. However I have setup a Github action for this. But, when running the final step vendor/phpunit/phpunit/phpunit path/to/package im experiencing the following issues:
- PHPUnit can't resolve certain classes
- It thinks PHPUnit
setUp()is public in my parent class though it is protected. - I suspect some issue with caching or delay after push (but I have tested wiping all cache, autoload and config)
Example error
Run vendor/phpunit/phpunit/phpunit packages/Ajthinking/PHPFileManipulator/tests
PHP Fatal error: Uncaught Error: Class 'PHPFileManipulator\Tests\FileTestCase' not found in /home/runner/work/php-file-manipulator/php-file-manipulator/host/packages/Ajthinking/PHPFileManipulator/tests/Unit/APIDelegationTest.php:10
Stack trace:
#0 /home/runner/work/php-file-manipulator/php-file-manipulator/host/vendor/phpunit/phpunit/src/Util/FileLoader.php(59): include_once()
#1 /home/runner/work/php-file-manipulator/php-file-manipulator/host/vendor/phpunit/phpunit/src/Util/FileLoader.php(47):
Reviewing my master branch, the requested file FileTestCase is there.
The full action script:
name: Laravel-wrapped-package-test
on: [push]
jobs:
laravel-tests:
runs-on: ubuntu-latest
steps:
- name: Install host app
run: composer create-project --prefer-dist laravel/laravel host
- name: Install package (this repo)
uses: actions/checkout@v2
with:
path: host/packages/Ajthinking/PHPFileManipulator
- name: Add this package to composer.json repositories
uses: ajthinking/[email protected]
with:
repo_relative_path: 'host/packages/Ajthinking/PHPFileManipulator'
- name: Require this package
working-directory: ./host
run: composer require ajthinking/php-file-manipulator @dev
- name: Publish things
working-directory: ./host
run: php artisan vendor:publish --provider="PHPFileManipulator\ServiceProvider"
- name: Run tests
working-directory: ./host
run: vendor/phpunit/phpunit/phpunit packages/Ajthinking/PHPFileManipulator/tests
TestCase
Below is my base test case. But the setUp method is never called. (Previously it was called TestCase as the default laravel provides - it was renamed while debugging)
<?php
namespace PHPFileManipulator\Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class FileTestCase extends BaseTestCase
{
protected function setUp() : void
{
parent::setUp();
dd("it will never reach this dd call on github actions!");
}
}
Usage:
<?php
namespace PHPFileManipulator\Tests\Unit;
use PHPFileManipulator\Tests\FileTestCase;
class StupidTest extends FileTestCase
{
/** @test */
public function it_can_run_tests()
{
$this->assertTrue(true);
}
}
versions
Im using PHP 7.4.2 and PHPUnit 8.5.2 (same as github actions ubuntu-latest) Mimicing the action script on my own machine works fine. I have reviewed CASE on github/local found no differences.
Any ideas, what I am missing?
"autoload-dev": { "classmap": [ "tests/TestCase.php" ] },composer.jsonfile. Wouldn't be easier to just runcomposer installfrom your CI script to install all the necessary dependencies and runvendor/bin/phpunitfrom there (package root) instead of creating a fresh laravel project, installing your package and running the tests from a subfolder?