The book offers a wide variety of information about PHPUnit. At the very beginning it provides insights how to install PHPUnit and how to set up a development environment. Further, it elaborates on the question why to do tests and how to write code that can be tested easier. Finally it reaches its culmination with more business oriented techniques of “Functional Tests in the Browser using Selenium” and “Continuous Integration”.

I skipped the first chapters about installing PHPUnit and Integration in IDEs, because I use it already in my daily work. But still while flying over the chapters I noticed that there is a good overview of the state of the art and lots of examples that make it much easier for beginners to try things on their own.

For example, there is a short introduction about the dependency manager Composer in the first chapter, which makes the installation of PHPUnit quite simple. There are also other methods mentioned (PEAR, native Linux packages and manual installation), but Composer is much more promoted, which is good in my opinion. It gives even beginners a much more professional feeling.

The second chapter gives an overview about largest or most used IDEs in PHP development: Netbeans, Zend Studio, Eclipse PDT, Phpstorm and shows how to set up a PHPUnit testing environment in each of them. Too bad that Aptana Studio was not mentioned, as it is my tool of choice for my daily work. Anyway everyone has to make their own choice and find out what they like best.

Chapter 3 explains what are tests and why they are important. It gives a good overview of what are testcases, the PHPUnit API with its different testing methods and how to create testcases.

I think when the project is small tests might not be needed, but as it grows they become more and more important. The difficult choice is when to start. Being disciplined in ones way of programming makes it much easier to implement tests later. On the other hand, using tests from the beginning helps to stay disciplined and keep up the code quality.

The Chapters 4 and 5 are about “Testing Dependencies and Exceptions” and “Running Tests from the Command Line”. Especially Chapter 4 includes an extensive example with a lot of code. I will not go into details here, but the use case is well explained. Chapter 5 explains in detail all the command line switches and usages. I think it is a little overkill, but as the book is directed to beginners, it might be fine.

The book gets more and more interesting towards the end. Now we are slowly moving to the more advanced features of PHPUnit: Chapter 6 “Test Isolation and Interaction”, Chapter 8 “Using Test Doubles”, Chapter 9 “Database Testing”, Chapter 10 “Testing APIs” and Chapter 11 “Testing Legacy Code”.

Yes I missed out Chapter 7 “Organizing Tests”. I think it should be moved more to the front of the book, as it is still about configuring PHPUnit and setting up a test suite. I develop mostly with Zend Framework 2 and using the Zend Skeleton Application it is basically everything set up for you, still it is good to know.

Chapter 9 “Database Testing” seems to be the largest chapter in the book. It highlights nicely how database testing works and also gives an introduction to Doctrine 2 ORM. Again a good gotcha for beginners that might not have come across Doctrine yet.

Chapter 10 was especially interesting for me, as I do a lot of API development and I know how difficult it is to do proper testing there. There are some nice examples using the Paypal API, Facebook API and Twitter API. In the last case they use the Twitter library which is integrated in Zend Framework 2. While all the APIs are based on OAuth and basically work in the same way, each example shows a different method of testing.

Chapter 11 “Testing Legary Code” is also an interesting chapter. The horror of every developer is to look into an old project which has to be updated and there is lots of “spaghetti code” inside where updating without destroying is like disarming a bomb. This chapter shows how to test “untestable” code, it include an example of testing some WordPress methods. Since Wordpress has historically grown with the development of PHP it includes lots of spaghetti code from the old times when there was not so much object orientation in PHP. The runkit PHP extension presented in the end of that chapter was new for me. It was really interesting to read about such powerful mechanism that even can override PHP internal methods.

The Chapters 12 and 13 presenting Selenium and Continuous Integration where definitely one of the most interesting chapters for me. Both are things that I wanted to try, but didn’t have the time and need to set up yet. These tools and methods are usually needed only on larger projects where many developers are involved. Not really necessary for beginners, but still good to know.

The book ends with “PHPUnit Alternatives, Extensions, Relatives and BDD“. The book goes away from PHPUnit and shows some alternative frameworks and different methods of testing. It is a good roundup on what can be found out there.

To sum it all up: the book offers state of the art information about testing in PHP and gives many real world examples that beginners can follow well. Even experts can find some useful information that they probably have not used in their daily work yet.

For my taste there was a little too much code in the book. I had the ebook version where it is fine in a way, because you can copy and test the examples yourself, but in a printed version this would be a lot of “wasted” pages. Still publishers will unlikely publish different versions of the same book.

]]>http://tylkowski.net/2014/09/05/review-phpunit-essentials/feed/1258Create a private mediawiki with some public pageshttp://tylkowski.net/2012/09/28/create-a-private-mediawiki-with-some-public-pages/
http://tylkowski.net/2012/09/28/create-a-private-mediawiki-with-some-public-pages/#respondFri, 28 Sep 2012 13:06:13 +0000http://tylkowski.net/?p=231Continue reading "Create a private mediawiki with some public pages"]]>Per site restriction is not possible by default in mediawiki, but there are many ways to create such environment mostly with using extensions. The most easy and flexible way without extensions is described on this page: http://meta.wikimedia.org/wiki/Regexp_wgWhitelistRead

It’s simply done by editing the file include/Title.php and find the line that looks like this in the function userCanRead(). In my version 1.16 it looked minimal different than at the link example:

Introduction

I recently had the chance to take a look at the professional version of Codelobster PHP Edition. For those who may not know it: Codelobster is an IDE specialized on PHP development. Since HTML, CSS and JS are mostly always needed when working with PHP it also includes good support for them.

The IDE is available in two different versions a free one and a professional one. While the free version features mostly everything one might know from other IDEs, the professional version has some neat support for the most famous PHP CMSs (Drupal, Joomla and WordPress), Frameworks (Symfony, CakePHP, CodeIgniter, facebook API, yii framework, smarty), jQuery and an SQL Manager to make the developers life even more easier, than by just using those frameworks.

]]>http://tylkowski.net/2012/03/05/review-codelobster-php-edition/feed/1204PHPUnit: use different dataset on every test in a testcasehttp://tylkowski.net/2011/09/18/phpunit-use-different-dataset-on-every-test-in-a-testcase/
http://tylkowski.net/2011/09/18/phpunit-use-different-dataset-on-every-test-in-a-testcase/#commentsSun, 18 Sep 2011 11:30:28 +0000http://tylkowski.net/?p=190Continue reading "PHPUnit: use different dataset on every test in a testcase"]]>PHPUnit offers the possibility to perform tests based in database fixtures. The common way is like described in the PHPUnit documentation.

But what if you just want to have a small and different dataset on every test?
My way to achieve that is the following:

create a minimal dataset with a table and a column that exist in your database, because getDataSet() has to return an object that implements the PHPUnit_Extensions_Database_DataSet_IDataSet interface.

]]>http://tylkowski.net/2011/09/18/phpunit-use-different-dataset-on-every-test-in-a-testcase/feed/1190Convert phpmyadmin to phpunit xml formathttp://tylkowski.net/2011/09/10/convert-phpmyadmin-to-phpunit-xml-format/
http://tylkowski.net/2011/09/10/convert-phpmyadmin-to-phpunit-xml-format/#commentsSat, 10 Sep 2011 10:43:17 +0000http://tylkowski.net/?p=186Continue reading "Convert phpmyadmin to phpunit xml format"]]>It is always a pain to create datasets for testing. I know the code should make it possible to test without using the database, but this is not always the case. Phpmyadmin offers a good possibility to create datasets by exporting the needed data from a database. The problem here is that the exported format does not match the format needed for phpunit. After digging a while in the net I found out, that there are converters to do this, but they are for older versions of phpmyadmin. Since version 3.3.0 they changed their xml format.

Usage

Example

The converter offers you to combine different tables into one dataset.

Let’s say you don’t want to create a database copy for the test (which should be usually the case) you just make a simple selection of the values that you need for the test and export it as xml file. You do this for all the tables and columns that you need and you end up with some xml files. Put the path to each file as parameter into the function and wait a little. The function will create a output file with all the datasets combined into one, which is ready to be used with php unit

Have fun.

]]>http://tylkowski.net/2011/09/10/convert-phpmyadmin-to-phpunit-xml-format/feed/3186Symfony 2 FAQhttp://tylkowski.net/2011/05/25/symfony-2-faq/
http://tylkowski.net/2011/05/25/symfony-2-faq/#commentsWed, 25 May 2011 07:33:57 +0000http://tylkowski.net/?p=161Continue reading "Symfony 2 FAQ"]]>I recently started to work with symfony 2, a really nice PHP framework. Like Zend but with different concepts. While working with it I will line out some problems I had and solutions I found. This page will gradually be updated.

CLI says on doctrine:schema:create : No Metadata Classes to process.

If you’ve done everything following the documentation this error occurred because there is some inconsisty between the documentation and the implementation.The documentation says (for the PHP annotations) to put @ORMEntity tags in the docblock. The real syntax is @orm:Entity. This behaves the same for all the other tags too (@orm:Table, @orm:Id, …)

]]>http://tylkowski.net/2011/05/25/symfony-2-faq/feed/2161PHP MySQL Chaininghttp://tylkowski.net/2011/05/01/php-mysql-chaining/
http://tylkowski.net/2011/05/01/php-mysql-chaining/#respondSun, 01 May 2011 15:32:59 +0000http://tylkowski.net/?p=145Continue reading "PHP MySQL Chaining"]]>In my last article I wrote about the new Lambda functions of PHP 5.3. Today I will talk about another cool feature. Since PHP version 5.3 it is possible to let functions return objects. This makes chaining like in JavaScript possible.
It is fairly simple: the function just has to return $this in the end and the next function can be added via ->.
Here is an example:

]]>http://tylkowski.net/2011/05/01/php-mysql-chaining/feed/0145PHP Lambda Functions – Anonymous JS-like functions in PHPhttp://tylkowski.net/2011/04/25/php-lambda-functions-anonymous-js-like-functions-in-php/
http://tylkowski.net/2011/04/25/php-lambda-functions-anonymous-js-like-functions-in-php/#respondMon, 25 Apr 2011 07:09:46 +0000http://tylkowski.net/?p=140Continue reading "PHP Lambda Functions – Anonymous JS-like functions in PHP"]]>PHP 5.3 brought some new interesting stuff, I know its out for a while, but I recently started to love this new functionality. Lambda functions are anonymous functions knows as closures and they are really similar to the closures in JavaScript.

The difference from JS is that variables in the closure don’t have access to variables from outside the function, unless they are brought into the closure by using the “use” keyword.
In following there is a nice example:

The “convertHexDecimal” splits the hex string (i.e. #23ef22) into its color components, converts them to decimal and returns an array(red, green, blue).

Cheers

]]>http://tylkowski.net/2011/04/25/php-lambda-functions-anonymous-js-like-functions-in-php/feed/0140Week Calculation in PHPhttp://tylkowski.net/2011/04/17/week-calculation-in-php/
http://tylkowski.net/2011/04/17/week-calculation-in-php/#respondSun, 17 Apr 2011 15:55:46 +0000http://tylkowski.net/?p=128Continue reading "Week Calculation in PHP"]]>Working with Dates is always a problem. PHP just has a limited ability to work properly with dates, some things are not so easy too find. The PEAR Library offers a good amound of possibilities to work with dates, but the price is a massive loss of speed.

After searching a while I found 3 useful functions to work with weeks. Which I adapted to my needs.