Code completion for PHPUnit and Selenium in NetBeans - netbeans

How can I get NetBeans to provide code-completion for PHPUnit classes and methods?
I have already tried downloading from the PHPUnit GitHub project, but I didn't understand why the directory is different from what's mentioned on the Selenium documentation. I am looking example for the /test/PHPUnit/Extensions/SeleniumTestCase.php file.
I have already installed PHPUnit from PEAR, but what I need now is the complete PHPUnit file so I can include it in my IDE (in this case NetBeans).

Add the PHPUnit directory to NetBeans's PHP global include path. This will provide code completion in NetBeans for all projects.
Open Tools : Options
Switch to the PHP tab
Click Add Folder... next to the Global Include Path box
Enter /usr/share/php/PHPUnit or navigate to where PEAR installed PHPUnit's source files
Click Open
Click OK
Update: The file defining PHPUnit_Extensions_SeleniumTestCase is placed in the same directory as PHPUnit when you install PHPUnit Selenium.
For example, PHPUnit_Framework_TestCase is stored in
/usr/share/php/PHPUnit/Framework/TestCase.php
The Selenium test case is stored in
/usr/share/php/PHPUnit/Extensions/SeleniumTestCase.php
So by placing /usr/share/php/PHPUnit into the NetBeans include path, you pick up both. You have to install the extension first, of course.
pear install phpunit/PHPUnit_Selenium

Moving away from PEAR...(I'd even uninstall the PEAR version to avoid conflicts first).
Download PHPUnit with sources
https://github.com/sebastianbergmann/phpunit and extract somewhere
semi-permanent /your-install-path
Add /your-install-path/phpunit to your PATHs
In Netbeans options (Tools > Options on Windows, Netbeans > Preferences on OS X), go to PHP tab..
a. Under the General tab, Add Folder... and select the /your-install-path/src/ folder - this will make the auto complete work
b. Go to Frameworks & Tools tab, PHPUnit, select the /your-install-path/phpunit and /your-install-path/phpunit-skelgen respectively - this will make PHPUnit tool work within Netbeans
In your project settings, right click project name > Settings, Testing category, enable PHPUnit. Optionally go to the Testing > PHPUnit settings panel and make adjustments for your project.
Edit:
When I followed the instructions above, the output window told me I needed to install dependencies using "composer install." These additional steps were needed on my machine (running Netbeans 8.2 on Windows 7).
Download Composer and install: https://getcomposer.org/doc/00-intro.md
Modify your-install-path/composer.json by adding the version number between the "description" and "type" keywords like so:
"description": "The PHP Unit Testing framework.",
"version": "5.7.8",
"type": "library",
Using the command line, type the following (this is a windows machine, for mac or lunix, it should be a little different):
cd your-install-path
composer install

Related

PhpStorm PhpUnit via phar autocomplete not working

I have PHPStorm 8.0.1.
PHPUnit is installed via PHAR archive like:
wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
sudo mv phpunit.phar /usr/bin/phpunit
PHPUnit works via cli:
user#pc:/usr/bin$ cd ~
user#pc:~$ phpunit --version
PHPUnit 4.3.5 by Sebastian Bergmann.
I followed the instructions from JetBrains website https://www.jetbrains.com/phpstorm/webhelp/enabling-phpunit-support.html#d298258e897
In PHPStorm File->Settings tab PHP/PHPUnit
the radio button Path to phpunit.phar is checked
and value is set to /usr/bin/phpunit
I have a file with a test defined like:
class MyTest extends PHPUnit_Framework_TestCase {
...
At this point PHPStorm marks Undefined class PHPUnit_Framework_TestCase
I've restarted PHPStorm and Computer, but still have the same problem.
I've also tried adding /usr/bin to include path (right click on external libraries in project view, and choose option Configure PHP include paths) without success.
Here's the config for PHPStorm Settings, tab PHP (if it matters):
PHP Language level: 5.5 (finally, generators, etc.)
Interpreter: PHP 5.5 (5.5.9-1ubuntu4.5)
Include path is empty
In order to have a PHAR archive indexed by the IDE it has to have a .phar extension (that's a requirement).
The easiest solution is to place phpunit.phar somewhere in your project (usually it would be PROJECT_ROOT/vendor/ folder).
If having local copy inside the project folder is not desired (for whatever reason; although Composer and other similar kind of tools (bower/npm/etc) are primarily aimed at keeping dependency stuff/packages locally), you may use symbolic links:
either create a symbolic link to that file locally (e.g. PROJECT_ROOT/phpunit.phar --> /usr/bin/phpunit)
or place a full copy (or such symbolic link) in a separate folder outside of the project and then reference it via PhpStorm's Settings | PHP | Include Paths functionality.
The above fix by Calin worked for me too on PhpStorm 2019.1.1, so I'll post it as an answer for easier visibility:
Try right clicking on the .phar and clicking "Exclude phar from project", then clicking "Include phar into project" to refresh it.
In my case, both the .phar file and my .idea folder were pulled from a git commit. I guess PhpStorm didnt realise that the file needed reimporting.
I noticed even though PHP itself can find and run phar that is in its include path, PHPStorm having trouble finding and parsing them.
LazyOne's explanation is correct, however, I didn't need to put it in project folder to be recognized, you can put them in any path as long as its path is introduced to IDE. In my case, I put all phar files in PHP folder, so I just needed to add PHP folder to Include Path list in IDE
Include Path for PHP is under Settings -> Language & Frameworks -> PHP screen (that tiny + at the bottom of screen).

How to use SASS with Netbeans 8.0.1

I'm trying to use SASS in Netbeans 8.0.1. I have Ruby and SASS set up correctly based upon the feedback from ruby -v.
I have a web application set up with css and scss folders under Project\Web Pages\resources.
My input and output are set to /scss and /css respectively and I have checked 'Compile Sass File on Save'. I have created a styles.scss file and added some SASS/CSS.
When I save the styles.scss file, is it supposed to generate a styles.css? Nothing happens when I save or compile the project.
Has anyone run into any similar problems or have suggestions on how to debug this problem?
Thanks in advance!
Installing SASS on Windows10, Ruby2.2.3, Netbeans8
Download SASS for Windows - RubyInstaller.org
Install Ruby like:
Search windows for CMD (Command Prompt) and start it.
Access Ruby's bin folder using cd \Ruby\bin (Hit Enter)
Install sass using the command gem install sass (Hit Enter to install)
Wait for the installation to finish
In Netbeans open
Options → Tools → Miscellaneous (HTML/JS in v8.1+) → CSS Preprocessors tab
Enter the path to the installed sass.bat C:\Ruby\bin\sass.bat than click Install Sass.
Confirm your changes with Apply / OK
Use an existing one or Create a New Project (HTML5, PHP, whatever...).
After the project is created open the Projects window.
Right-Click your project and choose > Properties.
From the Project Properties popup select CSS Preprocessors.
Select the Compile SASS Files on Save.
(If you want the compiler to automatically minimize your .css result file, use --style compressed under the Compiler Options)
You can see from the image above that the compiler uses two default Input(watchable)/Output(compiled destionation) folders paths.
Create the scss folder (an optionally the css folder) in your project as well.
You're done!
As soon you create a new .scss file or you save it Netbeans will automatically compile the file to .css in the /css folder.
Yes, when you save the file, the css should be created/updated. I think you have wrong mapping for the input/output directories. The paths need to be relative to site root/web root. I don't know for sure what your project is (HTML5 or PHP or Java Web or other?), but if you have Java Web project, then the paths need to be
resources/scss -> resources/css
Salam guys, the below image form my (Command Prompt with Ruby) says that:
"Ruby Sass has reached end-of-life and should no longer be used"
For modern SASS and Netbeans we can just use https://github.com/sass/dart-sass/releases/tag/1.56.1 and install it in our PATH.
The release has the sass.bat file we need (as Roko C. Buljan pointed in his tutorial for Ruby).
There's not need to install Ruby and any other environment.
I applied this on Netbeans 15

GWT_HOME variable setup problems

i installed GWT using Eclipse wizard to be more precise, i followed this tutorial: https://developers.google.com/web-toolkit/usingeclipse?hl=pt-PT
I now have GWT working in my eclipse indigo release. But now i need to define the GWT_HOME variable (ambient variable) so i can run a project using a build file.
Because i installed the gwt plugin with the eclipse wizard, i don't know how to setup the ambient variable, because i can't seem to find the folder where gwt got installed.
I'm using eclipse indigo on windows 7.
Can anybody help me?
Maybe you used the update site for Eclipse 3.6 instead of 3.7
This one should be the correct one for Indigo: http://dl.google.com/eclipse/plugin/3.7
When you have installed GWT like described here you just go into:
Eclipse > Preferences > Window Builder GWT and in GWT_HOME variable you click Browse and select the gwt folder inside your Eclipse plugin directory.
(For example:
.../eclipse-modeling-indigo-sr2-64/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201205091048-rel-r37/gwt-2.4.0/
)
You can also check the correct path under:
Eclipse > Preferences > Google > Web Toolkit
Regards,
Fachexot
I ran into the same problem on Linux running ant from the command line.
I got around the problem by running ant as:
ant -Dgwt.sdk=$GWT_HOME war
FYI the line:
is in build.xml.
I believe name property is not the way to set gwt.sdk variable. I.e., the problem is with:
Behdad
I am using Indigo 3.7, I could not find Eclipse > Preferences > Window Builder GWT (as suggested by fachexot), but I found that if I set the environment variable GWT_HOME in Windows 7 my ant would be able to use the value.
To set the environment variable, in Windows 7, type "environment" in the search box of "Start" and then click "Edit environment variables for your account", and then "New" a "User variable" called "GWT_HOME" (you have first look up the exact path to GWT folder inside your Eclipse plugin directory).
After that, remember to restart eclipse so that the new environment can be picked up by the program.
On Mac OSX, if you want to access the variable from an ANT build as ${env.GWT_HOME} run from within Eclipse or some other IDE then you need to use launchctl as envoronment variables set per normal in NIX envoronments is not passed to OSX windows apps.
The simplest way to do this is add the following 2 lines to your .bashrc (replacing the path shown with the correct one for your install):
export GWT_HOME=${HOME}/.p2/pool/plugins/com.google.gwt.eclipse.sdkbundle_2.7.0/gwt-2.7.0
launchctl setenv GWT_HOME $GWT_HOME

Setting up a cross-platform C++ project in Eclipse with cross-platform libraries

I am working on a cross-platform C++ project with 8 other people which uses the following libraries:
OpenCV Library
Boost C++ Library
The project is inteded to be cross-platform so all users have agreed not to use platform-specific code, and, to keep things as simple as possible, all users will be using Eclipse as their IDE. However, some will be using Eclipse for Windows while other will be using Eclipse for Linux.
Since the project will be hosted on SVN, we would like to avoid conflicts with different configuration files (like make files, eclipse project files etc..) which are shared. We would also like to share as much of the configuration files as possible through SVN, to keep the configuration as simple as possible.
Let's assume that all users have properly configured system variables and installed the required build tools (such as make, cmake etc.), and have configured their Eclipse settings configured properly (but not the project-specific settings).
How to configure the project once and what of the configuration files to share on the repository, so that both Windows and Linux users can compile it without modifying configuration files retrieved from the SVN repository?
(I am not looking for the complete solution which would specifically work for those 2 libraries I mentioned, so I would appreciate a general how-to step-by-step explanations which would enable me to easily add another library.)
General discussion:
You will need to install Cygwin or something similar to it to make GNU Autotools toolchain available to Eclipse on Windows:
How to deal with Eclipse CDT+Cygwin?
Once your toolchain, Eclipse, with CDT and SVN connectors are ready on your development machines, go through the following steps.
Open Eclipse and switch to CDT: Click Window->Open Perspective->Other... and select C/C++
Select: Eclipse->File->New->C++ Project
Project name: viewer
Select: Project type->GNU Autotools->Hello World C++ Autotools Project
Click: Next
Click: Finish
Right-click in Project Explorer: viewer->Reconfigure project
Click: Console->Display Selected Console submenu-># CDT Global Build Console. If "autoreconf -i" output is nominal, proceed to step 9. If Console reports: sh: autoreconf: command not found, then add the path to the autoreconf command to the Project Build Environment:
Right-click in Project Explorer: viewer->Properties->C/C++ Build->Environment->Add...
Name: PATH
Value: path_to_autoreconf:${env_var:PATH}
Click: OK
Click: Apply
Go back to step 8.
Double-click: Project Explorer->viewer->src->viewer.cpp
Add some code:
include <opencv/cv.h>
include <opencv/highgui.h>
include <cassert>
int main(int argc, char *argv[]) {
assert(argc > 1);
CvMat* img = cvLoadImageM(argv1);
cvNamedWindow("Picture", CV_WINDOW_AUTOSIZE);
cvShowImage("Picture", img);
cvWaitKey(0);
return 0;
}
Double-click: Project Explorer->viewer->configure.ac and enter the following code below AC_PROG_CXX.
AC_CHECK_LIB([opencv_core],[cvSetZero],[],[])
AC_CHECK_LIB([opencv_highgui],[cvShowImage],[],[])
AC_CHECK_LIB([boost_regex-mt],[regexecA],[BOOST_LIB_SUFFIX="-mt"],[BOOST_LIB_SUFFIX=""])
AC_SUBST(BOOST_LIB_SUFFIX)
Double-click: Project Explorer->viewer->src->Makefile.am and enter the following code.
>
bin_PROGRAMS=viewer
viewer_SOURCES=openCvFocusIssue.cpp
viewer_LDFLAGS = -lboost_regex#BOOST_LIB_SUFFIX# -lopencv_core -lopencv_highgui
Repeat step 8, autoreconf (Reconfigure project)
Click: Project Explorer->viewer
Build project by clicking the hammer in the toolbar. If you do not see the hammer, Window->Open Perspective->Other... and select C/C++. If C/C++ does not show up, install the CDT.
Click: Project Explorer->viewer and then Run->Run, then in the Run As window->Local C/C++ Application, then in the Launch Debug Configuration Selection window->gdb/mi and press enter. You should see Hello World.
Quit Eclipse and navigate to the viewer project directory.
On the command line, issue make dist
Ensure you got a viewer-1.0.tar.gz or similarly named file, and then remove it: rm viewer-1.0.tar.gz
On the command line, issue make clean
In the same place, issue make distclean.
Navigate to the workspace directory that contains the viewer project.
Move the entire viewer directory to the directory that contains the svn checkout you want to place the viewer project in.
Change directories to where you just moved the viewer.
svn add viewer && svn ci -m "Added eclipse-autotool project"
Open eclipse and make sure that you have an SVN connector installed.
Remove the "viewer" project from the Project Explorer view.
Open eclipse and add this SVN repository checkout to the Team perspective.
Import the viewer project from your SVN repository checkout.
Switch back to the C/C++ perspective and have fun.
Two suggestions:
Use cmake: I love this tool. There is a bit of a learning curve but
if you get it right all the project will include is the cmake files
and when a person first checks it out they run cmake to generate
their makefiles (or VC++ project files, etc) with all the different rules for linux or windows one
might need.
or
Check in a basic config for the project, then add those configs to the git/svn ignore so no one ever checks them in again, then when you checkout for the first time you have to get your config running but after that it won't be overwritten.

Eclipse PDT: put my workspace under htdocs or is there a "move files" build directive?

I am using Eclipse PDT with the Zend community server to develop PHP.
If I write some code and hit Run As...PHP Web Page, I get "Page cannot be found". This makes sense since my workspace is off in my documents folder, not in the Zend/Apache's htdocs tree.
So one option would be to move my workspace to a folder under the Apache htdocs. But that just seems wrong ;-) Also, I keep my workspace in a Dropbox folder.
Is there an alternative directive/configuration setting for Eclipse PDT that says "when I say Run or Build, I want you to copy the project to folder X and run it as a web page from there". Or perhaps something else I'm missing about Eclipse PDT?
I found a method, using Ant: http://www.tellingmachine.com/post/Configuring-Eclipse-PDT-to-work-with-Ant-build-tasks.aspx
Here is my method for developing PHP on Windows in Eclipse:
Download the Zend all-in-one Eclipse environment
Download the Zend Server CE
Install Zend into someplace like c:\Zend. If you put it in Program Files, you'll need to do extra security configuration or else your build directives will fail.
Using the link above to setup Ant and a build directive
Wah-lah. You can setup a Run Configuration and then Run As... and view your php script in a web browser.
You could also use the stock Eclipse PDT and WAMP and achieve the same effect. The key is (1) putting your htdocs outside of Program Files, and (2) using Ant to automate the build copy.
http://ventralnet.blogspot.com/2011/03/eclipse-pdt-auto-deploy-webapp-to.html
You can use a combination of ANT and custom builders in eclipse to auto copy your web app to your web root