booni3's avatar

PHPUnit Assert Code Completion

I am using Laravel valet and have setup my PHP Storm as follows:

  1. Kept the default phpunit.xml file apart from updating the db_connection to sqlite and db_database to :memory:

  2. PHPUnit is installed with composer and setup in the PHP Storm languages and frameworks. PHPUnit version is showing as 7.4.3 so assume this means it is installed correctly.

  3. Set the default configuration file to phpunit.xml

  4. Set a PHPStorm/PHPUnit Run/Debug Configuration. Se the test runner scope to "Defined in the configuration file".

I can now run tests from within phpstorm and they run correctly.

However, as far as I understand I should now be able to see all the phpunit assertions $this->assertTrue(); within my tests under code completion. I cannot... Any ideas why?

I read about a bug in PHPStorm 2016 where you have to press the spacebar first to get the static methos showing in code completion, but this does not help.

0 likes
6 replies
Sinnbeck's avatar

Are you sure your test file is extending phpunit?

Can you show the content of the file?

(I have the same setup and it works)

booni3's avatar

Thanks for this quick reply!

I have

<?php

namespace Tests\Unit;

use App\MessageSchedule;
use Carbon\Carbon;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class MessageScheduleHashTest extends TestCase
{
    use WithFaker, RefreshDatabase;

    public function setUp()
    {
        parent::setUp();
    }
...
namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
}

Then its into the Framework abstract Test case that extends PHPUnit\Framework\TestCase

booni3's avatar

I have just tested the same setup in another project and that seems to work fine. I deleted the .idea folder and re-setup the first project but still no luck getting auto-completion.

booni3's avatar
booni3
OP
Best Answer
Level 3

Update: Turns out deleting the .idea folder, waiting for it to re-index, setting up the testing environment again AND restarting PHP Storm got them back to autocomplete!

Sinnbeck's avatar

If it happens again, just try invalidation cache (File menu)

Please or to participate in this conversation.