Quantcast
Channel: Craft It Online!
Viewing all articles
Browse latest Browse all 92

PHPSpec It Like A Junior: Part V

$
0
0

Previous episodes:

Screen Shot 2013-08-24 at 4.49.31 AM

As I promised sometime and delivering now even though late, here is the Part V of the series.

So I got into phpspecking this Notificator library with this PR. In the way I wanted to have autocomplete for the method matchers so I ended up bootstrapping this stub library called cordoval/phpspec-stubs

Just add it to your composer.json:

//...
    "require-dev": {
        "phpspec/phpspec": "dev-master",     
        "cordoval/phpspec-stubs": "dev-master"
    },

And run:

composer update cordoval/phpspec-stubs

Then you need only one more step to use these amazing stubs library:

<?php
namespace spec\Namshi\Notificator\Notification\Email;
 
use Cordoval\PhpSpec\ObjectBehaviorComplete;
 
class EmailNotificationSpec extends ObjectBehaviorComplete
{
    function let()
    {
        $this->beConstructedWith('recipient', []);
    }
 
    function it_is_initializable()
    {
        $this->shouldHaveType('Namshi\Notificator\Notification\Email\EmailNotification');
        $this->shouldHaveType('Namshi\Notificator\Notification');
        $this->shouldImplement('Namshi\Notificator\Notification\Email\EmailNotificationInterface');
    }
}

It will autocomplete the methods in PHPStorm. Now the library has a growing number of methods so your PR’s are welcome. I will try to explore how to generate the “`ObjectBehaviorComplete“` class from a command in the future. But for now enjoy your free stubs for autocompletion!

Last but not least, take a look at the book I am writing Lean Book on Symfony2 Ecommerce http://pilotci.com

More quality surprises coming in these blog posts but more in the book too!


Viewing all articles
Browse latest Browse all 92

Trending Articles