Laravel项目,简单测试,只尝试加载默认页面'/'
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);
}
}
通过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
通过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.
经过进一步调查......
也无法通过IDE找到Assert类。
查看作曲家自动加载器,正在加载的仅PHPUnit \ Framework类是“ForwardCompatibility / TestCase ??? !!!
3285'PHPUnit\\Framework\\TestCase' => $vendorDir . '/phpunit/phpunit/src/ForwardCompatibility/TestCase.php',
3825'PHPUnit\\Framework\\TestCase' => __DIR__ . '/..' . '/phpunit/phpunit/src/ForwardCompatibility/TestCase.php',
这是我的作曲家档案,好的措施......
{
"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
}
}
答案 0 :(得分:2)
升级到PhpSpec 3将解决您的依赖性问题。
较旧版本的PhpSpec不能与最新版本的PHPUnit一起安装,因为它们都需要不同版本的sebastian/exporter
。