Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
It's all about behaviour, also in php - phpspec
1. IT’S ALL ABOUT BEHAVIOUR
-ALSO IN PHP@liuggio
PUG-ROMA 26-02-2013
2. WHY WE DO TESTS?
> refactor
> automation
> verification
> ??
3. WHO LOVES TDD?
"Test-Driven Development is a developer practice
that involves writing tests before writing the code
being tested."
<<TDD is a design tool
used to deliver high-quality code >>
REFACTOR IS TIME CONSUMING
5. TDD: THE INFINTE CYCLE
"Run it, watch it fail, write just enough
code to get it to pass, review the design,
and remove duplication" > "Run it, watch it
fail, write just enough code to get it to pass,
review the design, and remove duplication" >
"Run it, watch it fail, write just enough code to get it to pass,
review the design, and remove duplication" > "Run it, watch it fail,
write just enough code to get it to pass, review the design, and remove
duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and
remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove
duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just
enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough code to get it to pass, review the design, and remove duplication" > "Run it, watch it fail, write just enough
code to get it to pass, review the design, and remove duplication"
TECHNOLOGIC
6. TDD: mmm
If you have a blank project, you have to start...
Where to start?
What to test?
What not to test?
How much tests?
Where to start?
7. TDD: mmmmmmmmm
“If you need to test the insertion of an object into a
collection and the collection is represented by an
Array, with xUnit you should assert that the
collection contains the object in the Array, but if the
collection will change to another type of container,
graph for example, the xUnit will fail, even if the
behaviour is unchanged. “
8. BDD :)
in BDD you are not testing
you are describing what that classes will do,
so you can continue creating the class
Specify the Behaviour by Examples
not testing a class.
9. BDD :D
External behaviour - Story
Behat deals to have specifications that reflects
the environment from the outside.
Solve: Where to start, What to and not to test
Internal behaviour - Example
PHPSpec responds to the behaviour in the lower
level, from the internal of the classes.
Solve all the TDD mmmmmmm
10. BDD the double cycle
1 start from Scenario
2 write a story that fail
go to phpspec2 internal level
3 write a fail Example
4 get it green
5 refactor
go to behat external level
7 refactor
11. "Spec BDD with phpspec
phpspec is a development tool, designed to help you achieve
clean and working PHP code by using a technique derived
from test-first development called (spec) behaviour driven
developement, or SpecBDD."
12. LET’S CODE
1. Installation composer
{
"require-dev": {
"phpspec/phpspec2": "*"
},
"config": {
"bin-dir": "bin"
},
"autoload": {"psr-0": {"": "src"}},
"minimum-stability": "dev"
}
2.
Code the behaviour: WAIT
we have to talk the same language
13. DEFINITION
In BDD you are going to 'Describe' the behaviour of a Class
creating a `Spec` that will contain more Examples.
'example' is the class to write, before write the subject code.
'expectation' the behaviour that the subject code should
have.
• Assertion becomes expectation.
• Test method becomes code example
• Test case becomes example group/Specification
14. CODING TIME
Not really coding, command lining :)
$ bin/phpspec desc FakeTwitter
Specification for FakeTwitter created in spec/FakeTwitter.php.
Now Code the examples ...
$ bin/phpspec run -v -f prettify