Now, let's begin using phpspec as a design tool to build our entities.
If the top-level namespace is MyCompany
, then use phpspec and simply type the following command:
# phpspec describe MyCompany/AccommodationRepository
On typing the preceding command, spec/AccommodationSpecRepository.php
gets created:
<?php namespace specMyCompany; use PhpSpecObjectBehavior; use ProphecyArgument; class AccommodationRepositorySpec extends ObjectBehavior { function it_is_initializable() { $this->shouldHaveType('MyCompanyAccommodationRepository'), } <?php namespace MyCompany; class AccommodationRepository { }
Then, type the following command:
# phpspec run
On typing the preceding command, the developer is shown, as follows:
class MyCompanyAcccommodationRepository does not exist. Do you want me to create 'MyCompanyAccommodationRepository' for you? [Y/n]
After typing Y, the AccommodationRepository.php
class is created, as follows:
<?php namespace MyCompany; class AccommodationRepository {}
Downloading the example code
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
The beauty of phpspec lies in its simplicity and the ability to speed up the creation of classes which carry along with the specification.