Similarities and Differences Between PHPUnit and PHPSpec - php

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.

Related

PHP Framework for TDD

I am starting work on a personal project which should (hopefully) develop into a startup, the project will need to scale well and I would prefer to invest the time now in TDD.
I am a big Lithium fan, and I am aware that Lithium have their own built in test suite, but I can't find any solid documentation on it and I have never done any real TDD before.
Is there a better way for me to go? Or should I just stick in with Lithium and grind the learning process?
EDIT: Just to clarify. I am talking about PHP Frameworks, not testing frameworks.
If you think, that your project might actually grow into something large, you should write it without the use of framework. The problem with frameworks in general is that they are made with "everything and a kitchen sink" methodology.
You would be much better off, if you build it all from scratch (maybe borrowing some parts you like from Lithium) and use PHPUnit as your testing suite/framework.
Also, i would strongly recommend watching this lecture (and maybe some others from same series), for some general pointers.
Well, if you do plan on developing it in Lithium, then I would definitely stick with the integrated testing framework that's built into lithium.
Find it here:
http://li3.me/docs/manual/quality-code/testing.wiki
If you want to figure out how to integrate tdd into your normal development, I would recommend you pick up one of the .net mvc books by Steve Sanderson (since you seem to do a bit of .net already).
It should only take a few days of working though that book for you to get a solid understanding of how to integrate tdd into your development routine, since that book heavily emphasizes unit testing in development.
Good luck with your start up.
Have a look into Zend framework. It's one of the biggest and most comprehensive frameworks out there. Also it embraces MVC be default.
It also has a built in support for PHPUnit using Zend_Test.

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.

Solutions for testing entire features of an app

EDIT: to clarify - I am asking for advice on both unit testing and user interface testing.
Currently, I don't use TDD. While I am developing an application I am constantly testing what I am working on. Testing iteration could be anything from minor function changes to entire models. I try not to code too much before I test. I like instant feedback.
Of course, with experience I can see potential problems or bugs occurring as I'm coding.
BUT, after an application is complete I will usually go through the entire app on the frontend and ensure all functions are working as expected. This means literally everything. Every add/edit/delete, sort, filter, even broken links and such.
This can take a lot of time sometimes but it does ensure my work hardly ever contains bugs after deployment.
However, I'm looking for a more standard solution. What do experienced developers do? Assume for a moment I am a single developer and so do not have a testing department etc
Do you hire beta testers (no good if app is sensitive to public use)?
Is it viable to build a series of 'general' unit tests which can for example test ALL sorting, filter functions. One for testing ALL add/edit/delete functions.
Love to hear your feedback. Will be changing the way I develop based on suggestions.
Of course as David said : Unit-testing for models and helpers, of course.
and I need to add Selenium
Selenium is a robust set of tools that supports rapid development of
test automation for web-based
applications. Selenium provides a rich
set of testing functions specifically
geared to the needs of testing of a
web application. These operations are
highly flexible, allowing many options
for locating UI elements and comparing
expected test results against actual
application behavior.
which is amazing :
watch the 2 min intro
http://seleniumhq.org/movies/intro.mov
How Selenium Works
Testing with PHPUnit and Selenium
Unit-testing for models and helpers, of course.
But you can do unit-testing on "page-requests", as well. See, for example:
Content with Style - Unit testing controllers with Zend Framework
That's a step towards integration testing. But for issues of layout and visual aesthetics, you're pretty much stuck with walking-through each request with your browser.
Usually what you code works is not that the problem, very nice if you also write tests for it. The problem is that you need to test the integration of your changes every time you make commit.
If you like instant feedback,as I do, probably you should have a look at Continuous Integration.
I've started using Hudson as CI server and I am not regretting it!

zend-framework versus Kohana versus Symfony [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Which one of this frameworks would you recommend to someone who knows the basics of PHP?
What are the advantages and disadvantages?
I wouldn't suggest any frameworks to someone who knows just the basics. Instead, I'd suggest to get a firm grip on OOP and the most common Design Patterns first, because that is what you will find in these frameworks. It also doesn't hurt to know your way around the various available PHP libs and extensions.
I think frameworks are a double edged sword for beginners. You may be able to do more in less time in many cases but in other cases (not a few) you will make mistakes because you do not understand the complexity of the framework code. I think you should be able to read a framework and understand its architecture if you want to use it.
That said it seems that the real cracks use Symfony. It might become or might already be the best, most versatile, most powerfull framework out there. But it definitely needs a lot of understanding of the principles of programming as well as web techonology and server technology in general.
Also very powerfull and much easier to start with is Zend Framework. It can definitely do much more for you than Kohana.
If you want a lightweight framework, Kohana is a good choice too. It has come a long way the last months and I think it is rapidly establishing itself as the new lightweight favourite.
So all in all, the three frameworks you mentioned are the three top frameworks on the PHP framework market at the moment and you won't make a mistake with any of them.
UPDATE: It is now 8 years later and Kohana is no longer maintained. Laravel would be my current recommendation for a relatively simple yet very powerful PHP framework.
Even though ZF is well established and well documented, I would suggest Kohana since it is quite a bit less complex. It is very easy to start tinkering with it by simply downloading or cloning the sample application from github.
Symphony is not for beginners. I disagree that frameworks in general are not for beginners. Starting with a blank file and no framework leaves all of the architectural design up to someone who has no idea what they are doing while starting with a lightweight framework like Kohana gives you a well-organised platform and documentation to hit the ground running. Learning OO without any examples to guide you is very difficult since you don't already know what good OO design looks like.
After downloading/cloning the Kohana sample app, hit the docs and you'll be writing well-designed OO code in no time.
For a beginner and using the three examples you gave I would say start with Kohana(or Code Igniter) for these reasons.
It's a lightweight framework which is a good starting point for full PHP development because it serves as a guide in how to organize a project in a language that doesn't have a lot of structure on it's own
Introduces basic MVC concepts.
Has basic features that will be useful in any PHP project e.g. caching, data filtering etc
I would then move on the Zend Framework if you plan or strive to work on larger projects for these reasons:
Kohana documentation is greatly lacking (it's manageable for a beginner because you end up poking around and see what makes a framework tick so that they don't see like this ominous holy code which is a plus; but in a major project with timelines it's annoying)
Kohana enforces certain conventions which is often inconvenient in major projects
Lacks mature features that are useful in "enterprise" development e.g. a decent unit testing system (there is rudimentary phpunit modules to use in Kohana and you can certainly use base PHPUnit but in contrast Zend Framework has extended PHPUnit functionality to better suite it's framework)
Better support. Zend framework has the Zend Company behind it as well as a huge community. This is a huge win for them because it permeates in everything about the framework e.g. configuration is thought out much better in Zend framework,more robust security featues, proper class autoloading based on PEAR namespacing, and it has a plethora of contributed components. Some of these benefits you can shrug of when starting but become invaluable when taking on large projects.
I've not used symfony but from what I can tell that also has some useful features once you get more versed in PHP (better ORM, better scaffolding etc). Synopsis: Kohana is a good start but I'd advise against roosting there if you plan to get into PHP beyond small sites.
In your case I would go with (in this order):
Kohana
Zend Framework
Since they are easier to pick up (specially for a beginner) than Symphony.
I always wondered why people say that not providing a unit test system is a major drawback in a framework. Well, testing you app is your responsibility and you should use the tools you're most comfortable with. Me, for instance, prefer SimpleTest and are bothered with framework that come bundled with and promote the use of their own testing system. Why learn another unit test system when SimpleTest is more than enough?
Notice that providing a unit test system and unit testing the framework is two completely different things. The framework should be unit tested, period. But for this task, the developers of the framework may use the tool they prefer most. They may even roll their own test framework (it seems that some people never learn and keep reinventing the wheel). However, (IMHO) the framework test should be kept separate from the framework itself. It shouldn't even be included on the framework tarball, but be kept as a separate package that interest only to developers of the framework.
Just my 2c.

Categories