0
votes

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.

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
    }
}
1
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 - Artistan

1 Answers

2
votes

Upgrading to PhpSpec 3 will solve your dependency problem.

Older versions of PhpSpec can't be installed alongside very recent versions of PHPUnit, as they both require different versions of sebastian/exporter.