phpUNIT - how use this?

I am coming from a strictly hand coding experience, using PsPad, phpMyAdmin and a white board to layout the logic and diagram out my functions and code when I can't figure out what I did wrong that screwed it all up.  Really sick of doing all that and flipping back and forth from 3 or 4 differrent software, browsers and what not.  It is fine when doing a project with only 10 or so files but when you get into 30 or more and in different folders etc... and several thousand lines of code.   It's like using an abacus to predict weather patterns, good luck with that.

The main IDE I have used is dreamweaver cs3, I have plenty of plugins and database design specific plugins that is mainly reason I ever open up DW, until I recently discovered I can access that particular tool without ever needing to open DW which was the only reason I ever when into DW anyway.  BUT, even though it is great I would really like an all inclusive tool to help me, so over the last few days I have been researching IDE's that allow for php, mysql, css, xhtml, html, ajax, js coding and being able to track and help me figure out what is what and hopefully help me code better and make things more secure and effecient with all the database calls and help find bottlenecks etc...

I looked at eclipse, netbeans, codelobster, aptana and 3 other commercial competitors. Trying out each one and narrowing down to the most usable for me and has the most amount of features I am looking for.  I have never heard of Xdebug, phpUNIT and a sluegh of other technologies and terms I came up against over the last few days.  I have been able to install pear into my php installation on my testing environment, I use Windows XP and WIndows 7 with vertrigo server that has Apache, Php, Mysql and I added perl, python and few others over last year but I primarily only code using PHP and Mysql.   I was able to install pear and have it install phpUNIT. I manually installed and configured php.ini to properly work with Xdebug and have been able to use that with phpStorm and it works like in the video's.

With that bit of a background that basically lets you know where I am coming from, I don't know much about this stuff yet but I am learning.  phpUNIT is the thing that allows for tracking how long each bit of code takes to run and shows the bottlenecks right?
I do not understand anything about it other than that.  I read through their site and looked through the manual pages but I don't understand any of what it says about calls and how to setup tests, or even what tests I can setup.  I am totally new to this part of coding, the debugger stuff when it comes to php. I have used code compilers and debuggers before but I don't really code in C++ or anything like that yet, sort of  a little python and am ok with actionscript.

I read what I could find in the forum and on the site about configuring things with Xdebug and some about phpUnit but I really don't understand it much yet.  Xdebug I got working and that is mostly self explanitory I just can't get my head around phpUNIT right now for some reason.  I have no idea how to test if phpUNIT even works correctly after the install or not.

What do I do and how do I do it I guess is what I need to know.

It's installed, that is all I know.

Thanks.

8 comments
Comment actions Permalink

newbie2IDE wrote:

phpUNIT is the thing that allows for tracking how long each bit of code takes to run and shows the bottlenecks right?

No, you describe XDebug's profiler. phpUnit is used for unit-tests: http://en.wikipedia.org/wiki/Unit_testing

0
Comment actions Permalink

Hi there,

phpUNIT is the thing that allows for tracking how long each bit of code takes to run and shows the bottlenecks right?

No.

PHPUnit is a unit testing software framework for PHP. Like all Unit testing frameworks PHPUnit uses assertions to verify that behaviour of the unit of code under test behaves as expected. The goal of unit testing is to isolate each part of the program and show that the individual parts are correct. A unit test provides a strict, written contract that the piece of code must satisfy. As a result, unit tests find problems early in the development cycle.
Grabbed from Wikipedia.

If you are after finding bottleneks and checking "how long each bit of code takes", then you can use Profiler feature of Xdebug. Xdebug's built-in profiler allows you to find bottlenecks in your script and visualize those with an external tool such as KCacheGrind or WinCacheGrind. I may recommend you webgrid (an Xdebug profiling web frontend in PHP5) -- easy to use and understand -- using it myself.

0
Comment actions Permalink

@Andriy    Thankyou, I have webgrind installed and it works great. I had to put a htaccess file in the webgrind folder to turn off Xdebug profiler for that folder structure to turn off profiling of webgrind but once I did that it works great.

Isn't there a way to view this information within phpStorm itself at each debugging run?  If so, how can I set that up?   I haven't really gone hardcore into using phpStorm yet, mainly just checking it out but today and this week I am going to be using it full time on my projects then will purchase a license after I am 100% certain this is the right tool for me.  Thanks.

0
Comment actions Permalink

@OZ     Ok.   How do I use this within phpStorm?

0
Comment actions Permalink

I use my own unit-tests.

0
Comment actions Permalink

Hi there,

Isn't there a way to view this information within phpStorm itself at each debugging run?

No. But it is planned for 2.x version -- please watch this ticket: http://youtrack.jetbrains.net/issue/WI-312?projectKey=WI

Another useful related feature (to be implemented): http://youtrack.jetbrains.net/issue/WI-313?projectKey=WI

I had to put a htaccess file in the webgrind folder to turn off Xdebug profiler for that folder structure to turn off profiling of webgrind but once I did that it works great.

From personal experience: I recommend to turn off profiler autostart and use it only when needed (when debugging it is useless anyway and while running already working code (when no need for profiling) the profiler itself consumes some resources and generates those unwanted-at-this-stage profiler-results files). You can use some browser extensions to turn on/off profiler and/or xdebugger when needed (e.g. easy Xdebug for Firefox, Xdebug helper for Chrome) or bookmarklets: http://www.jetbrains.com/phpstorm/marklets/

0
Comment actions Permalink

ic.  I thought I saw in one of the video's on the site something about being able to define our own tests within phpStorm during the debugging, isn't this done with phpUNIT?   If it is, do you know if I need to do anything within phpStorm to use this or is there no configuration like Xdebug?

I am sorry if this is a basic or dumb question but I am really new to this so any help would be great.

Thanks.

0
Comment actions Permalink

Hi there,

PHPUnit tests can be run from within PhpStorm by creating PHPUnit Run Configuration in "Run | Edit Configurations". All the job (actual unit testing) is done by PHPUnit itself, PhpStorm here only provides integration interface, so that you can run such tests and see the results of it (easily see which tests have passed and which have failed, easily navigate to the error line for failed tests etc).

You can create such test files in few ways:

  • manually
  • via console using PHPUnit's own phpunit --skeleton-test command (refer to the PHPUnit manual).
  • right click on PHP file and choose "Generate PHPUnit Test..." menu item (only available if PhpStorm thinks that file matches some requirements -- currently this option is not available if such file has no classes defined in it or if file contains namespace). This action will simply provide custom dialog window where you enter some additional details which then will be passed to PHPUnit's phpunit --skeleton-test command.
0

Please sign in to leave a comment.