Assetic The Latest Fix!

This is real quick for when you get an exception of the sort of the route problem.

An exception has been thrown during the rendering of a template ("Route "_assetic_817694b" does not exist.") in AlomWebsiteBundle:tylesheets.html.twig at line 1.

The solution is simple, just telling assetic to scan that bundle:

assetic:
    debug:          %kernel.debug%
    use_controller: false
    bundles:        [ AlomWebsiteBundle ]
...

Make sure you `php app/console cache:clear`.

Thanks to josiah for the tip. Encouragements in all good.

Git GUI Tools

I recently found about gui tools for git. I knew about gitk and merge tools but was not aware there was a gui that could help you remember or explain some of the concepts of git one use daily. The gui can be started from the cli:

$ git gui

And it will show you something like:

I tested it on the following task. I had to filter the changes done in certain files. I had affected some of the core files where it was unacceptable and other core files where my changes were meant to be. I had to first rebase and squash all my commits with:

git rebase -i HEAD~2
// then set to `s` the commits

Then I would proceed with the `gui` tools to select ammend last commit, and could remove the hunks/changes made to certain core files. Thereby I cleaned/filtered all my commits while I was squashing them. This could have been a nightmare or longer process without the gui tools.
If say I have had the need to enter some changes I could have commit my change and then squash and follow the same pattern of operations.

Hope this helps!

PHPSpec now running specs on itself with Composer and Travis!

PHPSpec now run its own specification examples on itself with the help of composer and travis.
Composer is the tool to automate dependencies. PHPSpec now has a direct dependency on Mockery/Mockery and when installed through composer on can run the tests with `./scripts/phpspec-composer.php spec/` provided previously we have run `composer.phar install`. If you don’t know how to get the install step take a look at the earlier posts that teach you just that.

In order to have a solid stable version of phpspec that can be well tested or rather specified we used `travis` continuous integration service. With travis we are able to tell it to test phpspec specifications in any version of php and in any pre-configured environment.
This is the PR send that implements all the changes: https://github.com/phpspec/phpspec/pull/59/files.
And here is the output on travis:

PSSMockeryBundle + PHPSpec: The Automation Of Mocking Services Begins!

Let’s say we want to spec a service we are trying to design and we want to use PHPSpec in order to do that.
Our system runs supported by the Symfony2 Components/Framework and according to the rules of the Dependency Injection game we have a client running the application from where we can get all the services of the project the container holds.
Since our service is meant to live within this “Sitz im Leben” or context and would need some interaction with other services we would like to develop the service classes right without leaving at any time this environment.

Welcome to PSSMockeryBundle world. Thanks to Jakub Zalas creator of PSSMockeryBundle, we have something that was meant to solve the problem indicated above by setting up a base class for the container in which we can easily mock any service on the container. Tie this with PHPSpec and you are about to discover a framework setup in which anyone can easily start creating, stubbing, mocking and perfecting their service design for their bundles and craft carefully their dependencies on other services.

<?php
namespace Acme\DemoBundle\Spec\Model;
 
use Symfony\Bundle\FrameworkBundle\Spec\WebSpec;
use Acme\DemoBundle\Model\MyService;
use Twig_Environment;
 
class DescribeMyService extends WebSpec
{
    protected $container;
    protected $client;
    protected $serviceUnderSpec;
 
    public function before()
    {
        $this->client = self::createClient();
        $this->container = $this->client->getContainer();
        $this->serviceUnderSpec = $this->spec(new MyService($this->container));
    }
 
    /**
     * Specking MyService class mocking another service directly related
     */
    public function itShouldGetCreateDirectoryUsingFileSystemServiceFromContainer()
    {
        $filesystemMock = $this->container->mock('filesystem', 'Symfony\Component\Filesystem\Filesystem');
        $filesystemMock->shouldReceive('mkdir')->once()->andReturn(true);
 
        $this->serviceUnderSpec->methodUsingFileSystem()->should->beTrue();
    }
 
    /**
     * Specking MyService method that uses the router service
     * we do not mock the routing but we do mock the Twig_Environment service
     * used by the router
     */
    public function itShouldIndirectlyMockServiceTheRouterDependsOn()
    {
        $twigEnvironmentMock = $this->container->mock('twig','\Twig_Environment');
        $this->serviceUnderSpec->methodUsingRouter()->should->be('/');
    }
}

We first have created a Spec class to speck our new service `MyService` non-existent at this time. The idea is to write one example method at a time. Here we have just gone ahead and written the two we are interested in demoing. Then we proceed to run:

~ phpspec src/Acme/DemoBundle/Spec/

Then we get an error telling us to create the methods on our empty class:

~ phpspec src/Acme/DemoBundle/Spec/
EE
 
Exceptions:
 
  1) Acme\DemoBundle\Spec\Model\MyService should get create directory using file system service from container
     Failure\Exception: $this->runExamples($exampleGroup, $reporter);
     ErrorException: Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Acme\DemoBundle\Model\MyService' does not have a method 'methodUsingFileSystem' in /home/cordoval/sites-2/spec-symfony/vendor/phpspec/src/PHPSpec/Specification/Interceptor/Object.php line 66
 
  2) Acme\DemoBundle\Spec\Model\MyService should run command on client
     Failure\Exception: $this->runExamples($exampleGroup, $reporter);
     ErrorException: Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Acme\DemoBundle\Model\MyService' does not have a method 'methodUsingRouter' in /home/cordoval/sites-2/spec-symfony/vendor/phpspec/src/PHPSpec/Specification/Interceptor/Object.php line 66
 
Finished in 0.052649 seconds
2 examples, 2 exceptions

Next is writing just about enough code on our Service class to make the examples pass. For that we take a look at our `MyService` class:

<?php
namespace Acme\DemoBundle\Model;
 
class MyService
{
    protected $container;
 
    public function __construct($container)
    {
        $this->container = $container;
    }
 
    public function methodUsingFileSystem()
    {
        $filesystem = $this->container->get('filesystem');
        return $filesystem->mkdir('folder1');
    }
 
    public function methodUsingRouter()
    {
        $router = $this->container->get('router');
        return $router->generate('_welcome');
    }
 
    public function checkInternalResponse()
    {
        return true;
    }
}

If you fail to meet the requirements with the writing of your methods, don’t worry PHPSpec is here to guide you make that example green:

~ phpspec src/Acme/DemoBundle/Spec/
.F
 
Failures:
 
  1) Acme\DemoBundle\Spec\Model\MyService should run command on client
     Failure\Error: $this->serviceUnderSpec->methodUsingRouter()->should->be('/somepath');
     expected '/somepath', got '/' (using be())
     # ./src/Acme/DemoBundle/Spec/Model/MyServiceSpec.php:39

Finished in 0.060213 seconds
2 examples, 1 failure

If we get everything right after all we should get:

~ phpspec src/Acme/DemoBundle/Spec/ -fd -c -b
Acme\DemoBundle\Spec\Model\MyService
  should get create directory using file system service from container
  should run command on client
 
Finished in 0.074234 seconds
2 examples

Notice that the examples are simple and are meant for you to see how easy is to use PHPSpec with PSSMockeryBundle within Symfony. We are using the spec-symfony sandbox available in our PHPSpec repos. A lot of effort is being put these days in bringing powerful tools for BDD Spec type of BDD methodology into Symfony2. PHPSpecBundle is the leading bundle along these lines that will have commands to generate the skeletons required to practice good BDD Spec type on Symfony2. BDD Spec and BDD Scenario complement each other so that is why it is important to keep the and use them together because they are more powerful together than separate.

I thank the Lord Jesus Christ for all the help in completing this effort through good friends and very good willing people like Jakub who is an expert in symfony2. We brainstormed once and next day he had the bundle ready. This is a very interesting community accomplishment! bravo!

KnpLabs Help To The Symfony2 Community: The Review

I would like to strike a note of appreciation to thank deeply the KnpLabs in the US. I lived in the southeast area of the US for 5 years and I feel like I know their kind ways and goodwill of helping others. They not only have worked on giving tutorials or workshops throughout the world in shape of conferences but they have also provided free resources readily available for the avid dispossessed stalker-reader. I am now remembering their help in form mainly of 1) the Christmas gift @weaverryan gave everybody on his free slides with code included, 2) KnpLabps Ipsum demo and repos, 3) One to one help in the old days about how to capistrano deploy symfony2 the right way (disclosed just for me or so I thought), 4) and many many other tips and tricks now in this latest video, like the play.php script (which was not really mind games but really just bringing out what is inside the handle method), and 5) the thing we all know him for, the sf2 `docu`. If I ever come back to the southeast of my second home I would rent a car with my family and drive from South Carolina to Nashville just to greet these guys.

That said, let’s dig once more and dissect for fun the latest knpuniversity tutorial channel:

The tutorial for autoloader was a token of what one could expect of their professionalism in their other extended video Starting in Symfony2 Tutorial. Its make-even-a-3-year-old-child-understand clean type of communication has been compressed in time for the busiest of us and yet still conveys a direct ready-to-apply batch of pro-tip treasures. I myself learned three new things, 1) the tip for debugging right on play.php script unrolling the handle method and recreating the request with Request::createFromGlobals, 2) an easy one, the tip on PHPStorm for Go To Class, and 3) the php app/console doctrine:fixtures:load –append, never used it before even though it was there but I like to know it is there now :D. Of course the other parts of the tutorial are thrilling. Just that I learned it the painful way, being slapped again and again on the mailing list and ignored in the IRC channel. Of course I always get help from the goodies. So that is why I am still alive and learning 😀 and now writing this review for what I think is a worth looking tutorials PHP and Symfony Tutorials. My thought is there are a lot of people who know a lot, some more than others, but few teach it to others. Thankfully the symfony2 community does not lack great individuals who like to pass the baton.

I watched the 1 hour video and it felt like it was 10 minutes. I thirst for more of course, but it was so complete and thrilling. It was a gap filling device in my newbie education. It felt so short to me because I enjoyed it so much understanding details in clear and proper conveyed English. Usually foreign developers cut to pieces our loved southern English, and this video just made it justice for once. Communication skills are important and help develop the other side of our brain!

The video also transpires some explanations that drip Symfony2 philosophy, it is a good complement to the series @fabpot is currently writing, you will enjoy his revised written English as much as I do. He is on chapter 7 now so hurry up, they are short and easy to deal with and full of keen ideas.

I stay with the code of the play.php script and I will use it to understand inner parts of the Symfony2 framework more or at least to dig into ideas and try to explore further. I think that a video that shows you how to fish is a good video and this tip aimed in this direction.

It feels good when you understand one thing over and over and more and more. This is the case for Symfony2, it just gets better when you understand it further and further.

In behalf of the Symfony2 Community (yes I often like to take attributions and it is cool with you :D), thanks guys for this video and more to come.