Designing with phpspec

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
{
}

Tip

The path to phpspec should be added to either the .bashrc or the .bash_profile file so that phpspec can be run directly.

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
{}

Tip

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.

Designing with phpspec

The basic steps involved in describing and creating a class with phpspec

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset