Changes
Title
unchanged
NetBeans IDE and Yii projects
Category
unchanged
Tutorials
Yii version
unchanged
Tags
unchanged
IDE, Selenium, PHPUnit, XDebug, NetBeans
Content
changed
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](http://www.phpunit.de/manual/3.6/en/installation.html).
- Open "Tools > Options > PHP > Unit Testing" and set the correct path to the launch script. This is phpunit.bat in Windows and usually /usr/bin/phpunit in Linux.
- 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](http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_sample2.pkg.html).
## Debugging
- Include the Xdebug extension for PHP (should already be available):
- In php.ini enable (remove trailing comment semicolon sign - ;) these settings: <pre>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</pre>
#### Usage:
- Debug project: Ctrl-F5
- Use breakpoints, walk through running code, and watch variables and objects in real-time. :)
- If you want to stop the debugger from pausing on the first line for every request, simply turn that "feature" off by clicking: Tools > Options > PHP > Debugging > Stop at First Line (uncheck)
In Netbeans (6.9.1 on Windows anyways):
Menu bar > Tools > Options > PHP > Debugging > Stop at First Line (uncheck)
# Test Driven Design with Netbeans
Check the forum here: 1. Code completion
To get context sensitive code completion, follow these steps:
- If the Yii framework folder is not inside the project folder:
- 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
#### Usage:
- Typing suggestions: Ctrl-Space
- Show Function parameters: Ctrl-P
- Comment your own code with PHPDoc style. [Here's a good example](http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_sample2.pkg.html).
- Code completion in view files
- Add the following PHPDoc statement at the head of the file to use code completion in view files. (you may add additional passed parameters as well)
```php
/* @var $this PostController */
/* @var $model Post */
$this->getSomeProValue(); // possible with code completion
$model->author; // possible with code completion
```
## 2. Code templates
You can create code templates for commonly used/overridden function in Yii.
For example, if you want to add an beforeSave() function in your model, by typing a shortcut you can automatically have the function template in place. There are additional shortcuts for common stuff like Yii::app(), Yii::t(), Yii::app()->user->checkAccess(), and more!
- Download this template set to get started: [http://fbe.am/hly (version 2)](http://fbe.am/hly). View all available commands [in this printable cheat sheet](http://www.cheatography.com/hoplayann/cheat-sheets/yii-code-templates-for-netbeans/).
- Go to "Tools > Options > Editor > Code Templates"
- Hit "Import", select the file, and choose "Code Templates"
- You might get an error message "invalid zip file" if you are importing to a older/newer version of NetBeans. Open up the zip file, edit build.info, and set the correct path to Userdir.
#### Usage:
- Type the shortcut and hit TAB
- More info: [NetBeans Docs](http://netbeans.org/kb/docs/php/code-templates.html#using-templates)
- Example:
```php
// typing: ybeforesave + TAB
// expands to:
/**
* This method is invoked before saving a record (after validation, if any).
* @return boolean whether the saving should be executed. Defaults to true.
*/
protected function beforeSave()
{
return parent::beforeSave();
}
```
## 3. Testing
To run functional tests and unit tests in Yii, recommended is installing PHPUnit and SeleniumRC.
- Install PHPUnit
- Follow [the official installation instructions](https://phpunit.de/manual/current/en/installation.html).
- Open "Tools > Options > PHP > Frameworks & Tools -> PHPUnit" and set the correct path to the launch script. This is phpunit.bat in Windows and usually /usr/bin/phpunit in Linux.
- Install SeleniumRC with one of these two methods:
- Through NetBeans plugins (may be outdated):
- Open "Tools > Plugins > Available Plugins"
- Install "Selenium Server"
- Install ["Selenium Module for PHP"](http://plugins.netbeans.org/plugin/37753/selenium-module-for-php)
- Through the Selenium website:
- Download and execute ["Selenium Server"](http://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar)
- Configure project options
- Open "File > Project properties > Testing":
- Add folder \[PROJECT ROOT\]/protected/tests
- Enable testing provider "PHPUnit"
- Open "File > Project properties > Testing > PHPUnit":
- Set "Use Bootstrap" to \[PROJECT ROOT\]/protected/tests/bootstrap.php
- Set "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)
## 4. Debugging
- Install Xdebug (usually already available in your installation):
- Follow [the official installation instructions](http://xdebug.org/docs/install).
- Include the Xdebug extension for PHP:
- In php.ini enable (by removing ; prefix) these settings: <pre>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</pre>
#### Usage:
- Debug project: Ctrl-F5
- Use breakpoints, walk through running code, and watch variables and objects in real-time. :)
- If you want to stop the debugger from pausing on the first line for every request, simply turn that "feature" off by clicking: Tools > Options > PHP > Debugging > Stop at First Line (uncheck)
### 5. Navigation, wizards, additional code completion
[Install a special Yii plugin](http://plugins.netbeans.org/plugin/47246/php-yii-framework-netbeans-phpcc).
## Got problems or questions?
Do NOT post a comment on this wiki page, but go to the forums:
<http://www.yiiframework.com/forum/index.php?/topic/11735-netbeans-ide-and-test-driven-development/>