2

I'd like to use PHPUnit autocompletion in my project. For some unknow reason it is works at home but not in at workplace.

enter image description here

As you see I've added the following directories to the Include Path:

D:\phpunit
D:\phpunit\vendor\phpunit
D:\phpunit\vendor\phpunit\phpunit\src\Framework\Assert

Before this I played with some more directory. I also tried to add it to the Global PHP Inlcude path with no success.

Of course the tests are works, the D:\phpunit\ in the path. I can not figure out why autocompletiotion not works.

2 Answers 2

4

EDIT:

when reading through the question I assumed your path of D:\phpunit\ is for phpunit.phar or test files or smth like that. But the last line of inlcudes makes me think you've cloned the sources of phpunit. This way it certainly should work, since sources are on the include path. But I wonder why are there include #2 and #3? They are in the first path already. Maybe NB is getting confused some way with all this multiple nested stuff? Personally I have used the way described below with almost all version of PHPUnit starting from 4.8 on both Linux and Windows of different versions, using both Netbeans 8.1 and 8.2. Netbeans's autocompletion always did work even for database testcases (which are usually the 4-th child from the very base class). Comparing to NB, Komodo IDE never could manage to pick those up.

Original answer:

PHPUnit is regularly distributed via .phar archive which is also executable. All PHPUnit files are packed inside. As far as I know Netbeans won't support file lookup in archives like .phar. So if you want to enable that, I suggest doing

// assuming that phpunit.phar is in the current directory
$phar = new Phar('phpunit.phar');
$phar->extractTo('PHPUnit/');

This can be done via creating a php script and executing it or directly in the console in interactive mode.

Then in Netbeans you should go to the menu Tools -> Options -> PHP tab -> General tab and add a global include path to the folder where you've just extracted the files (smth like /home/blah/blah/blah/PHPUnit or whatever it is).

The steps above do not affect how phpunit is actually run, it is only to enable Netbeans to do lookup for autocompleting.

Concerning the second thing you've mentioned -- class naming and namespacing:

PHPUnit's units of code are now namespaced. For instance, PHPUnit_Framework_TestCase is now PHPUnit\Framework\TestCase

(taken from original source https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-6.0.0)

And the last one: as far as I remember phpunit skeleton generator is abandoned very long time ago so it might be useful to rethink of its usage.

Sign up to request clarification or add additional context in comments.

2 Comments

Those other dirs was just try, I saw intresting things on windows even if I know what an include path means. The problem is that no PHPUnit_Framework_TestCase exists. Please read my answer. Anyway, I downloaded through composer, the skeleton is from phpunit.de.
Fwiw there is no reason this would not work in Komodo IDE, but depending on your setup you may need to do some additional configuration (set an import directory).
0

Usualy when I figure out the answer for my question, I delete that question if the answer was so obvious or it was just a typo, but I do not do it now. The reason for this that the solution is not so obvious, and it could be handy for others.

I am using Netbeans 8.2

When you use netbeans, and want to set PHPUnit, you can set the:

Options -> PHP -> Framework & Tools -> PHPUnit

One of the input field called: Skeleton Generator script.

This script helps you create a sekeleton when you create a new test from netbeans.

The only one you need to add to the Include Path is the path to your PHPUnit directory, for me it's: D:\phpunit

The test file start like this:

<?php

/**
 * Generated by PHPUnit_SkeletonGenerator on 2017-03-06 at 15:56:58.
 */
 class AbcTest extends PHPUnit_Framework_TestCase {

Sadly, you can not change it, because it is in the phpunit-skelgen-2.0.1.phar, what won't work if you made some changes in it. There is an integrity check what prevents you to change the contents of the file.

So, the problem is that there is no class like this:

PHPUnit_Framework_TestCase

I think there is an autoloader method what turns it to \PHPUnit\Framework\TestCase.

The solution is to change the word after extends to this:

class AbcTest extends PHPUnit\Framework\TestCase

or

use PHPUnit\Framework\TestCase;
class AbcTest extends TestCase {

After this, when you start to type $this-> you will get the autocomplete list.

1 Comment

That didn't work for me. Unpacking phar and pointing to unpacked folder in include path works better. You can also use PHPUnit_Framework_TestCase as generated by skeleton script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.