What unit testing in PHP to start [duplicate] - php

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Simple test vs PHPunit
I'm new to good practices on software development. I need to know with witch testing unit framework should I use. I have see that some people use PHPUnit and others use SimpleTest. What package should I choose for a beginner?
Best Regards,

I'm really really baffled that Simpletest still is considered an alternative to phpunit. Maybe i'm just misinformed but as far as I've seen:
PHPUnit is the standard; most frameworks use it (like Zend Framework, Cake, Agavi, even Symfony is dropping their own Framework in Symfony 2 for phpunit).
PHPUnit is integrated in every PHP IDE (Eclipse, Netbeans, Zend Stuide, PHPStorm) and works nicely.
Simpletest has an eclipse extension for PHP 5.1 (a.k.a. so old that it's on sourceforge) and nothing else.
PHPUnit works fine with every continious integration server since it outputs all standard log files for code coverage and test reports.
Simpletest does not. While this is not a big problem to start with it will bite you big time once you stop "just testing" and start developing software (Yes that statement is provocative :) Don't take it too seriously).
PHPUnit is activly mainted, stable and works great for every codebase, every scenario and every way you want to write your tests.
Simpletest is unmaintained, outdated and does not work well with PHP 5.3 (released over a year ago)
(Subjective) PHPUnit provides much nicer code coverage reports than Simpletest
With PHPUnit you also get these reports inside your IDE (Netbeans, Eclipse, ...)
I've yet to see any argument in favor of Simpletest. It's not even simpler to install since PHPUnit is available via pear:
pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit
and the "first test" looks pretty much the same.
For everything you want to test PHPUnit will have a solution and you will be able to find help pretty much anywhere (SO, #phpunit irc channel on freenode, pretty much every php developer ;) )
Please correct me if i've stated something wrong or forgot something :)

I started with SimpleTest because the learning curve didn't seem as steep. But it's not maintained, and brings up loads of warnings in PHP5.3, as well as not being able to do everything I wanted. I eventually had to switch to PHPUnit, which was a long process converting my tests. If only I'd started with PHPUnit in the first place!

SimpleTest is slightly easier to grasp, but PHPUnit is the best ( in my opinion at least ) , so if you want to start learning and using a framework, start with the one you're going to use when you'll be a master in TDD. Don't look at if it's easier or harder now , because if you start with SimpleTest for example , then you start using Zend Framework because your boss tells you so , you'll have to use PHPUnit with ZF. So think of your future , because an easy to learn framework doesn't necessarily have to be the best one , usualy the harder to grasp the better the framework .
Also have a look at their revisions , see which one is maintained better .

I found SimpleTest easy to start, and usable for my purposes. No big issues found as for now. The manual/website is a bit confusing, but with some example-searching it's enough.
Does not feel very professional, but as you're asking for beginner framework, by all means, try that one :)

Here's a good read... This uses SimpleTest and to start with this is better than PHPUnit...
Newbie's Guide to Unit testing

Related

Similarities and Differences Between PHPUnit and PHPSpec

I am currently doing research into which test framework I should be using for php. The two choices I have are PHPUnit and PHPSpec. I know that PHPUnit is TDD(Test driven development) and PHPSpec is BDD(Behavior driven development). However due to the lack of any real PHPSpec tutorial and limited documentation on the PHPSpec site I am unable to come to a full conclusion. My question to everyone is what are some addition similarities and differences between the two frameworks? Yes BDD and TDD are big ones but are there others? And they seem similar but no one talks about their similarities in great detail. Thank you.
PHPSpec is a SpecBDD tool more dedicated to guide you in code design rather than a testing framework.
It depends what you expect from tool and if you want to make a proper TDD/SpecBDD it's easier to use PHPSpec because it was created to help developers write readable and well designed code.
Remember that TDD/SpecBDD is not about testing all edge cases or doing whole-application-integration testing. It's about writing specifications for small units of code.
Few days ago I gave a talk on it, here you can find slides: http://www.slideshare.net/cakper/2013-0613-spug-spec-bdd-in-php I hope it will be useful to make a decision.

Kohana AND PhpUnit in Netbeans

I do some PHP with Kohana 3 (IDE:Netbeans), and got excited about idea of writing tests for code. It sounds pretty cool thing to do, but i have few complications and worries.
Why using Kohana unittest module in browser is like 5 times faster then running tests in Netbeans or command Line ?
How could i exclude all kohana internal tests? In the PHPUnit .xml configuration file ?
Why when run any test i've got in Netbeans panel two entries for it - one with yellow triangle (it says 'file x skipped'), and entry with normal test result. I do get that double entries for every test, also those native from Kohana. I don't mind but it's strange.
All over the Web i see examples, tutorials and screencasts of PHPUnit with sample classes and methods that add two numbers or displays name or do some other trivial things. I've learnt to do those kind of assertions, but how could i test my code in Kohana? My Models are 90% ORM stuff. Controllers? How? Any 'How-tos' and examples are welcome.
I've seen in Ruby tutorial about Rspec a way to test DB by using testing enviroment Databse and rollbacks after finisning tests. Also user actions like clicking links were simulated. Is it possible with PHPUnit ?
There always has been a lot of discussion on what has to be tested and what has not to be tested. Generally my opinion is that you shouldn't test things that should work, like the database driver and connection, this has little to do with your code. Some then argue that you should be able to test it anyway, but in most environment this isn't an easy thing to do and usually a big hassle.
Generally controller actions should be tested as well as any helpers or modules you've written. Usually one uses the paradigm of a mocking framework to get around the database. The good thing about this is a gigantic speed increase in your testing. There are several PHP mocking frameworks as well I suppose.
Another great thing to keep in mind is that you also have user testing. This cannot be simulated with the kind of tests you write in kohana. For this it is interesting to look at http://seleniumhq.org/
It's probably better to split such a rambling question into multiple SO questions.
No idea. Perhaps there's an invocation overhead for NetBeans to invoke phpunit, compared to apache passing the request to PHP.
That might be possible, or you could find a way to set the following option: --exclude-group kohana
No idea sorry.
AFAIK PHPUnit can't do client-interaction tests. How to do system behaviour testing could be a question on its own.

Simple PHP unit tester with web report and good documentation?

Is there a decent PHP unit testing framework that display the test report as a webpage and has current documentation. SimpleTest's documentation isn't reliable. Even the "Getting Started" page has errors.
I would like a simple alternative to PHPUnit that allows you to just get started writing tests quickly.
Funnily enough, yours is a combination of two questions I asked some time ago :)
https://stackoverflow.com/questions/2408860/whats-the-state-of-php-unit-testing-frameworks-in-2010 in which I lamented the complicatedness of PHPUnit, but saw the light and understood that it simply is the most serious product in PHP unit testing, and probably the most worth getting into
and "Web interface" to PHPUnit tests? in which I was shown some really nice graphical "frontends" to PHPUnit tests.
Enhance PHP has web-bases results and is very simple to install and use. It also has good documentation at http://www.enahance-php.com/
It is currently being actively developed to compete with other frameworks - it is downloadable for free from the website.

Which unit testing framework do you use for Symfony?

Which unit testing framework do you use for Symfony?
Lime or PHPUnit? What are the pros and cons of using them?
In my opinion, here are a few things that come to my mind :
PHPUnit is more integrated with other tools, like, for instance,
Selenium (PHPUnit can use it to open true real browsers to test your site)
phpUnderControl for continuous-integration
PHPUnit works well with Xdebug, to generate code-coverage reports
PHPUnit is more widely used ; which probably means more support
But note I don't work with symfony, nor lime...
Still, I've never heards anyone speak about it, except for those working with symfony -- that not a good thing, for the day you'll have to work with another framework (yes, this happens ^^ )
One thing that's not in PHPUnit :
"false" browser (being able to do HTTP Requests to the application, without using Selenium to open a real browser)
But some frameworks (Zend Framework does, with it's Zend_Test component) integrate with PHPUnit (or use it), while allowing injection of data into the MVC and fetching of the response, without having to issue any HTTP Request.
I don't know if symfony allows that, but that's a nice thing with ZF/PHPUnit ^^
(Yes, not a symfony-specific answer ; but of the things I said must still be valid with that framework)
Lime is a much more simple testing framework, which can be a good or a bad thing depending on how you want to use it.
The symfony library itself uses its own testing framework, Lime, to test its code base. From the symfony book:
It is based on the Test::More Perl
library, and is TAP compliant, which
means that the result of tests is
displayed as specified in the Test
Anything Protocol, designed for better
readability of test output.
I cannot vouch for the statement that the lime framework is "more lightweight" than other PHP testing frameworks as the symfony docs claim, but I do really like that it's built right into your symfony project and works well with the symfony command line tools without any additional configuration. One thing that is especially cool is that the lime tests within symfony are set to run within your "test" environment which has it's own database, symfony cache (which gets cleared out during each test session), and environment variables. This comes in handy when you want to do functional testing (checking server response and your html output in your modules/actions, versus basic unit testing). I also like that lime is super easy to pick up and understand since it's so simple. You also have the ability to put your tests into YAML configuration file rather than write the tests by hand.
Pascal is entirely right that PHPUnit is much more widely used and you'd be able to use it in non-symfony projects. There is even a plugin for it, PHPUnit symfony plugin. My best advice would be to use lime if you just wanted to jump right into writing simple tests while you develop your symfony app. But, if you have the time and hope to use these testing skills outside of the symfony world, or bring in pre-existing PHPUnit tests into your symfony code, it'd be worth your time to check out the plugin and give it a spin.

Where can I find large php5 best practices project?

I'm trying to find a project that incorporates the "best practices" that are discussed and debated on a daily basis for almost all languages but I'm trying to focus on php5.
Is there a php5 open source project that I can comb through to see working examples of project that exemplifies Units Tests, Dependency Injection and other best practices
I'm basically researching for a new large project and wanted to see a shining example project in all it's glory instead of the snippets of code that are endlessly debated. Since this project will not inherit a whole bunch of legacy code I'm really trying to get things right from the start.
It seems like you are looking for something like Zend Framework!
Check out Kohana Framework too. In fact, most of the popular frameworks have great PHP code. I can not say the same for Wordpress, osCommerce, etc. Magento seems to be OK, maybe a little over engineered.
Here are the list of few libraries which are having good php standards
Laravel - PHP Framework with tons of goodies
Guzzle - CURL library
PHPUnit - PHP Testing Framework
Carbon - DateTime handling library
Faker - For generating fake data
Many more are there, the following link will help you more
https://github.com/uhub/awesome-php

Categories