Continuing with our series. We have seen in the last episode of this series, namely here, that we wish we could have a simpler configuration for getting phabric into our BDD flow within Symfony2 development.
This time we will go ahead and setup Phabric in a “standalone” fashion. And will try to reuse a lot of what symfony2 has already done for us and that we don’t need to setup again and again.
First we start setting phabric repository into our dependency file deps. We insert the following and we don’t need to get its dependencies of phabric since these are gotten already by symfony2 for us on the autoload.php file and also together with the bundles already registered on the AppKernel.php.
// deps [Phabric] git=https://github.com/benwaine/Phabric.git target=/Phabric // autoload 'Phabric' => __DIR__.'/../vendor/Phabric/lib/',
We are now interested in reproducing the long setup given on the readme.md of the phabric repo but using the symfony2 advantages. For that we would like for now hard code our entities definition since this is going to be done ultimately done by @everzet on the BehatBundle. What @everzet will do is to add the phabric specific configuration parameters so they can read from config_test.yml which is symfony configuration file for tests. The inclusion of these parameters will allow us to call
$parameters = $kernel->getParameters(); from within the FeatureContext class so we can pass in turn these to the Phabric bus class. He [@everzet] can of course choose to even better inject the Phabric bus class to the container so that it automatically fetches our database parameters and so all the setup could be done on the config_test.yml under the main behat keyword. Of course options should be set for different database names so that we can have a database for testing and database for other purposes or for different test scenarios. For now we have just chosen to hard-code our parameters at the level of entity definitions.
So after doing in the constructor for the FeatureContext a:
We get the format we need to follow to hard-code the
$parameters_temp = array ( 'event' => array ( 'tableName' => 'event', 'primaryKey' => 'id', 'nameCol' => 'name', 'nameTransformations' => array ( 'Date' => 'datetime', 'Desc' => 'description', ), 'dataTransformations' => array ( 'datetime' => 'UKTOMYSQLDATE', ), ), 'session' => array ( 'tableName' => 'session', 'primaryKey' => 'id', 'nameCol' => 'session_code', 'nameTransformations' => array ( 'Session Code' => 'session_code', ), ), 'attendee' => array ( 'tableName' => 'attendee', 'primaryKey' => 'id', 'nameCol' => 'name', ), 'vote' => array ( 'tableName' => 'vote', 'primaryKey' => 'id', 'nameCol' => NULL, 'nameTransformations' => array ( 'Attendee' => 'attendee_id', 'Session Code' => 'session_id', ), 'dataTransformations' => array ( 'attendee_id' => 'ATTENDEELOOKUP', 'session_id' => 'SESSIONLOOKUP', 'vote' => 'UPDOWNTOINT', ), ), );
Now on your FeatureContext.php class:
$this->doctrine = $this->getContainer()->get('doctrine'); $this->db = $this->doctrine->getConnection(); $datasource = new \Phabric\Datasource\Doctrine($this->db, $parameters_temp); $this->phabric = new Phabric($datasource); $this->phabric->createEntitiesFromConfig($parameters_temp);
This let us all setup to continue to develop with our behat and phabric setup all under symfony2. Hope you appreciate this blog post and please donate. Thanks!