22. Feature: Organizers can open a call for paper
As an event organizer
I want a way to publish a centralized cfp form
So that it’s easier for speakers to submit
Scenario: Creation form with valid attributes
Given I am in on "call-for-papers/add"
When I fill in the following:
| event | PHPLondon Conference|
| start_date | 2012-02-06 |
| limit_abstract_wc | 500 |
| why_you_field | 1 |
| offer_hotel | 1 |
| offer_travel | 0 |
And I press "Create"
Then I should see "The cfp was created successfully"
Saturday, 29 October 2011
40. All together
class DescribeStringCalculator extends PHPSpecContext
{
function itReturnsZeroWithNoArguments()
{
$calculator = $this->spec(new StringCalculator);
$result = $calculator->add();
$result->should->be(0);
}
}
Saturday, 29 October 2011
41. Hooks
before()
after()
beforeAll()
afterAll()
Saturday, 29 October 2011
42. Setting initial state with before hook
class DescribeStringCalculator extends PHPSpecContext
{
function before()
{
$this->calculator = $this->spec(new StringCalculator);
}
function itReturnsZeroWithNoArguments()
{
$result = $this->calculator->add();
$result->should->be(0);
}
}
Saturday, 29 October 2011
43. class DescribeStringCalculator extends PHPSpecContext
{
private $calculator;
function before()
{
$this->calculator = $this->spec(new StringCalculator);
}
function itReturnsZeroWithNoArguments()
{
$this->calculator->add()->should->equal(0);
}
function itReturnsTheBareNumber()
{
$this->calculator->add('42')->should->equal(42);
}
}
Saturday, 29 October 2011
44. Formatters
progress
documentation
html
coming soon:
junit
Saturday, 29 October 2011
45. Progress Formatter
$ phpspec StringCalculatorSpec.php -c
.*.F
Pending:
String Calculator returns the bare number
# Waiting to clarify the spec
# ./spec/StringCalculatorSpec.php:19
Failures:
1) String Calculator returns the sum of space separate string
expected 42, got 0 (using be())
# .spec/StringCalculatorSpec.php:28
2) StringCalculator returns the sum of any white space separated string
Failure/Error:
Just because
Finished in 0.056134 seconds
4 examples, 1 failure, 1 pending
Saturday, 29 October 2011
61. create a project
$ zf create project callconf
Creating project at /var/www/callconf
Note: This command created a web project, for more
information setting up your VHOST, please see docs/README
Saturday, 29 October 2011
63. initialize Behat
$ zf generate behat
+d features - place your *.feature files here
+d features/bootstrap - place bootstrap scripts and static
files here
+f features/bootstrap/FeatureContext.php - place your feature
related code here
Saturday, 29 October 2011
69. create a view spec
$ zf create view-spec add CallForPapers
Saturday, 29 October 2011
70. create a view spec
$ zf create view-spec add CallForPapers
Creating a view script in location /var/www/callconf/
application/views/scripts/call-for-papers/add.phtml
Creating a spec at /var/www/callconf/spec/views/call-for-
papers/AddSpec.php
Saturday, 29 October 2011
72. Spec created by default
<?php
namespace CallForPapers;
require_once __DIR__ . '/../../SpecHelper.php';
use PHPSpecContextZendView as ViewContext;
class DescribeAdd extends ViewContext
{
function itRendersTheDefaultContent()
{
$this->render();
$this->rendered->should->contain('CallForPapers');
$this->rendered->should->contain('add');
}
}
Saturday, 29 October 2011
73. what behaviors can we
describe in the view spec?
Saturday, 29 October 2011
74. Variables we need assigned
What content was rendered
(We can use selectors)
Saturday, 29 October 2011
78. create a controller spec
$ zf create controller-spec CallForPapers add,create
Saturday, 29 October 2011
79. create a controller spec
$ zf create controller-spec CallForPapers add,create
Creating a controller at /private/var/www/callconf/
application/controllers/CallForPapersController.php
Creating an add action method in controller CallForPapers
Creating an create action method in controller CallForPapers
Creating a spec at /private/var/www/callconf/spec/
controllers/CallForPapersSpec.php
Saturday, 29 October 2011
87. create a model spec
$ zf create model-spec Speaker name:string,email:string
Saturday, 29 October 2011
88. create a model spec
$ zf create model-spec Speaker name:string,email:string
Creating a model at /private/var/www/callconf/application/
models/Speaker.php
Creating a db table at /private/var/www/callconf/
application/models/DbTable/Speakers.php
Creating a mapper at /private/var/www/callconf/application/
models/SpeakerMapper.php
Creating a spec at /private/var/www/callconf/spec/models/
SpeakerSpec.php
Creating migration scripts at /private/var/www/callconf/db/
migrate/001-CreateSpeakersTable.php
Updating project profile '/private/var/www/
callconf/.zfproject.xml'
Saturday, 29 October 2011
90. Spec created by default
<?php
require_once __DIR__ . '/../SpecHelper.php';
use Application_Model_Speaker as Speaker;
class DescribeSpeaker extends PHPSpecContext
{
function before()
{
$this->validAttributes = array(
'name' => 'value for name',
'email' => 'value for email',
);
}
function itShouldCreateANewInstanceGivenValidAttributes()
{
$this->speaker = $this->spec(Speaker::create($this->validAttributes));
$this->speaker->should->beValid();
}
}
Saturday, 29 October 2011
91. what behaviors can we
describe in the model spec?
Saturday, 29 October 2011
92. Business logic
Validation
Spying results from data source operations
Saturday, 29 October 2011
93. Business Logic
class DescribeSpeaker extends PHPSpecContext
{
function before()
{
$this->validAttributes = array(
'name' => 'Marcello Duarte',
'email' => 'marcello@ibuildings.com',
'diet_restriction' => 'vegetarian',
);
$this->speaker = $this->spec(Speaker::create($this->validAttributes));
}
function itGetsExtraRatingPointsForTalkIfVegetarian()
{
$this->speaker->should->haveExtraPoints();
}
}
Saturday, 29 October 2011
94. Business Logic
class Speaker
{
//... other methods
function hasExtraPoints()
{
return stripos($this->getDietRestrictions(), 'vegetarian') !== false;
}
}
Saturday, 29 October 2011
98. Dependencies can be hard to manage
class DescribeEvent extends PHPSpecContext
{
function itDoesSomethingWhenYouHaveSpeakerAllocated()
{
$event = new Event(
new Organizer('John Smith',
new Organization('Ibuildings')
)
);
$event->addSpeaker(new Speaker('Rowan'), new Slot(’10:30’),
new Room('A'));
$event->addSpeaker(new Speaker('Ben'), new Slot(’10:30’),
new Room('B'));
// specify expected behavior
}
}
Saturday, 29 October 2011
99. Usually dependencies are replaced with
doubles when writing specs
We can use a framework like Mockery
But if you really need the real thing
Saturday, 29 October 2011
101. Dependencies can be hard to manage
class DescribeEvent extends PHPSpecContext
{
function itDoesSomethingWhenYouHaveSpeakerAllocated()
{
$exampleEvent = ExampleEvent::newWithSimultaneousSpeakers();
// specify expected event behavior
}
}
Saturday, 29 October 2011
104. Is created with save “empty” objects
Has a fluent interface
Has a build method
Saturday, 29 October 2011
105. Dependencies can be hard to manage
class DescribeEvent extends PHPSpecContext
{
function itDoesSomethingWhenYouHaveSpeakerAllocated()
{
$eventBuilder = new EventBuilder();
$organizerBuilder = new OrganizerBuilder();
$event = $eventBuilder->withOrganizer(
$organizerBuilder->withOrganization()->build()
)->withConflictingSpeakers()
->build();
// specify expected event behavior
}
}
Saturday, 29 October 2011
113. Create objects
// in one of my specs
$ben = Phactory::create('speaker', array('name' => 'Rowan'));
$rowan = Phactory::create('speaker', array('name' => 'Ben'));
// Phactory_Row objects
echo $ben->name // prints Ben
Saturday, 29 October 2011