views:

55

answers:

3

I'm a .net developer so pardon me for not knowing anything about PHP. I read some things on the net but I can't say how it compares to Asp.net MVC in terms of automated testing.

I tend to think that PHP is very much like classic ASP except that it's OOP (is it?). In order to improve its testability you have to follow certain development patterns and code style to provide SoC (similar to Asp.net WebForm where you have to do MVP for instance but you're still light years away from what Asp.net MVC gives you out of the box).

So. How does PHP compare to Asp.net MVC in terms of writing automated tests (most notably unit tests of course)? Do I have to use certain libraries? Do I have to follow certain rules/patterns to make it work?

How about continuous integration? Can test be auto run there as well?

+1  A: 

There are three that I use, depending on the situation: SimpleTest, PHPUnit, and Zend_Test (which is really just a wrapper for PHPUnit to be used with the Zend Framework). Of these, SimpleTest really is easier. However, PHPUnit provides a lot of power and flexibility.

Andrew Sledge
So basically what you're saying is: If you want to do unit testing you have to take care of SoC (and naturally for IoC as usually anywhere else) by yourself and then use some unit testing library + separate test runner to make it happen? Is that it?
Robert Koritnik
@Robert How should testing take care of SoC (assuming Separation of Concerns)? Isn't that a programming concern unrelated to testing?
ircmaxell
@ircmaxell: testing doesn't take care of SoC. Application framework does in Asp.net MVC. In PHP you probably have to take care for it yourself either by hand or using some library I suppose (similar to using MVVM Prizm framework with Silverlight). SoC is however imperative part to increase testability.
Robert Koritnik
@Robert: Believe me, I understand the importance of SoC. What I'm not understanding is how a framework (application or testing) "takes care of SOC" for you. Sure, it can help by pushing you towards a convention of separating concerns (As MVC does), but it's ultimately up to you to do the separation. I'm not sure how a library will do it for you (in any case, yet alone PHP or ASP). If you're asking for an architectural framework to guide you down the path, there are [tons for PHP](http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#PHP_2). But that's not doing it for you...
ircmaxell
I don't know how familiar you're with Asp.net MVC framework, but the way a developer has to write code forces you to separate each functional unit. Controllers are simple classes that don't access any view's elements. They just provide data for them and return a view. Framework executes the view rendering (and flushing of the data to it) internally. Model on the other hand is also separated from controllers (not to mention views). So SoC is inherently forced by the project structure. You have to of course take care of IoC, but SoC is something you don't have to think about so much.
Robert Koritnik
+1  A: 

I'm not a .net developer, so I can't compare the two, but I can help fill in a few gaps about PHP.

First, while PHP does support classes and OOP like you're accustomed to, it's not necessary. In fact, some PHP-based projects (such as Drupal) have little to no OO code in them.

As for testing PHP code, you'll probably want to use PHPUnit. It implements the xUnit system for testing code in PHP. But if PHPUnit isn't to your liking, then you may want to check out SimpleTest, a slightly different PHP testing framework.

Douglas Muth
Robert Koritnik
Not necessarily. There's no reason you couldn't write code to use PHPUnit to test code that's just a bunch of functions. But it does make setup/teardown much more challenging, since in an OO environment, creating a new object should (in theory) let you start with a clean slate.
Douglas Muth
Right. Basically you can unit test standard Asp.net webforms apps as well even without any pattern (like MVP) but you're into a lot of work and trouble. Similar here. Thanks for the info. +1
Robert Koritnik
A: 

php doesn't compare to asp.net mvc as php is a language like c# They both have OO and you can test methods and classes like you do in asp.net

Just like in asp.net you have a mvc in php too. You might want to take a look at some frameworks like Symfony that work on the same mvc model.

Testing in .net is done with NUnit or others, in PHP you have some simular ones like PHPUnit and in Symfony there is Lime too.

actually, I'm in the oposit situation comming from php and now in c# development, and it's all almost the same...

tests can be autorun, in .net you might know nant (automated testing and build tool), ant is the same for php/java and hudson as a tool to get an overview on all builds.

Kennethvr
Well I must disagree with you to some degree. PHP is a language. Granted. But it's also a web platform. C# on the other hand is not. Asp.net MVC is a platform but not a language. So. I'm aware of the wast selection of libraries that are available for any web platform to do MVC/MVVM/MVP pattern. But I suppose there's no other platform that enforces SoC the way that Asp.net MVC does. You can't do it any other way than that. So implicit SoC so to speak. On other platforms you can always do however you want. Same with Asp.net WebForms.
Robert Koritnik
I also admit that my question wasn't written in the best way. But it's too late for it now to change, because it would automatically discard all your answers. So thank you for providing your input.
Robert Koritnik