NetBeans, code completion for PHPUNit not working. (Windows) - php

I've followed these steps to get PHPUnit working in NetBeans in windows:
Download PHPUnit.phar and save to c:\phpbin
Follow instructions under the Windows heading here
Set up PATH variables and NetBeans global/project settings
Everything's working, except I don't have code completion working for PHPUnit. For example, if I type:
$this->asser
I would expect it to show a list of the various assert statements. But it doesn't.
I tried following this guide to get it working, but I don't know where the PHPUnit source files are, so I cannot add it to NetBean's PHP Global Include Path as per the instructions.
Where are the source files? Or is there another way for autocompletion to be correctly configured?
Thanks

You should have the PHP Windows installation. When I last did this using PEAR (which is deprecated) PHPUnit was installed under the root of the PHP web server. I would bet that PHAR puts it in the same place.
Once that is done, you typically have to set up a bootstrap that tells Netbeans where to look for executables, directories and such. Oddly enough the Netbeans tutorial doesn't mention that you have to extend the PHPUnit class for your test. That should give you the autocomplete you seek.
class ClassTest extends PHPUnit_Framework_TestCase {
}

Related

VSCode PHP Intelephense doesn't detect my libraries

I'm switching from PhpStorm to VSCode for my PHP development and I have a problem: For my multi-root workspace, it only detects the classes from the current repository, not all the other repos and libraries from my project. For example, when trying to autocomplete a class, Go to Definition, etc.
I'm developing a TYPO3 project, using composer. Therefore, the structure of the nested projects is this one:
path-to-html/
path-to-html/public/typo3conf/ext/{extension1, extension2, etc.}
I've installed the VSCode PHP Intelephense extension and configured it according to its description. But, as I've said, I only get completion for symbols of the current repository, not of all the libraries of the TYPO3 project. How should I configure this?
I've read all the Intelephense options and I've tried setting these ones:
"settings": {
...
"intelephense.environment.documentRoot": "/path-to-html",
"intelephense.environment.includePaths": [
"/path-to-html/public/typo3conf/ext/extension_1",
...
]
}
But it still doesn't work.
Disclaimer: I also have "PHP Intellisense" installed. The context menu items such as "Go to Defintion" or "Go to declaration" etc only work correctly, when I use enable both extension. Maybe it has to do with the fact that "PHP Intellisense" also uses the Language Server Protocol, but the implementation of the LSP is provided by "PHP Intelephense". Admittedly I don't understand it fully, .
In any case, these "PHP Intelephense settings" work for me.
I am using these settings right now for a local TYPO3 CMS 10 version, ddev-based.
I'll provide it here as a screenshot because these are VSCode Workspace Settings, and I cannot fgure out where VSCode stores these. (They are not stored in the $HOME/.config/Code/Usersettings.json file).
I think I could have used $HOME/ddev/typo3-10/public/typo3/sysext/ instead of $HOME/ddev/typo3-10/public/typo3/. Havent't tries
Key is,
Intelephense needed a few minutes to pick up the settings after changing them. It does not happen instantly that the red wiggly lines disappear
Needless to say, "Go to Definition" (opens a Doc-preview Window), "Go to Declaration" (Opens the PHP Class File), etc, are only enabled for Intelephense Premium.
No need to install, while it is supposed to be there and the html is useless.
The config needs to include the sources; eg.:
"intelephense.environment.includePaths": [
"../../typo3_src/typo3_src-8.7.44"
]
Also see: https://github.com/bmewburn/vscode-intelephense/issues
I just quit VS Code and re-open it. VS Code will open in the exact state it was in on quit. And Intelephense will have scanned the vendor folder. No need for any config changes.

How to have eclipse resolve php classes in MongoDB\BSON namespace?

After many comes and goes I managed to install the MongoDB Driver for PHP 5.6 and made it work on OSX El Capitan. (The way it worked was using Homebrew)
To start working on a project I created the folder for the project and using Composer installed the required packages I needed. Between theese packages I required mongodb/mongodb which is the recomended mongo php library to use by the php Manual on line and in the driver github page.
The problem I found is that Eclipse is resolving the classes in the \MongoDB\ namespace but not in the \MongoDB\BSON\ namespace. If I check what Composer installed in the vendor folder I am able to see that the \MongoDB\BSON\ classes in fact are missing. On the other hand if I run the program in the PHP included webserver, it executes as expected.
So my question is how can do or what am I missing for Eclipse to find the missing classes. Are they defined somewhere else?
If this is not possible because they are compiled into a binary library and I have no way to resolve them, Is there any way to have Eclipse not showing these particular classes as mistakes?
Example of class that runs ok in the webserver, but is highlighted as an error in Eclipse:
$fecha_creacion = new MongoDB\BSON\UTCDateTime();
Reading this post and not finding anything newer on the subject I arrived to the conclusion that developers of the driver don't provide the php sources and leave it to the IDE developers to provide STUBs for the different fuctions of the driver in a way the IDE can recognize the functions and provide syntax checking and documentations popups.
Following this question, I finally ended up finding a JetBrains GitHub where there are many different stubs for PHPStrom, this one among them.
So I copied the file and added it to my project as part of the sources. And that solved my problem.

Eclipse MakeGood Error: PHPUnit_Framework_TestCase class is not available

I've been having an issue setting up XDebug (2.6.0) to work with PHPUnit (6.0.13) in Eclipse Neon (4.6.3). I've had XDebug working within my browser, and have had PHPUnit working from the command line, however am unable to get the two working together.
I'm working within a Vagrant VM running Ubuntu, with OSX as my main system.
XDebug is installed globally through Vagrant and PHPUnit is installed via Composer. In my Project Settings, I have pointed a PHP Executable to /usr/bin/php, using the system default .ini file., however this is the file on my machine, rather than the file on the VM, so I don't know if I need to adjust this, but nothing I read mentioned it?
The issue I am having is that my 'MakeGood' tab is showing the error 'PHPUnit_Framework_TestCase class is not available. Fix...' even though I have included the vendor/autoload.php file within the Project Preferences. I have also tried setting up a custom library pointing towards the vendors/ folder, as I saw suggested on a blog post, however it didn't help anything. So any suggestions as to what else to try would be greatly appreciated.
I've tried looking around on here and further across the web, and most of the resources I can find talk only about setting it up referencing through PEAR, however that obviously doesn't work with Composer.
As always, thanks for any help you can provide.
Edit: Just in case it makes any difference, my tests are stored in tests/, with the namespace \App\Test and my classes in resources/src/ with the namespace \App.

I've installed PHPunit on my system and set the settings in Netbeans but i still can't create PHPUnittests

Well title says most of it. I have installed Netbeans 8.0.1 then i've installed both the skeleton generator and the phpunit using PEAR. All the .bat files are in the C:/bin. When i go to the Netbeans settings of phpunit and add both the .bat files in the right place i still can't use PHPUnit. Even when i try to do what is written in the tutorials and clicking my right mouse button on a class i still can't create a PHPUnit test nor can i use any of the annotations that should be available after installation of PHPUnit

How do I successfully create a project with Zend Framework and PHPUnit?

Let me just start by saying that I've posted this to multiple forums and even tried to get help on the ZF IRC channel. I've been Googling for a straight week and still no results. I've read a lot of Q's and A's on this site in the past, so I figured I'd make an account and try asking you.
(Yes, I've searched previously asked questions, but none of the answers helped me.)
I'm trying to learn how to use Zend Framework for a new project that I've joined. For compatibility reasons they are using Zend 1 (and not the newer Zend 2). I have found and followed a number of online and physical book tutorials but I've the same results over and over again.
So here goes (this are the instructions that all the tutorials give). I went to framework.zend.com and downloaded the full version of ZF 1.12.
I unzipped the contents
I moved the library folder to a safe directory where it won't be modified
I moved the contents of the bin folder to same directory as my PHP executable
I changed the include_path in my php.ini file to include the library directory
I updated my Windows PATH variable to make sure it included the path to the PHP executable
I ran
zf --help
This command worked as intended. I also successfully ran zf show version (Zend Framework Version 1.12.7).
I ran the command
zf create project myproject
Upon doing this, I receiving the following error message:
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in D:\Zend\library\Zend\Test\PHPUnit\ControllerTestCase.php on line 48
That particular line in question is a class declaration that extends PHPUnit_Framework_TestCase. I don't know where PHPUnit_Framework_TestCase is defined. It is not in any of the files or directories that came in the single ZIP file that I downloaded from Zend. I even ran grep on all files and folders searching for the string "class PHPUnit_Framework_TestCase" but it printed no results.
Some have suggested that I don't have PHPUnit installed (which is obvious to me now). The part that bugs me is that absolutely none of the tutorials that I read mention anything about installing PHPUnit before hand or how to install it or what dependencies Zend has on it. Many of these were beginner tutorials that assumed you only had a basic knowledge of PHP, and it's pretty shocking to me that none even mentioned PHPUnit. If PHPUnit was that important I would think that the file I downloaded from Zend would have included it. I guess not.
So I went online again and got the PHAR file for PHPUnit, but now what? I tried putting it in multiple different directories but I still get the same error. Am I not supposed to use a PHAR file? Should I be using the actual files instead?
What do I have to do to get ZF to recognize PHPUnit, resolve this error and create my first ZF project?
Additional Info:
Windows 7, XAMPP Server (running on localhost), PHP 5.5.6
Assuming you have PHPUnit installed and it is on your include path (Bearing in mind that ZF1 only officially supports PHPUnit 3.4.x and definitely doesn't support anything above PHPUnit 3.5.x, so if you're using XAMPP you may have to downgrade PHPUnit as described here). The problem is most probably due to this commit, where the require calls for PHPUnit were stripped out in favour of using an autoloader. The ZF tool over CLI doesn't set up an autoloader though, so PHPUnit is not found because it is simply not required! To fix you can return these lines to the start of Zend/Test/PHPUnit/ControllerTestCase.php
/** #see PHPUnit_Runner_Version */
require_once 'PHPUnit/Runner/Version.php';
/**
* Depending on version, include the proper PHPUnit support
* #see PHPUnit_Autoload
*/
require_once (version_compare(PHPUnit_Runner_Version::id(), '3.5.0', '>=')) ? 'PHPUnit/Autoload.php' : 'PHPUnit/Framework.php';
It's worth noting that even with the error you mention, ZF tool should still work correctly when setting up a project, it just won't produce unit test actions (you'll have to make them yourself). If you don't want to downgrade your XAMPP PHPUnit version you should be able to add the correct version locally to your project using composer as described here.
Update Jan 2015:
Downgrading PHPUnit for XAMPP is no longer necessary as ZF1 has supported at least version 4.1 of PHPUnit since 1.12.7 (I've not tested above 4.1). This is helpful as PHPUnit has completely removed their deprecated Pear repository as of December 2014, which means you can't download versions older than 3.7 anymore anyway! (Currently XAMPP ships with PHPUnit 3.6). These days though it's probably worth chucking XAMPP for Vagrant and globally installing PHPUnit 4.1 via Composer during Vagrant provisioning.
I recommend using Composer to load both ZF and PHPUnit. Then make sure to include the Composer autoload.php file as your/in your phpunit boostrap file.
I had the same problem when I set up my laptop as a second development machine and downloaded the newest version of Zend Framework 1 (1.12.9). Whenever I tried to create a new action in a controller, I got the same error. Yet on my main computer, it worked fine.
I realized it was because the version of ZF1 I had in my php includes path was actually 1.11.11. So I went and got 1.11.14 from the ZF archives page, put it in the includes directory, and it worked fine.
Not entirely sure if this is the best way to make it work, since it is an older version, but at least it does work. And until someone actually comes on here and offers a better solution, that's what I intend to stick with.
You can create or edit a .zf.ini file in your home directory (~/.zf.ini or C:\Users\YOUR_ACCOUNT\.zf.ini on Windows)
php.include_path = "PATH_TO_THE_LIBRARY_FOLDERS_CONTAINING_ZEND_AND_PHPUnit"
basicloader.classes.0 = "PHPUnit_Framework_SelfDescribing"
basicloader.classes.1 = "PHPUnit_Framework_Test"
basicloader.classes.2 = "PHPUnit_Framework_Assert"
basicloader.classes.3 = "PHPUnit_Framework_TestCase"
If you are using Netbeans on Windows it could looks like this (you can put several library folder, just separate them with a semicolon ;) :
php.include_path = "C:\Users\romain\dev\ZendFramework-1.12.17\library;C:\Program Files\NetBeans 8.1\php\zend;C:\xampp\php\pear"
basicloader.classes.0 = "NetBeansCommandsProvider"
basicloader.classes.1 = "PHPUnit_Framework_SelfDescribing"
basicloader.classes.2 = "PHPUnit_Framework_Test"
basicloader.classes.3 = "PHPUnit_Framework_Assert"
basicloader.classes.4 = "PHPUnit_Framework_TestCase"

Categories