Hands on PHPSpec

Miro Svrtan

@msvrtan

Software design/architecture

  • simple design
  • inspire confidence

Test First Development

Test Driven Development

Test Driven Development

Source: https://github.com/dwyl/learn-tdd

Check out 'Uncle Bob' doing TDD

  Robert Martin: The Transformation Priority Premise
   https://www.youtube.com/watch?v=B93QezwTQpI

Behavior Driven Development

  • specBDD vs storyBDD

PHPSpec

  • specBDD
  • modeling tool
  • tests are side effect of modelling
  • generates files/code
  • highly opinionated

Dependency injection

Value object

SOLID

  • S - Single responsibility principle
  • O - Open/closed principle
  • L - Liskov substitution principle
  • I - Interface segregation principle
  • D - Dependency inversion principle

Test doubles

  • dummy
  • stub
  • spy
  • mock
  • fake

More about ...

Konstantin Kudryashov (everzet)

Design How Your Objects Talk Through Mocking at Laracon EU 2014
https://www.youtube.com/watch?v=X6y-OyMPqfw

Example: automattic car lock

  • let's model automattic car lock
    • when car is parked
    • and engine is not running
    • ...
    • after 2 minutes
    • car should be locked
  • think about all the "and ..." needs
  • 2 mins to write all of them down
  • lets see phpspec in action

Get composer

https://getcomposer.org/download/

Create composer.json

{
    "autoload": {
        "psr-0": {
            "": "src/"
        }
    },
    "require-dev": {
        "phpspec/phpspec": "~2.0"
    },
    "config": {
        "bin-dir": "bin"
    }
}

Create composer.json

php composer.phar install

Lets code

Example: Savings

  • we are a cool banking startup
  • on each bank transaction
    • round up (7.22 to €8)

    • send difference (€0.78) to savings account

  • ​dont think about boring security stuff, we have their CTO's ear

  • model it in teams

  • present your model

Thank you all

Hands on PHPSpec - PHPDay 2017

By Miro Svrtan

Hands on PHPSpec - PHPDay 2017

Hands on PHPSpec tutorial, PHPDay 2017, May 12 2017

  • 2,094