Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Semaphore CI Blog:
Getting Started with BDD in Laravel
Aug 05, 2015 @ 14:17:43

Bruno Skvorc has written up a tutorial on the Semaphore-CI blog showing you how to get started with behavior-driven development in Laravel applications. He makes use of the Behat and PHPSpec libraries to write and execute the tests.

For many developers BDD is a complicated subject, and getting started with it the right way often does not come easy - especially when you need to implement it into an existing framework. This tutorial aims to help you get a BDD-powered Laravel project up and running in very little time, introducing you to the basic concepts and workflow you'll need to proceed on your own. We'll be installing and using Behat and PhpSpec.

He walks you through the process of getting everything you need installed: a simple Laravel application and Behat (also requiring a bit of setup to make it "play nice" with Laravel). He initializes the Behat directory and explains the concept of "context" and how to configure your Behat installation. He then gets into writing the features, creating a basic test that checks the main page of the Laravel application for the phrase "Laravel 5". A bit of additional PHP code is required to make the tests work (included) and the result is a passing test, executed with just a behat command.

The second half of the article is about PHPSpec, showing how it can be used as a sort of replacement for PHPUnit with a bit more readable syntax. He shows how to write a simple test against an object. Finally, he shows how to combine the powers of Behat and PHPSpec into a single method of testing, using PHPSpec behind the scenes in the Behat context to help with testing assertions.

tagged: phpunit phpspec testing behaviordriven behat bdd introduction tutorial

Link: https://semaphoreci.com/community/tutorials/getting-started-with-bdd-in-laravel


Trending Topics: