pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.58k stars 356 forks source link

"The class `Tests\TestCase` was not found." - on CI (Docker) #220

Closed Enaah closed 3 years ago

Enaah commented 3 years ago

Hi there,

so here's my situation:

What I did to debug:

  1. Used php artisan test instead of ./vendor/bin/pest
  2. I did all the commands to debug:
    php artisan clear
    php artisan cache:clear
    php artisan config:clear
    composer dump-autoload

    even did a fresh cloning of the repo.

  3. removed all test but one example test

Screenshots/Errors

CI with ./vendor/bin/pest Bildschirmfoto 2020-11-18 um 12 38 32

local with ./vendor/bin/pest Bildschirmfoto 2020-11-18 um 12 43 53

CI with php artisan test Bildschirmfoto 2020-11-18 um 12 55 26

local with php artisan test Bildschirmfoto 2020-11-18 um 12 43 38

CI with PHPUnit (before Pest was used) Bildschirmfoto 2020-11-18 um 13 10 38

local with PHPUnit (before Pest was used) Bildschirmfoto 2020-11-18 um 13 03 09

File-contents

tests\Pest.php

<?php

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

// Uses the given test case and trait in the current folder recursively
uses(TestCase::class, RefreshDatabase::class)->in(__DIR__);

tests\TestCase.php

<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
}

tests\Helpers.php

<?php

namespace Tests;

use Illuminate\Contracts\Auth\Authenticatable;

/**
 * A basic assert example.
 */
function assertExample(): void
{
    test()->assertTrue(true);
}

function actingAs(Authenticatable $user, string $driver = null)
{
    return test()->actingAs($user, $driver);
}

tests\CreateApplication.php

<?php

namespace Tests;

use Illuminate\Contracts\Console\Kernel;

trait CreatesApplication
{
    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';

        $app->make(Kernel::class)->bootstrap();

        return $app;
    }
}

tests\Unit\ExampleTest.php

<?php

test('basic', function () {
    assertTrue(true);
});

tests\CreateApplication.php

<?php

namespace Tests;

use Illuminate\Contracts\Console\Kernel;

trait CreatesApplication
{
    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';

        $app->make(Kernel::class)->bootstrap();

        return $app;
    }
}

tests\Unit\ExceptionTest.php

<?php

it('throws exception', function () {
    throw new Exception('Something happened.');
})->throws(Exception::class, 'Something happened.');

Do I miss anything?

Went through the docs 2 times and couldn't find anything.

Thanks in advance!

octoper commented 3 years ago

@Enaah Have you installed Pest for Laravel correctly?

Enaah commented 3 years ago

I hope so.

Pulled it via composer and did php artisan pest:install. It was working on my computer, but CI did not want to work.

Will try it again, later.

Enaah commented 3 years ago

Found the error... it was me. As usual.

Sorry for disturbance and thanks for this project 💐