Framework: PHPUnit Failed

Created on 7 Feb 2017  ·  7Comments  ·  Source: laravel/framework

  • Laravel Version: v5.4.9
  • PHP Version: 7.1.1
  • Database Driver & Version: n/a

Description:

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

Steps To Reproduce:

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/T‌​estResponse.php

Most helpful comment

This happened to me after upgrading to 5.4 as well.

Solved by:

  • requiring "phpunit/phpunit": "~5.7" instead of 5.0
  • removing phpspec/phpspec from composer.json altogether
  • running vendor/bin/phpunit instead of phpunit

The last step is probably the most important.

All 7 comments

This happened to me after upgrading to 5.4 as well.

Solved by:

  • requiring "phpunit/phpunit": "~5.7" instead of 5.0
  • removing phpspec/phpspec from composer.json altogether
  • running vendor/bin/phpunit instead of phpunit

The 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

  • Installing phpspec/prophecy (v1.6.2) Downloading: 100%
  • Installing phpspec/php-diff (v1.0.2) Loading from cache
  • Installing phpspec/phpspec (2.5.5) Loading from cache
    Skipped installation of bin bin/phpspec for package phpspec/phpspec: name conflicts with an existing file
  • Installing phpunit/php-text-template (1.2.1) Downloading: 100%
  • Installing phpunit/phpunit-mock-objects (3.4.3) Downloading: 100%
  • Installing phpunit/php-timer (1.0.8) Downloading: 100%
  • Installing phpunit/php-file-iterator (1.4.2) Downloading: 100%
  • Installing phpunit/php-token-stream (1.4.9) Downloading: 100%
  • Installing phpunit/php-code-coverage (4.0.5) Downloading: 100%
  • Installing phpunit/phpunit (5.6.4) Loading from cache

without phpspec

Package operations: 0 installs, 5 updates, 2 removals

  • Removing phpspec/php-diff (v1.0.2)
  • Removing phpspec/phpspec (2.5.5)
  • Updating blueimp/jquery-file-upload (v9.14.2 => v9.15.0) Downloading: 100%
  • Updating sebastian/recursion-context (1.0.2 => 2.0.0) Downloading: 100%
  • Updating sebastian/object-enumerator (1.0.0 => 2.0.0) Downloading: 100%
  • Updating sebastian/exporter (1.2.2 => 2.0.0) Downloading: 100%
  • Updating phpunit/phpunit (5.6.4 => 5.7.11) Downloading: 100%

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.

Been searching for a while pavoltanuska it worked

Was this page helpful?
0 / 5 - 0 ratings