I am trying to run my test file, ImportCSVTest.php with the command ./vendor/bin/phpunit --filter=testNoImportFile
but I get the error of
/usr/bin/php declares an invalid value for PHP_VERSION.
This breaks fundamental functionality such as version_compare().
Please use a different PHP interpreter.
My test file, ImportCSVTest.php is as follows
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Tests\TestCase;
class ImportCSVTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testNoImportFile()
{
Storage::fake('products');
$response = $this->json('POST', '/import', [
'csv' => UploadedFile::fake()->create('emptyUpload', 0, null)
]);
Storage::disk('products')->assertMissing('emptyUpload');
}
}
First time I am coming across an error like this, how does one fix this?
PHPUnit refuses to be run with a PHP interpreter where the value of the PHP_VERSION constant contains an invalid value due to modification made by vendors that ship (binary) distributions of PHP.
7.3.24-(to be removed in future macOS) is such an invalid value. The -(to be removed in future macOS) suffix was added by Apple, who is the vendor of the PHP interpreter binary you use.
Here is a great article that explains the background. Here is the ChangeLog for PHPUnit 8.5.17. Here is the ChangeLog for PHPUnit 9.5.6. These are the first versions of PHPUnit that check for invalid values of PHP_VERSION on startup.
TL;DR: Do not use the PHP interpreter that is shipped by Apple with macOS. Use Homebrew, or similar, instead.