
Installing PHP tools
We installed some plugins in our Jenkins, but to make these plugins work, we need to install some PHP tools on our EC2 instance. We can install these tools via Composer on our Symfony project, but this is not a good practice. They will sit in the vendor/
directory and make our Symfony project big and heavy.
Instead, we are going to install them in the CI server itself and benefit from them for every project we define in Jenkins:
- Assuming that the SSH connection to our EC2 instance is still live, open a terminal window and add the following PEAR channels to the system:
$ sudo pear channel-discover pear.pdepend.org $ sudo pear channel-discover pear.phpmd.org $ sudo pear channel-discover pear.phpdoc.org $ sudo pear channel-discover pear.symfony-project.com
- Now install PHP tools as follows:
$ sudo pear install pdepend/PHP_Depend $ sudo pear install phpmd/PHP_PMD $ sudo pear install phpunit/phpcpd $ sudo pear install phpunit/phploc $ sudo pear install --alldeps phpunit/PHP_CodeBrowser $ sudo pear install phpdoc/phpDocumentor-alpha
Note
You might have used some of these tools and some of them might look new to you. I am not going to go through all of them and explain what they do. It needs another book to go through all the details. Instead, I encourage you to have a look at their documentation and briefly familiarize yourself with their functions.
You can find a list of URLs for these tools on their official website or https://packagist.org/.
One last thing that you may notice is why we didn't install these packages via Composer. Note the following command:
$ sudo pear install phpunit/phpcpd
It is better if you replace the preceding command with this one:
$ sudo composer global require 'sebastian/phpcpd=*'
It is certainly better to use Composer. However, there is a catch to this. I've noticed that when you install packages via Composer, for some reason Jenkins doesn't like it and fixing build bugs might give you a major headache. So, to play it safe, install them via PEAR channel and play with Jenkins for a while. When you master the basics, there is always room for creating more EC2 instances and setting up the required tools like a pro.
You can find more about the basics on the http://jenkins.org/ website.
Sniff Symfony codes
Symfony has its own coding standards. To benefit from CodeSniffer in our project, we need to introduce Symfony standards and make it the default standard:
- First, find the PEAR directory:
$ pear config-show | grep php_dir
- Now, go to the
Standards
folder in CodeSniffer (in our EC2 instance, the path iscd /usr/share/php/PHP/CodeSniffer/Standards/
) and clone the following repository:$ sudo git clone git://github.com/escapestudios/Symfony2-coding-standard.git Symfony2
- Now make Symfony the default coding standard:
$ phpcs --config-set default_standard Symfony2