58
Specking Interactors with PHPSpec and YOLO Toward the scorners he is scornful, but to the humble he gives favor. ~ Proverbs 3:34 Friday, October 4, 13

Specking Interactors with PHPSpec and YOLO (DDD) at PHPConference Argentina 2013

Embed Size (px)

Citation preview

Specking Interactors with PHPSpec and YOLO

Toward the scorners he is scornful,    but to the humble he gives favor. ~ Proverbs 3:34

Friday, October 4, 13

Take control of your project and live a

simpler life

Toward the scorners he is scornful,    but to the humble he gives favor. ~ Proverbs 3:34

Friday, October 4, 13

Framework != Domain

Friday, October 4, 13

TestFirst

Friday, October 4, 13

DomainDomain

Friday, October 4, 13

Implementations are

DetailsFriday, October 4, 13

http://www.austinchronicle.com/binary/d294/SS.Hook._leftsideonly_.jpg

Friday, October 4, 13

http://static.guim.co.uk/sys-images/Film/Pix/pictures/2008/06/06/matrix460.jpg

Friday, October 4, 13

Signs of Inception

Friday, October 4, 13

Our FrameworkThe Best

Friday, October 4, 13

Our PracticesThe Best

Friday, October 4, 13

Our Communitynever makes

mistakes

Friday, October 4, 13

Framework isconvenient

Friday, October 4, 13

But we are notsolving

The Problem

Friday, October 4, 13

Friday, October 4, 13

Friday, October 4, 13

Friday, October 4, 13

Friday, October 4, 13

Domain

Friday, October 4, 13

DomainExpert

Friday, October 4, 13

BDD

Friday, October 4, 13

BDDTools

Behat, PhpSpec

Friday, October 4, 13

but DDD isfor Large Systems ...

Friday, October 4, 13

Friday, October 4, 13

show mehow...

Friday, October 4, 13

Friday, October 4, 13

Problem: some don’t want to pay for certification exams, so let’s build a community

site for those exams.

Friday, October 4, 13

Before we jump into the sauce:

Find a qualified examiner,could be a real educator

if not

then try to become one

Friday, October 4, 13

Spec First ↝ BDD + DDD

Feature: student can take an exam  Scenario: student takes an exam Given student starts an exam And student is presented with a question When student answers to question ... Then student ends exam and gets graded

Friday, October 4, 13

Modeling

feature DSL

BDD Scenario

Learning Process

Friday, October 4, 13

Modeling

feature DSL entity

service

repository

interactor(use case)

port

value object

BDD Scenario

Support BDD

Learning Process

Friday, October 4, 13

Modeling

feature DSL entity

service

repository

interactor(use case)

port

value object

ExamRepository

AttemptRepository

Attempt QuestionExam

Grader Converter

ShowAllExams

GradeAttempt

BDD ScenarioBDD Spec

Support BDD

Learning Process

Friday, October 4, 13

Modeling

feature DSL entity

service

repository

interactor(use case)

port

value object

ExamRepository

AttemptRepository

Attempt QuestionExam

Grader Converter

ShowAllExams

GradeAttempt

BDD ScenarioBDD Spec

Support BDD

DDD Breaking and Fixing Specs

Learning Process

Friday, October 4, 13

Modeling

feature DSL entity

service

repository

interactor(use case)

port

value object

ExamRepository

AttemptRepository

Attempt QuestionExam

Grader Converter

ShowAllExams

GradeAttempt

BDD ScenarioBDD Spec

Support BDD

DDD Refactoring Behavior DDD Breaking and Fixing Specs

Learning Process

Friday, October 4, 13

Learning Process

Friday, October 4, 13

Folder Structure

To convey:

- inversion of dependencies

- make dependencies explicit

- domain and infrastructure separation

- bounded context separation

Friday, October 4, 13

~ tree -L 6 !"" features#   !"" student_takes_exam.feature#   $"" teacher_builds_exam.feature!"" spec#   $"" Simulator#   !"" Domain#   #   !"" Model#   #   #   $"" Exam#   #   #   !"" AttemptSpec.php#   #   #   !"" ExamSpec.php#   #   #   !"" OptionSpec.php#   #   #   $"" QuestionSpec.php#   #   !"" Port#   #   #   !"" AnswerSpec.php#   #   #   !"" ExamSpec.php

Notice these are specs!

Friday, October 4, 13

~ tree -L 6 !"" features#   !"" student_takes_exam.feature#   $"" teacher_builds_exam.feature!"" spec#   $"" Simulator#   !"" Domain#   #   !"" Model#   #   #   $"" Exam#   #   #   !"" AttemptSpec.php#   #   #   !"" ExamSpec.php#   #   #   !"" OptionSpec.php#   #   #   $"" QuestionSpec.php#   #   !"" Port#   #   #   !"" AnswerSpec.php#   #   #   !"" ExamSpec.php

Friday, October 4, 13

~ tree -L 6 !"" features#   !"" student_takes_exam.feature#   $"" teacher_builds_exam.feature!"" spec#   $"" Simulator#   !"" Domain#   #   !"" Model#   #   #   $"" Exam#   #   #   !"" AttemptSpec.php#   #   #   !"" ExamSpec.php#   #   #   !"" OptionSpec.php#   #   #   $"" QuestionSpec.php#   #   !"" Port#   #   #   !"" AnswerSpec.php#   #   #   !"" ExamSpec.php

Friday, October 4, 13

~ tree -L 6 ...#   #   !"" Port#   #   #   !"" AnswerSpec.php#   #   #   !"" ExamSpec.php#   #   #   $"" ExamsSpec.php#   #   !"" Services#   #   #   !"" ExamsConverterSpec.php#   #   #   !"" GraderSpec.php#   #   #   $"" PrototypeManagerSpec.php#   #   !"" Support#   #   #   $"" StudentHelperSpec.php#   #   $"" UseCase#   #   !"" GradesAttemptSpec.php

Friday, October 4, 13

~ tree -L 6 ...#   #   !"" Port#   #   #   !"" AnswerSpec.php#   #   #   !"" ExamSpec.php#   #   #   $"" ExamsSpec.php#   #   !"" Services#   #   #   !"" ExamsConverterSpec.php#   #   #   !"" GraderSpec.php#   #   #   $"" PrototypeManagerSpec.php#   #   !"" Support#   #   #   $"" StudentHelperSpec.php#   #   $"" UseCase#   #   !"" GradesAttemptSpec.php

Friday, October 4, 13

~ tree -L 6 ...#   #   !"" Port#   #   #   !"" AnswerSpec.php#   #   #   !"" ExamSpec.php#   #   #   $"" ExamsSpec.php#   #   !"" Services#   #   #   !"" ExamsConverterSpec.php#   #   #   !"" GraderSpec.php#   #   #   $"" PrototypeManagerSpec.php#   #   !"" Support#   #   #   $"" StudentHelperSpec.php#   #   $"" UseCase#   #   !"" GradesAttemptSpec.php

Friday, October 4, 13

~ tree -L 6 ...#   $"" Infrastructure#   !"" Cilex#   #   !"" Command#   #   #   $"" ShowAllExamsCommand.php#   #   !"" Console#   #   #   $"" Runner.php#   #   !"" Provider#   #   #   $"" SimulatorServiceProvider.php#   #   $"" config.yml

Friday, October 4, 13

~ tree -L 6 ...#   $"" Infrastructure| ...#   !"" Persistence#   #   !"" Doctrine#   #   #   $"" OrmExamRepository.php#   #   !"" InMemoryAttemptRepository.php#   #   !"" InMemoryExamRepository.php#   #   $"" PDO#   #   $"" PdoExamRepository.php#   !"" Symfony#   #   $"" Bundle#   #   $"" SimulatorBundle#   $"" Yolo#   $"" Controller#   $"" ExamController.php

Friday, October 4, 13

~ tree -L 6 ...#   $"" Infrastructure| ...#   !"" Persistence#   #   !"" Doctrine#   #   #   $"" OrmExamRepository.php#   #   !"" InMemoryAttemptRepository.php#   #   !"" InMemoryExamRepository.php#   #   $"" PDO#   #   $"" PdoExamRepository.php#   !"" Symfony#   #   $"" Bundle#   #   $"" SimulatorBundle#   $"" Yolo#   $"" Controller#   $"" ExamController.php

Friday, October 4, 13

~ tree -L 6 ...#   $"" Infrastructure| ...#   !"" Persistence#   #   !"" Doctrine#   #   #   $"" OrmExamRepository.php#   #   !"" InMemoryAttemptRepository.php#   #   !"" InMemoryExamRepository.php#   #   $"" PDO#   #   $"" PdoExamRepository.php#   !"" Symfony#   #   $"" Bundle#   #   $"" SimulatorBundle#   $"" Yolo#   $"" Controller#   $"" ExamController.php

Friday, October 4, 13

What if I ask you which classes implement the features?

Friday, October 4, 13

Folder Structure~ tree -L 6

...#   #   !"" Port#   #   #   !"" AnswerSpec.php#   #   #   !"" ExamSpec.php#   #   #   $"" ExamsSpec.php#   #   !"" Services#   #   #   !"" ExamsConverterSpec.php#   #   #   !"" GraderSpec.php#   #   #   $"" PrototypeManagerSpec.php#   #   !"" Support#   #   #   $"" StudentHelperSpec.php#   #   $"" UseCase#   #   !"" GradesAttemptSpec.php

This bring us back to interactors/use cases

Friday, October 4, 13

Friday, October 4, 13

Friday, October 4, 13

Domain ↝ Domain- intention- expressive- explicit

Friday, October 4, 13

Domain ↝ Domain

Friday, October 4, 13

Domain ↝ Domain

Friday, October 4, 13

Show whatyou did :)

Friday, October 4, 13

"repositories": [ { "type": "vcs", "url": "[email protected]:cordoval/ExamSimulator" } ], "require": { "igorw/yolo": "dev-master", "cordoval/exam-simulator": "dev-master" },

Friday, October 4, 13

~ php bin/console exams:show - yolo - part I- yolo - part IIAll exams displayed

Friday, October 4, 13