Symfony development from a Drupal perspective
Submitted by clemens on Sun, 2012/05/20 - 11:31am
While still working on D8MI Let Symfony Translation component handle language messages I needed to code for Symfony to on the Translation component. So how does that work writing and testing Symfony code?
cd /tmp git clone https://github.com/symfony/symfony.git cd symfony ls
Dependency managementNote the composer.json which is key to get the Symfony phpunit test running. As a Drupal developer new thing are to be learned. Composer manages all dependencies needed to run either a Symfony application or the phpunit test. As we are developing for Drupal but need to be able to convert Drupal Gettext related test cases to Symfony we need to be able to run Symfony unit tests.
Awesome composerSo let's start by downloading composer from http://getcomposer.org/download/ and follow their instruction.
This installs a composer.phar file which is capable to process the composer.json and download all dependencies needed to run the phpunit tests. You can run
cd /tmp/symfony curl -s http://getcomposer.org/installer | php
to see all runtime dependencies being downloaded and installed. As a Symfony developer you need the development dependencies too. Install these through composer.
php composer.phar install
which installs the development dependencies too. I like this composer stuff to get started.
php composer.phar install --dev
Running phpunitRunning all tests is easy. (When you don't have phpunit see below for how I managed this on a Mac OS 10.6)
and see all tests running smoothly. Note the S's which are skipped unit tests.
cd /tmp/symfony phpunit
Run the Translation componentAs this blog is about D8MI we need to run the Translation tests.
cd /tmp/symfony phpunit src/Symfony/Component/Translation/
What are those skipped tests?
cd /tmp/symfony phpunit --verbose src/Symfony/Component/Translation/
Changing a fixtureBy downloading ie http://ftp.drupal.org/files/translations/7.x/drupal/drupal-7.11.nl.po we see these files have no whitelines between each translation item.
so lets test this with Symfony by editing one of the tests fixtures.
msgid "Home" msgstr "Inici" msgid "User interface" msgstr "Interfície d'usuari"
This will show two failures. So our unittests do some good work.
cd /tmp/symfony vi src/Symfony/Component/Translation/Tests/fixtures/resources.po # remove all whitelines (this is just the last line) or just add some (depending on Symfony current state) phpunit src/Symfony/Component/Translation/
Installing phpunitInstalling phpunit (on Mac Os 10.6) This is from a lame history so I commented out some command.
sudo su - pear channel-discover pear.phpunit.de # pear channel-discover components.ez.no # pear channel-discover pear.symfony-project.com # pear install phpunit/PHPUnit # pear upgrade pear install --alldeps phpunit/PHPUnit