PHPSpec-Symfony2 Lib Work

WIP

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->render();
        $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:

<?php
 
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);
$kernel->loadClassCache();
$kernel->init();
$kernel->boot();
 
// 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
$twig->render($template);

http://www.pastie.org/2459860

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>