Laravel project, simple test, only tries to load the default page '/'
SIMPLE TEST
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
ERROR MESSAGE via PhpStorm
Class 'PHPUnit\Framework\Assert' not found
/var/www/vhosts/app-native/app-app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:52
/var/www/vhosts/app-native/app-app/tests/Feature/ExampleTest.php:21
ERROR MESSAGE via CLI
# php vendor/phpunit/phpunit/phpunit
PHPUnit 5.6.4 by Sebastian Bergmann and contributors.
EEE.. 5 / 5 (100%)
Time: 1.78 seconds, Memory: 16.00MB
There were 3 errors:
1) Tests\Feature\ExampleTest::testBasicTest
Error: Class 'PHPUnit\Framework\Assert' not found
/var/www/vhosts/app-native/app-app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:52
/var/www/vhosts/app-native/app-app/tests/Feature/ExampleTest.php:21
2) Tests\Feature\JsonTest::testSignup
Error: Class 'PHPUnit\Framework\Assert' not found
/var/www/vhosts/app-native/app-app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:52
/var/www/vhosts/app-native/app-app/tests/Feature/JsonTest.php:29
3) Tests\Feature\RoutesTest::testBasicTest
Error: Class 'PHPUnit\Framework\Assert' not found
/var/www/vhosts/app-native/app-app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:52
/var/www/vhosts/app-native/app-app/tests/Feature/RoutesTest.php:21
ERRORS!
Tests: 5, Assertions: 2, Errors: 3.
Upon further investigation...
The Assert class is not found via the IDE either.
Looking into the composer autoloader, the only PHPUnit\Framework classes being loaded is the "ForwardCompatibility/TestCase ???!!!
3285'PHPUnit\\Framework\\TestCase' => $vendorDir . '/phpunit/phpunit/src/ForwardCompatibility/TestCase.php',
3825'PHPUnit\\Framework\\TestCase' => __DIR__ . '/..' . '/phpunit/phpunit/src/ForwardCompatibility/TestCase.php',
Here is my composer file, for good measure...
{
"name": "app/webapp",
"description": "app Web App (API & Frontend).",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "~5.0",
"laracasts/flash": "~1.3",
"maatwebsite/excel": "~2.1",
"guzzlehttp/guzzle": "~6.2",
"doctrine/dbal": "~2.5",
"laravel/cashier": "~7.0",
"league/flysystem-aws-s3-v3": "~1.0",
"zizaco/entrust": "1.7.0",
"barryvdh/laravel-ide-helper": "^2.2",
"blueimp/jquery-file-upload": "^9.14",
"ipunkt/laravel-analytics": "^1.3",
"braintree/braintree_php": "^3.21",
"tymon/jwt-auth": "0.5.*",
"f2m2/apidocs": "~2.0",
"barryvdh/laravel-cors": "0.8.*",
"pulkitjalan/geoip": "~2.4",
"aws/aws-sdk-php-laravel": "^3.1",
"vsmoraes/laravel-pdf": "^1.0",
"propaganistas/laravel-phone": "^2.8",
"activecampaign/api-php": "~2.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5",
"phpspec/phpspec": "~2.1",
"ozankurt/repoist": "^1.0",
"symfony/dom-crawler": "~3.1",
"symfony/css-selector": "~3.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan ide-helper:generate",
"php artisan ide-helper:meta",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan ide-helper:generate",
"php artisan ide-helper:meta",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true
}
}
install via composer
run phpunit default tests.
php vendor/phpunit/phpunit/phpunit
THIS HELPS .. but it is a hack...
removed use PHPUnit\Framework\Assert as PHPUnit;
replacing PHPUnit:: with \PHPUnit_Framework_Assert:: in the file ... vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php
This happened to me after upgrading to 5.4 as well.
Solved by:
"phpunit/phpunit": "~5.7" instead of 5.0phpspec/phpspec from composer.json altogethervendor/bin/phpunit instead of phpunitThe last step is probably the most important.
YEP!
phpspec is forcing phpunit back to version 5.6.4....
there is an issue there somewhere...
these are the updates with phpspec.....
Package operations: 10 installs, 0 updates, 0 removals
without phpspec
Package operations: 0 installs, 5 updates, 2 removals
i was already running the vendor version of phpunit, so it is really the phpspec/phpspec package that part of the issue, via itself or it's requirements...
Pavol Tanuška solved it, thanks!!
PhpSpec 3, which was released early last summer, works fine with recent versions of Laravel. You may, however, have trouble using brand new versions of PHPUnit and a very old version of PhpSpec, as they both require different versions of sebastian/exporter. I recommend upgrading to a recent version of PhpSpec.
Thanks Sam.
https://github.com/phpspec/phpspec/issues/1060
Been searching for a while pavoltanuska it worked
Most helpful comment
This happened to me after upgrading to 5.4 as well.
Solved by:
"phpunit/phpunit": "~5.7"instead of 5.0phpspec/phpspecfrom composer.json altogethervendor/bin/phpunitinstead ofphpunitThe last step is probably the most important.