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
Get composer
wget https://getcomposer.org/download/1.6.3/composer.phar
curl https://getcomposer.org/download/1.6.3/composer.phar > composer.phar
or
Initialize composer
php composer.phar init
Add autoload paths
{
...
"autoload": {
"psr-0": {
"": "src/"
}
},
"autoload-dev": {
"psr-4": {
"spec\\": "spec/"
}
}
...
}
Add phpspec
php composer.phar req --dev phpspec/phpspec
Run phpspec
./vendor/bin/phpspec run
Describe phpspec
./vendor/bin/phpspec desc 'MyCompany\Calculator'
./vendor/bin/phpspec run
Lets code
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
Example: Savings
- we are a cool banking startup
- for each transaction on customer checking account
-
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 - Zagreb 2018-02-10
By Miro Svrtan
Hands on PHPSpec - Zagreb 2018-02-10
Hands on PHPSpec workshop, Zagreb 2018-02-10
- 1,201