PHPSpec-Symfony2 Lib Work


So we are working on the BDD approach of this post. Most specifically if we look at the code below:

namespace Review;
// SpecHelper contains the usual ZF bootstrap
// copied from public/index.php
require_once __DIR__ . '/../../SpecHelper.php';
use \PHPSpec\Context\Zend\View as ViewContext;
class DescribeIndex extends ViewContext
    function itRendersTheSelectedVideo()
        $video = \Mockery::mock(
            'Application_Model_Video', array('getName' => 'Revolution OS'));
        $this->assign('video', $video);
        $this->rendered->should->contain('Revolution OS');

We are trying to find the equivalent of ZendView object wrapped on the class ViewContext which is \PHPSpec\Context\Zend\View. In there as you can see from the methods below:

public function render()
        $this->rendered = $this->spec($this->_view->render($this->_viewScript));

The methods are meant to be wrapped with$this->spec(). However the object $this->_view is the object of interest we are trying to find the equivalent in symfony2 to translate in our new port file at hand \PHPSpec\Context\Symfony2\View.
With Zend that _view object is assigned as:

require_once 'Zend/View.php';
        $this->_view = new \Zend_View(array('basePath' => $basePath));

There has been some discussions that an equivalent object for a Symfony2 version could be the class Twig_Template from Twig. But I don’t really now how this could be done, so I am asking for suggestions/help. We have to be able to call methods such as those equivalent ->render and others as shown in the class.

Zend_View class is described as very independent and even can be used without problems however there is no need to install a whole framework just when Symfony2 has its equivalent.

This is a snippet coming from @ManuelAC:

require_once __DIR__ . '/../app/bootstrap.php.cache';
require_once __DIR__ . '/../app/AppKernel.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\Templating\TemplateNameParser;
$kernel = new AppKernel('dev', true);
// Some variables
$template = "index.html.twig";
$templateDi = "CompanyBundleName:ViewFolderName:";
$templateWithoutDi = "/../src/CompanyName/BundleName/Resources/views/";
// Dependency Injection method
$twigDi = $kernel->getContainer()->get("twig");
// Standard
$loader = new Twig_Loader_Filesystem(__DIR__ . $templateWithoutDi);
$env = new Twig_Environment($loader, array('debug' => true));
$twig = new TwigEngine($env, new TemplateNameParser());
// With dependency injection, notice the Company:Folder:Template shortcut
$twigDi->render("CompanyBundleName:ViewFolderName:" . $template);
// Without dependency injection

Symfony2 TDD with Phabric: Series 1

I have read a bit about Phabric. Phabric responds to the need of further controlling data setup on behat scenarios at a high level of abstraction. Basically it is the doctrine:fixtures:load of behat or more properly it is the tdd version of that turning gherkin tables into database data.

The discussion is here for the first issue filed when Phabric saw the light. Once the Behat conditional dependency is included into BehatBundle we would be able to load the Phabric too within our Symfony2 project. Implementing a Symfony2 bundle ourselves would involve that we have to pass by injection a service into the Behat context. That may result in more difficulties at this time.

Thinking in how it could be done, perhaps, first we can unfold this as adding a regular dependency. That is basically modifying the xml file for Behat, however that is sourced by BehatBundle from the Behat behat.xml.
There is another xml file for services that is loaded here.
So I wonder if we could use this to insert that dependency? What other further modifications would need to take place.
It would be great to develop an example for how to make these guys play together within Symfony2.

Until next time for part 2.

Symfony2 Integrated TDD: TestBundle

Introducing TestBundle[1], a Symfony2 bundle that integrates TDD methodology for the main frameworks Behat, PHPSpec, and PHPUnit into one development tool. It is created to foster the BDD methodology into Symfony2 app development.

Instructions to install:

// AppKernel.php
php new Cordova\Bundle\TestBundle\CordovaTestBundle(),
// autoload.php
    'Cordova'          => __DIR__.'/../vendor/bundles',
// deps
// update
bin/vendors update
// creates autotest.phar
cd vendor/PHPAutotest

And here is its usage:

php app/console test:auto vendor/PHPAutotest/demo/Behat/features/minesweeper.feature

What can you do with it?
Well it depends how well one knows the integration of all the frameworks. Basically this bundle currently exploits PHPAutotest[2] and brings it into Symfony2 framework developers to foster new ways of automation and aid in the TDD task. There is a sweepminer’s example you can try and I am working on bringing more information into testing it with a complete integrated flow from start to end.

If you have further ideas of how much more this bundle can include you are welcome to post below on the comments. And if you would like to boost development of this bundle then please donations are a strong motivation (see link above).

Praise the Lord Jesus Christ!

[1] TestBundle Repository.
[2] PHPAutotest Tool Repository intro.

Prototype attribute on Symfony2 Forms

This is a snippet for collaboration purposes on dynamic forms:

<div id="khepin_productbundle_producttype_tags" data-prototype="
<label  class="">$$name$$</label>
<div id="khepin_productbundle_producttype_tags_$$name$$">
  <label for="khepin_productbundle_producttype_tags_$$name$$_name" class="">Name</label>
  <input type="text" id="khepin_productbundle_producttype_tags_$$name$$_name" name="khepin_productbundle_producttype[tags][$$name$$][name]" required="required" maxlength="255" value="" class="input-text" />

Here it is sbsien 🙂

Also please fix the css if you can.

PS> All this is regarding this link

Free Shared Hosting Git Repository For Your Teams!

If you don’t want to pay for codebasehq, github or any other service for private git repositories then do this on your shared hosting account:

// log into your server and install latest git:
mkdir ~/temp
cd ~/temp
curl -O
tar xvfz git-1.X...tar.gz
cd git-1.X..
./configure --prefix=$HOME
make SHELL="/bin/bash" install
// test if installed
git --version
// check which one
which git
// if above fails compile git on user space (google this)
// then continue
// add origin to remotes
mkdir -p ~/repos/yourproject.git
cd ~/repos/yourproject.git
git --bare init
// now from local enter the folder where your git tracked files are
git remote add origin ssh://
// put this on your .git/config so you can do git pull and push easily
[branch "master"]
        remote = origin
        merge = refs/heads/master
// to avoid typing passwords
// enjoy and please donate!

It has been verified with this hosting here of which I am an affiliate too because I do recommend it and work with it.

Adapted from here.