Difference between #20 and #17 of NetBeans IDE and Yii projects

unchanged
Title
NetBeans IDE and Yii projects
unchanged
Category
Tutorials
unchanged
Tags
IDE, Selenium, PHPUnit, XDebug, NetBeans
changed
Content
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(assuming it is properly placed
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
- In your code, you'll most likely want to have codeCode
completion for class methods/properties for objects passed in
the global namespace to "current" file your editing. For example, when
a controller object is being passed into a view file. To have code
completion in this case, you have to tellfiles.
  - Add the IDE what'sfollowing PHPDoc statement at
the classhead of this object. This is achieved by
adding a simple comment line (a 1 line php doc block) declaring the
class of the object. This comment should be placedfile to use
code completion in a line before using this object, with no new empty
lines in between. For example, in the code section below, which is part of
some view file, adding the comment makes the IDE think that $this is
of type YourController, and adds code completion accordingly:files.
(you may add additional passed parameters as well)
~~~
[php]
/* @var $this YourControllerPostController */
/* @var $model Post */
$this->getSomeProValue(); // whatever method/prop.possible
with code completion
$model->author; // possible with code completion
~~~ 

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_, _framework_ or smth. 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

- Install Xdebug (usually already available in your installation):
  - Follow [the official installation
instructions](http://xdebug.org/docs/install).
- Include the Xdebug extension for PHP (should already be
available):PHP:
  - In php.ini enable (remove trailing comment semicolon sign -
;)(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) 

## 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/>

Links
-----

- [Chinese version](http://www.itkuaixun.com/bbs/thread-216-1-1.html
"Chinese version")