2
votes

When I run phpunit command it throws all info from phpunit help with PHPUnit 3.7.21 by Sebastian Bergmann. So I suggest it should work, but not yet;

when I run

phpunit ExampleTest.php
PHP Fatal error:  Class 'Tests\TestCase' not found in C:\xampp7\htdocs\projects\heroes\tests\Feature\ExampleTest.php on line 8

In Laravel I've got 'tests' folder with

TestCase.php
<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
}

folder 'Feature' with

ExampleTest.php

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}

and folder 'Unit'

In Laravel root folder I've got

composer.json




  {
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "^1.0",
        "laravelcollective/html": "^5.4.0",
        "laravelcollective/html": "~5.0"
    },
    "require-dev": {
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ],
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

I just simply need to start unit testing

3
and if you run phpunit without arguments?Quezler
as I wrote in the beggining it throws alot of info phpunit PHPUnit 7.1.5 by Sebastian Bergmann and contributors. Usage: phpunit [options] UnitTest [UnitTest.php] phpunit [options] <directory> Code Coverage Options:....Dima Rashevskiy
Please show full content of your composer.json.rob006
I added it higher, also when I run phpunit . it says PHP Fatal error: Class 'Tests\TestCase' not found in ExampleTest.php on line 8Dima Rashevskiy

3 Answers

4
votes

It looks like your using phpunit installed globally in your system, which is super old and it is not connected with your project autoloading. You should use phpunit installed in your project by Composer:

vendor/bin/phpunit
1
votes

When I run

vendor\bin\phpunit

It works, however It would be nice if somebody explained why

1
votes

You can use this

./vendor/bin/phpunit

like this it will run phpunit from the root of your application