m2mdas / phpcomplete-extended

A fast, extensible, context aware autocomplete plugin for PHP composer projects with code inspection features.
MIT License
216 stars 23 forks source link

PHP completion does not work in the test/ folder of a laravel project #26

Closed jansenm closed 10 years ago

jansenm commented 10 years ago

Hi

Thx for the great plugin. Unfortunately it currently only works in the app/controller, app/models and perhaps some others for me. But not in app/tests.

One problem i can see is a message PHP Fatal error: Class 'PHPUnit_Framework_TestCase' not found in .../vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php on line 6

on the terminal when writing a test file (eg. app/tests/TestCase.php). I fixed that with declaring a alias in app/config/app.php but still no useful autocompletion. This is a laravel app btw.

Any ideas?

m2mdas commented 10 years ago

Yes this is a problem actually. It is actually related to how I index classes. Currently I am using PHP's built in ReflectionClass, ReflectionMethod etc to get info of a class. As PHPUnit is not set up so the indexer script obviously returns error. Have to find a workaround of the problem.

m2mdas commented 10 years ago

Hmm, it's been a long time since I checked PHPUnit installation documentation. PHPUnit is now composer compatible it seems. All you have to do is add following lines in composer.json

"require-dev": {
     "phpunit/phpunit": "3.7.*"
}

And run composer update command. Previously I ignored test case files for indexing. Now I have pushed update which will index test case files if PHPUnit classes are found in autoload classmap. Please update phpcomplete-extended and run :PHPCompleteExtendedGenerateIndex to see it is working for you.

jansenm commented 10 years ago

That unfortunately is only half of the fix. Laravel by default does not add app/tests into the autoloader. Which means the don't get added to the classmap and indexed even after this (apart from app/test/TestCase.php which is loaded explicitely).

To get it going i have to add the app/tests directory to the classmap (composer.json)

    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests"
        ],
   }

But i can live with that solution. If i understand correctly how your plugin works you can't fix it in the plugin anyway.

On a development branch i put the tests/ directory in the autoload and on production branch i remove them.

Thx. Works for me like that.