PHP

Tutorials and guides on PHP

Don’t prioritise controller testing over unit testing

There are lots of types of tests that programmers should perform, unit testing, functional testing, integration testing etc… Often I hear programmers confuse controller testing with unit testing. They see that a functional test offers more code coverage and so they focus on controller testing instead of units of code.

CSS classes in Symfony2 twig labels

Symfony is a PHP framework

A quick PHP tutorial showing how to apply css classes to a Symfony 2 label when rending a twig template. The demonstration covers the differences between rendering normal form controls and labels within a twig template.

In short the label attribute is called label_attr and the field attribute is called attr.
Both can have the same available parameters but the label attribute must be the third parameter of the label control

PHPUnit change http host with Symfony

Symfony is a PHP framework

A simple PHP tutorial demonstrating how to change the domain of a phpunit functional test.
This example uses a test written for the Sylius E-commerce framework and changes the domain of a Sylius channel to use a custom host entry.
The default domain is set to localhost but this causes errors when testing against different Sylius channels. This tutorial gives an example of how to overcome this issue by changing the domain within the PHP unit test.

Choosing to finish a Symfony 1.4 site rather than rebuilding it in Symfony2

Symfony is a PHP framework

Symfony2 is the hottest PHP framework out at the moment so you would jump to the assumption that I would build all my projects in the latest and greatest.
Well last week I went against the grain and put a Symfony 1.4 site live. Not a Symfony2 site … I hear you ask!
So whats my reasoning?

Adding arrays together while preserving keys in PHP

PHP is a web based programming language

In this post I will demonstrate how to add arrays together without losing or reassigning the arrays keys in PHP. This is handy if you want to combine two arrays which have defined keys.