Flow3 Debugging - php

I'm currently evaluating Flow3 for an upcoming project. The AOP Pattern and Dependency Injection would be just ideal for our purpose.
Now what I can't figure out is how to debug some results in a controller Action.
public function testAction() {
$beans = $this->coffeeBeanRepository->findAll();
var_dump($beans); // doesn't work, browser crashes
}
What I've tried:
Debugging with PHPStorm and XDEBUG (this is how I do it usually)
var_dump / print_r / print

You want to use FLOW3's var_dump, which deals with some of the recursion that comes from deeply nested objects and causes your browser to cache:
\TYPO3\FLOW3\var_dump()
XDebug can be tricky in FLOW3 because FLOW3 creates proxy classes for your classes in order to make all the AOP magic happen. Still, I know the developers here are using xdebug_break() successfully in PHPStorm on their FLOW3 projects, so it's definitely doable.

Xdebug is not so tricky, your cached PHP files must be used to debug purpose, if you need to debug MyController, search for a MyController_Original in the cache directory and put your break point in this file.
You can also use debugproxy.php to improve the usage of xDebug with Flow:
https://github.com/sandstorm/debugproxy

In the newest version of Typo3 Flow you have to use:
\TYPO3\Flow\var_dump('test');

Related

Debugging PHP Code with debug_backtrace

I love to save time using someone else's code. And I want to start effectively debugging my scripts, as well as scripts I inherit from other developers.
I've been reading up on debug_backtrace(), and I'm not sure if it's what I'm looking for.
Basically,when a class is instantiated I want to know what methods are being fired.
Truthfully, I'd like to know as much as possible, but knowing what's going on inside a single class would be fantastic.
<?php
require('aHugeComplicatedClass.php'); // sooooo many methods
try {
$obj = new aHugeComplicatedClass($params);
}
catch(Exception $ex){
var_dump($ex);
}
?>
From PHP's docs about debug_backtrace, it looks like I need to place the debug_backtrace() function inside each method/function within any and all classes, just to see how it was reached.
I gotta be reading this too literal. That would be a ton of modifications.
So, if I have a php file, that instantiates a class, and I know this class is extended from other classes, what's the simpliest way to debug that Object?
I would install XDebug and hook up the remote debugging to your IDE (e.g PhpStorm or Eclipse), that way you will get nice stack dumps on all errors, plus the ability to breakpoint your code and inspect the stack and all object internals at your leisure.
http://xdebug.org/
You can also use it to profile your application call chains without making any code changes (which sounds more like what you are wanting). By using the profiling options, which generate big log files, you can then load these logs into webgrind and visually inspect who's calling what in nice tree structures.
https://code.google.com/p/webgrind/
The Zend tool chain would also provide this kind of deeper debugging functionality out of the box.
Alternatively install an Application Performance Monitoring agent such as App Dynamics or New Relic for similar code-profiling. This is most useful for remote installations (i.e. production) where debugging isn't an option and profiling is expensive.
We use NuSphere PhpED for getting all such things. It can trigger debugger to stop on specified exceptions and/or errors and shows complete call-stack that may include php functions calls, php method calls, embedded functions calls and embedded method calls.
http://www.nusphere.com/products/phped.htm
I was told in the beginning that their debugger is the best and can confirm this. It stems from the OSS project
http://sourceforge.net/projects/dbg2/
With PhpED IDE we run full cycle of development -- coding, debugging, profiling, testing and uploading to the production server.

PHP Testing Include files that only output

The way we've been developing, many of our PHP files are included only with the expectation that they will output content; no methods are called, etc. My question is, what's the "correct" way to test this with PHPUnit? Should I have the require placed in the setUp so that it waits till then to run, or is that considered bad mojo?
That's about the only way you can test it. I assume you're planning to use output buffering to capture the content produced so that you can check it against expectations.
The best way is probably to refactor your code so as much work as possible is being done in self-contained classes / functions that return results to the caller, suitable for being tested from PHPUnit in a more conventional way.
If your application is a web application (i.e.: outputs content that requires a browser to be readable), then PHPUnit is integrated with Selenium, which is a Web Application Testing System. It's indeed very useful, especially since it has a Firefox plugin.
You can read more on PHPUnit and Selenium in the PHPUnit Manual.
If your templates (i.e.: include files) are used in command line scripts, then use output_buffering and regular expression assertions or regular assertions (i.e.: assertRegExp, assertEquals).

PHP Debugging with Breakpoints - case studies, examples..?

I'd really like to get deeper into my php scripts and use things like breakpoints, as I'm doing with JS with firebug.
I'd like to know more about what techniques people use, and some solid examples of how to debug with breakpoints a php project.
Thing's I'd like to be able to see..
Properties of objects
Class hierarchies.. where objects are coming from, file names etc.. (useful in ZF/Magento)
Variables, types, content..
headers, post data, get data, session data, cookies..
Network / filesystem status..
I know a lot of this can be done with logging and print_r/vardump etc, but its a bit raw.. and I'd like to be able to use a "continue"/"step-over" etc command on code after hitting a breakpoint, like with firebug.
from php.ini:
zend_extension_ts = c:\wamp\bin\php\php5.2.11\ext\php_xdebug-2.1.0-5.2-vc6.dll;
xdebug.remote_enable=On;
xdebug.remote_host="localhost";
xdebug.remote_port=9000;
xdebug.remote_handler="dbgp";
xdebug + remote debugging + one of the supported clients
Use XDebug, it does most of what you require (not network/filesystem), and with it you can debug from eclipse, zend studio, pdt, or even notepad++
I keep debugging again and again when dealing with Magento, and it is super useful in this case, since Magento's function call stack is very deep.
PHP is interpreted and server side scripting language. So, there are only few editors that supports the break point in PHP. And if you are doing the server side scripting then there is no way to debug your script using break points.
However if you are planning to have basic scripting & debugging then you can go with http://www.firephp.org/. Also if you use Zend Studio editor then you will have many options on hand for debugging your script. Zend Studio supports the break point, run & debug options.
I prefer to log the execution of my script in file.
Thanks

"Web interface" to PHPUnit tests?

Is there a simple "Web interface" to running PHPUnit test suites? i.e. a PHP script that runs the test on the command line, and outputs a nicely formatted HTML result.
I develop web applications, and the day-to-day workflow usually switches between the IDE and the browser. I would like to have the unit testing in the same environment.
I'm looking for something really simple and PHP based - I am planning to get into phpUnderControl (which has the functionality I'm looking for) but not yet.
I recently discovered Visual PHPUnit which looks like a very very nice interface for everyone that doesn't want to run PHPUnit from the command line:
It seems to be the next iteration of #Matt's PHPUnit Test Report
I feel your frustration - I'm a UI guy myself. Looking at the terminal too long makes my head spin. I wrote a quick little application that you might find helpful.
(source: mattmueller.me)
You can find it here: http://mattmueller.me/blog/introducing-phpunit-test-report
Cheers!
Matt
After several hours of researching recently, the best PHPUnit web frontend I have come across was https://github.com/NSinopoli/VisualPHPUnit
You can use phing to run a PHPUnitTask and then convert the output with:
PHPUnitReport - This task transforms PHPUnit xml reports to HTML using XSLT.
Example:
<phpunitreport infile="reports/testsuites.xml"
format="frames"
todir="reports/tests"
styledir="/home/phing/etc"/>
See phpunit --help for the various output formats.
The 2.3 version of PHPUnit had a chapter on this, but it is gone for some time now. You might be able to find an old copy with Google somewhere.
Since you mention this is for phpUnderControl: if you are not fixed on that, consider using Jenkins and http://jenkins-php.org.
On a side note: unless we are talking CI servers, most people I know don't use PHPUnit through a web interface. They either just use the command line or their IDE integration.
You can use Jenkins to run any kind of tasks including PHPUnit tests. It can automatically checkout your app, run the tests, build a HTML report and even email you if the build fails.
Here's the templates you need to setup Jenkins to build a bunch of interesting reports and stats from your project.
If you don't care about reformatting the output and just want to run PHPUnit from a web page, you can do so with some PHP code like this:
<pre>
<?php
$argv[0] = "phpunit.phar";
$argv[1] = '--bootstrap';
$argv[2] = 'src/load.php';
$argv[3] = "tests/MoneyTest";
$_SERVER['argv'] = $argv;
include 'phpunit.phar';
?>
</pre>
The file src/load.php is just a bunch of includes to include the classes. The output then looks like this:
#!/usr/bin/env php
PHPUnit 4.1.2 by Sebastian Bergmann.
........................
Time: 122 ms, Memory: 3.25Mb
OK (24 tests, 43 assertions)
Just ignore that first line and you can see the results.
I'm shocked that PHPUnit does not include a basic way to do this. Some classes may be dependent on the web server. Do we just not test those? Some sites have you upload your files and don't allow command line executions.
I've never seen such a web-interface... But, as you say you are always using your IDE and your webbrowser, why not think the other way ?
i.e. a possible solution would be to launch the unittests from your IDE ;-)
Which means you should be able to click on the failing tests to "jump" to either the test method, or the reason that caused the test to fail, for instance.
In the PHP + PHPUnit world, I know that Zend Studio does that -- yes, it's not free, unfortunatly ;-(
Using Eclipse PDT, a solution would be to register PHPUnit as an external tool (see or instance this blogpost : Using PHPUnit with Eclipse PDT) -- but it's quite not sexy, and you cannot click on the results to jump the the methods/tests...
Another solution would be to develop a plugin to integrate PHPUnit into Eclipse PDT (like it's been done for Zend Studio, I suppose) -- A phpunit4eclipse was created some time ago, but it's just a start, and didn't get much succes, so the author didn't work on it after releasing that...
I found this:
I stumbeld upon a post from Parth Patil, whose solution was to create an xml-report from PHPUnit and then use this xml to create your own report.
I used his solution, made it PHPUnit 3.4 compatible and also added some Reflection to see my testcase doc-comments in the report. (Note: For the refelection i use the Zend_Framework reflection class)
Ok you said you'd prefer an independent IDE solution, but just so you know there is a recent plugin that enables executing PHPUnit simply into Eclipse, and having a nice representation (like in Zend Studio, but for free).
Here is the link, the main developper replies fast to emails too if you have a problem :
http://www.phpsrc.org/wiki/
I personnaly tested some web interface, but I have always been deceived (not really practital and stable). But this is your choice.
jframework also has a nice UI for PHPUnit. It breaks the results, and shows test coverage on all files and each file separately.
It works on both web and cli, with the cli one having the benefit of dumping every test after its done (the web-based one has to wait until everything is over).
You can always use the Maven for PHP from which you can use the surefire reports (mvn site).
More info here: http://www.php-maven.org

Magento Debugging Environment

I looked for ideas on setting up a Magento development environment when we first started using it for our site last year. I didn't find anything that work really well, so I stayed with var_dump'ing using the log files.
Now that Magento has another year under its belt and several hundred more developers I was wondering if anyone has found a better solution for debugging Magento.
We use Eclipse as our development environment. We tried a pre-2.0 release of PDT with the Zend Debugger and didn't have much luck.
How about using FirePHP?
http://ajzele.net/utilize-firebug-and-firephp-to-speed-up-magento-development
It made my life a hell of a lot easier.
I use a combination of var_dump with xDebug and Magento's Mage::Log method. Mage::Log is particularly nice, as it'll do some auto-expanding and pretty printing of objects if you pass them in (I'm not sure if that's the logger, or just Magento's __toString implementation).
If I'm on my local development box I use Console.app to keep an eye on the log file, otherwise it's a simple
tail -f /path/to/log/file
That combined with some custom modules I've built for debugging the config and layout keep me happy. (although I prefer a light weight text editor toolchain vs. the One True IDE tool chain, so your results may vary)
logging $object->getData() rather than the $object itself is normally more useful, and everything built into Magento has it as a method (everything extends Varien_Object)
$object->debug() is often quite helpful too, although it doesn't exist on all objects.
Here are my most commonly logged statements:
Mage::log( $object->debug() )
Mage::log( $object->getData() )
Mage::log( get_class($object) ) # name of class
Mage::log( get_class_methods($object) ) # methods of class
I also use FirePHP but find this extension easier.
Give it a try to Magneto-Debug: https://github.com/madalinoprea/magneto-debug (only for dev environments).
Video doesn't contain features added in the latest version: http://www.youtube.com/watch?v=aqvgrmebcu4
- display layout updates from DB
- display blocks' rendering time
NuSphere is also good debugger for magento here is link
NuSphere

Categories