SpecBDD with phpspec

20
SpecBDD with phpspec Tassi Francesco

Transcript of SpecBDD with phpspec

SpecBDD with phpspec

Tassi Francesco

A php toolset to drive emergent design by specification.

http://www.phpspec.net/

It helps you with boring stuff

New classes…boOoOred

Constructor…boOoOred

New methods…boOoOred

Syntax just make sense

Obvious SUT

You’re testing just one class, no need to instantiate it. !

$this is your SUT

Natural language

The method your testing

What it should be doing -> shouldBe -> shouldEqual -> shouldBeEqualTo -> shouldBeLike -> shouldThrow

Natural language

let our SUT be constructed with …

Constructor args

Easy mocking

All you need to define a mock is add it as an argument of your spec

Easy mocking

A method with some arguments should be called during the test

Easy mocking

A method will return some value.

Easy mocking

Same instance. Of course, they have the same name and the same type after all

There’s more magic to come

TemplatesConfiguration

FormattersMatchers

!

Let’s go see the prophet

https://github.com/phpspec/prophecy

Prophecy is a highly opinionated yet very powerful and flexible PHP object mocking

framework. Though initially it was created to fulfil phpspec2 needs, it is flexible enough to be used

inside any testing framework out there with minimal effort.

Prophet

Use it !