You are viewing revision #11 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version or see the changes made in this revision.
This page is created to supply short directions and general tips for managing a Yii application in NetBeans IDE.
Testing ¶
To run functional tests and unit tests in Yii, recommended is installing PHPUnit and SeleniumRC.
- Install PHPUnit
- Follow the official version 3.6 installation instructions.
- Open "Tools > Options > PHP > Unit Testing" and set the correct path to phpunit.bat
- Install SeleniumRC by getting the NetBeans plugin
- Open "Tools > Plugins > Available Plugins"
- Install "Selenium Module for PHP"
- Configure project options
- Open "File > Project properties > Sources" and set "Test Folder" to [PROJECT ROOT]/protected/tests (If the whole project testing doesn't work, try [PROJECT ROOT]/protected/tests/unit)
- Open "File > Project properties > PHPUnit" and set "Use Bootstrap" to [PROJECT ROOT]/protected/tests/bootstrap.php, and "Use XML Configuration" to [PROJECT ROOT]/protected/tests/phpunit.xml
Usage: ¶
- Test whole project: Alt+F6
- Test single file: Shift-F6
- Check code coverage (right click project > Code Coverage)
Code completion ¶
To get context sensitive code completion, follow these steps:
- Include Yii folder (outside project directory)
- Open "File > Project properties > PHP Include Path" and add the Yii framework root path
- Ignore yiilite.php to avoid doubled/missing documentation
- Open "Tools > Options > Miscellaneous > Files"
- Add to the front of "Files Ignored by the IDE" the file "^(yiilite\.php|CVS|SCCS|...."
- Restart NetBeans
For above and many more reasons, Yii core files should be kept outside project directory and anywhere outside any web-accessible directory. I.e. if you keep your project files in Apache's httpd directory, it is wise to create a new dir (called yii, framewore or sth. like that) in the same level of dirtree (inside Apache main folder, not in httpd dir!) and put Yii core files there. If you do that, you have to include Yii folder in Include Path, as it is written above.
Usage: ¶
- Typing suggestions: Ctrl-Space
- Show Function parameters: Ctrl-P
- Comment your own code with PHPDoc style. Here's a good example.
Debugging ¶
- Include the Xdebug extension for PHP (should already be available):
- In php.ini enable (remove trailing comment semicolon sign - ;) these settings:
zend_extension = "C:\xampp\php\ext\php_xdebug.dll" xdebug.remote_enable = 1 xdebug.remote_handler = "dbgp" xdebug.remote_host = "localhost" xdebug.remote_port = 9000
- In php.ini enable (remove trailing comment semicolon sign - ;) these settings:
Usage: ¶
- Debug project: Ctrl-F5
- Use breakpoints, walk through running code, and watch variables and objects in real-time. :)
Test Driven Design with Netbeans ¶
Check the forum here: http://www.yiiframework.com/forum/index.php?/topic/11735-netbeans-ide-and-test-driven-development/
Test Folder
Thanks for posting this! I've been running all my test from my shell, so this is very helpful.
Just a side note: running all tests (Alt-F6) did not work for me until I changed the test directory to /path/to/myapp/protected/tests/unit
Ignoring yiilite
Don't forget to escape the dot when you insert yiilite to be ignored. The line should start with:
^(yiilite\.php|
Global include
If Yii is your primary framework and you are creating many projects then adding the Yii path to every project can be tedious and sometime you can just forget to add it...
To solve this Yii path can be added to the "global include path" so that it's automaticaly included for every old and new projects...
Open "Tools > Options > PHP" and add the Yii framework root path to the "Global include path"
ubuntu/linux
Great article, worked for me, thank you. I must admit, I struggled with Eclipse but Netbeans seems a lot easier to use.
For ubuntu/linux
Open a terminal and enter
gksudo gedit /etc/php5/apache2/php.ini
the php.ini setting should be
zend_extension=/usr/lib/php5/<DATE+lfs>/xdebug.so xdebug.remote_enable=on xdebug.remote_handler = "dbgp" xdebug.remote_host = "localhost" xdebug.remote_port = 9000
Save, close and restart apache
sudo apachectl -k graceful
Also, I installed netbeans from the Ubuntu Software Centre which doesn't include php. So I downloaded the php bundle from
http://netbeans.org/downloads/
Extracted the zip to a directory (/home/russ/Downloads/netbeans)
Then ran Downloads/netbeans/bin/netbeans from a terminal
This seems to update the netbeans to include php projects.
problem to find the phpunit on linux (ubuntu)
all is in the title.
I can't find the script in this folder "/usr/bin/phpunit".
someone can help me plz (NetBeans IDE 6.9.1)
@Alix installing phpunit
I'm using Ubuntu and installed it via
sudo apt-get install phpunit
Thanks, Russ
where can i fond the path script to launch ?
Yes but, when i need to configure this, "Open "Tools > Options > PHP > Unit Testing",i don't find the correct path in order to launch the correct script.
@Alix
Please repost your question here
PHP_CodeSniffer
see here
NetBeans and PHPUnit
Hi! i'm newbe...
What does meands the message: "Test were not generated for the following files: Review the log i Output window"?
I have totally new XAMPP (:) ) installed in Win7.
New NetBeans 6.9.1, PHPUnit installed with XAMPP, then must be new.. 3.6
I doing step by step with this tuts "NetBeans IDE and Yii projects", and...
i don't see any files with log, why its not generated? Whitch one window is "Output window" when i see "the log"?
I'm very flustrated...
;)
Sorry for my lang, and bad mood... :) Help me please.
Thanks and regards
Ykee
error
i did all steps but when i test whole project i get this error
PHP Fatal error: Cannot redeclare class CActiveRecord in /srv/http/weblog/framework/db/ar/CActiveRecord.php on line 1832
Manual Install of PHPUnit
If you are using 64bit windows with WAMP or XAMPP install then you most likely don't have pear so go to this site and follow the instructions for installing PHPUnit manually.
http://www.unclecode.com/2010/05/install-phpunit-on-wamp-xamp-manually-without-pear/
This is an old article so I am not sure about it's download location, I used the following site to download the current version.
https://github.com/sebastianbergmann/phpunit/
Selenium and chrome
How to run selenium with google chrome? IE is too slow.
Awesome
thank you for the setup explanation
Code completion for attached behaviors
This won't work out of the box, it requires some additional typing. But at least you can make it work. Consider one of your model has some behaviors attached:
class MyModel extends CActiveRecord { public function behaviors() { return array( 'someBehavior' => 'MyBehavior' ); } } class MyBehavior extends CActiveRecordBehavior { public function foo() { } }
With this, the IDE has no idea about instances of "MyModel" providing a method "foo". You won't get suggestions for:
But what you can do is adding some PHPDoc to your model class:
/** * @method void foo() */ class MyModel extends CActiveRecord { public function behaviors() { return array( 'someBehavior' => 'MyBehavior' ); } }
Now, the the code completion should show the method.
Code completion in view files
I had to play with the order of the PHPDoc definitions to get code completion work.
Tweak the lines of your definitions if you encounter any problems.
/* @var $matters Matters */ /* @var $model Order */ /* @var $this OrderMatters */
Code templates
I discovered the advantages of using code templates and added some information to the wiki page about it. See if you like it. :)
Re: Code templates
I forgot beforeValidate(), added now to the file.
Do you still have to use command-line to create controllers, views and models in Yii?
Hi guys,
I have just managed to get NetBeans configured for an existing Yii demo project I created.
But now I intend to use this for commercial projects.
Do I still need to do bulk of the work from command-line? Or is there a plugin that can help?
Best Regards,
Ashish.
Re: Do you still have to use command-line to create controllers, views and models in Yii?
I think pretty much everyone is using the standard Gii-tool since two years now ;)
http://www.yiiframework.com/doc/guide/1.1/en/quickstart.first-app#implementing-crud-operations
Re: Do you still have to use command-line to create controllers, views and models in Yii?
@marcovtwout - Thanks so much.
Separate application and framework projects
I found usefull to have separate projects for application and yii, so in example when you open
Go to file
dialog there is checkboxPrefer current project
, so your project files are first on the list. My folder layout is:MyApplication/app // Project MyApplication/framework // Framework project
Cheat sheet for 2. Code templates
Hi,
for those interested, I have created a cheat sheet in order to learn a bit faster those code templates :-)
Yii + Php code templates for NetBeans:
http://www.cheatography.com/hoplayann/cheat-sheets/php-yii-code-templates-for-netbeans/
Only Yii code templates for NetBeans:
http://www.cheatography.com/hoplayann/cheat-sheets/yii-code-templates-for-netbeans/
Good luck !
Code templates version 2
I created a new version of the code template set. It contains new commonly used function calls, and example code in some of the already existing methods.
Added the new download and a link to hoplayann's cheat sheet to the wiki page. :)
NetBeans 7.3 Yii Plugin released!
NetBeans 7.3 now has an "official" Yii Plugin that includes some nice features:
Plugin Portal: http://plugins.netbeans.org/plugin/47246/php-yii-framework-netbeans-phpcc
Github/docs: https://github.com/nbphpcouncil/nb-yii-plugin/tree/nb73dev
Can I ask?
hi,
pmaselkowski at 2012/11/22 01:21pm sayd
>Separate application and framework projects
>I found usefull to have separate projects for application and yii, so in example when you >open Go to file dialog there is checkbox Prefer current project, so your project files >are first on the list. My folder layout is:
>MyApplication/app // Project
>MyApplication/framework // Framework project
do you mean that if you have the framework in a project you don't have to include it in your real projects? sorry for me english, home you understood, thanks
Re:
@Juan Pablo Sala - Exactly, you can have separate open projects, and netbeans will also search other projects. Also there is even possibility to not make framework project at all!
Here is how:
Click on application project, choose
properties
then fromcategories
choosePHP include path
and thenAdd folder
and navigate to framework folder. This wayOpen file
dialog will completely ignore framework files, but code completition still works.Does this work with phpStorm
I currently have a plugin for Yii installed in my installation of phpstorm, but it does not include a lot of what is available with this plugin. Can I install this with phpStorm
and will it work the Yii plugin for phpStorm, I already have installed?
.
I recommend to look at Codelobster IDE with special Yii plug-in.
It has great autcomplete and help system.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.