PHPackages                             magetest/magento-phpspec-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. magetest/magento-phpspec-extension

AbandonedLibrary[Testing &amp; Quality](/categories/testing)

magetest/magento-phpspec-extension
==================================

Magento PHPSpec extension

5.0.0(8y ago)9466.0k25[8 issues](https://github.com/MageTest/MageSpec/issues)MITPHPPHP ^7.0CI failing

Since Oct 9Pushed 8y ago15 watchersCompare

[ Source](https://github.com/MageTest/MageSpec)[ Packagist](https://packagist.org/packages/magetest/magento-phpspec-extension)[ RSS](/packages/magetest-magento-phpspec-extension/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (9)Dependencies (9)Versions (23)Used By (0)

MageSpec
--------

[](#magespec)

[![Build Status](https://camo.githubusercontent.com/bdc629e74f796e9a024be9ace47a794310323088e6bbd78ceae1a7cf00fa0262/68747470733a2f2f7472617669732d63692e6f72672f4d616765546573742f4d616765537065632e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/MageTest/MageSpec)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2211f2da64c780836930e1bdba0c7f5b856574c52d85bc8a0ff62e363cb619ff/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4d616765546573742f4d616765537065632f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/MageTest/MageSpec/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/d4287e0c96898d57882dfd1e28c94b581a073b093eb1661be6f3e26dcf2b42e5/68747470733a2f2f706f7365722e707567782e6f72672f6d616765746573742f6d6167656e746f2d706870737065632d657874656e73696f6e2f762f737461626c652e706e67)](https://packagist.org/packages/magetest/magento-phpspec-extension)[![Packagist Downloads](https://camo.githubusercontent.com/b77695e00e1bc07a84760165494de6e4ce7a4bd5fc86bcd060ed689ea3c90452/68747470733a2f2f706f7365722e707567782e6f72672f6d616765746573742f6d6167656e746f2d706870737065632d657874656e73696f6e2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/magetest/magento-phpspec-extension)[![License](https://camo.githubusercontent.com/185875b42284443c2eb144347b251dec623f33a3e926cac5b1db88eec0e68d56/68747470733a2f2f706f7365722e707567782e6f72672f6d616765746573742f6d6167656e746f2d706870737065632d657874656e73696f6e2f6c6963656e7365)](https://packagist.org/packages/magetest/magento-phpspec-extension)

Installation
------------

[](#installation)

### Install using composer

[](#install-using-composer)

First, add MageSpec to the list of dependencies inside your `composer.json` and be sure to register few paths for autoloading:

```
{
    "require-dev": {
        "magetest/magento-phpspec-extension": "^5.0"
    },
    "config": {
        "bin-dir": "bin"
    },
    "autoload": {
        "psr-0": {
            "": [
                "public/app",
                "public/app/code/local",
                "public/app/code/community",
                "public/app/code/core",
                "public/lib"
            ]
        }
    }
}
```

Then simply install it with composer:

```
$ composer install
```

You can read more about Composer on its [official webpage](http://getcomposer.org).

SpecBDD and TDD
---------------

[](#specbdd-and-tdd)

There isn’t any real difference between SpecBDD and TDD. The value of using a xSpec tool instead a regular xUnit tool for TDD is language. The concepts and features of the tool will keep your focus on the “right” things. The focus on verification and structure as opposed to behaviour and design is, of course, a valid one. We happen to find that the latter is more valuable on the long run. It was also the intention of early users of TDD.

SpecBDD and StoryBDD
--------------------

[](#specbdd-and-storybdd)

While with StoryBDD tools like [Behat](http://behat.org/) are used to understand and clarify the domain - specifying feature narratives, its need, and what do we mean by them - with SpecBDD we are only focused on the how: the implementation. You are specifying how your classes will achieve those features.

A good StoryBDD tool will let the business talk the domain language and drive the development by putting the focus on what really matters first.

Once you know why you are adding a feature and what it will be, it’s almost time to write code. But not yet! Adding code without a way to validate that it serves the specs just means you will have to go back and rework it, so that it does match the spec. And the later you find out you missed the requirement or added a bug, the harder and more expensive it is to fix. Kent Beck also adds that describing the code before you actually write it is a fear management technique. You don’t have to write all the code, just the spec of the next thing you want to work on. That executable spec will then guide you to what code you need to write. Once you do that, then what you have is a chance to refactor. Because if you change the behaviour of your code the specs will go red. So you spec so that you can refactor, or allow the design of your code to emerge in a sustainable way. SpecBDD tools are designed to guide you in the process, or at least not stand on the way.

It’s valid to assume that StoryBDD and SpecBDD used together are a very effective way to achieve highly customer-focused software.

Basic usage
-----------

[](#basic-usage)

MageSpec has been developed as PhpSpec extension which means that it depends on it and that we need to tell PhpSpec to load the extension for us. In order to do that we have to create a file in our project root called phpspec.yml and add the following content to it:

```
extensions:
    MageTest\PhpSpec\MagentoExtension\Extension: ~
```

However that's not enough. Due to the unusual and non-standard convention used by Magento to store controllers, models, helper and so on, MageSpec implement a custom PhpSpec locator service. Such a locator has to be properly configured accordingly to our project setup which means we need also to add some 'mage\_locator' configuration as following:

```
extensions:
    MageTest\PhpSpec\MagentoExtension\Extension:
        mage_locator:
            src_path: public/app/code
            spec_path: spec/public/app/code
```

Currently the mage\_locator supports five options:

- namespace (default ''): The base namespace for our source code
- spec\_prefix (default 'spec'): The namespace prefix which will be used to namespace your specs based on your source code namespace
- src\_path (default 'src'): The relative path of your source code
- spec\_path (default '.'): The relative path of your specs
- code\_pool (default 'local'): Specifies the Magento code pool for creating the extension files. Options are 'local' and 'community'

### Describing a model

[](#describing-a-model)

Say we are building a module that tells us if a product has existing reviews. We will work on simple things first and a design will emerge that will reach all the necessary features. Even though I have all the specs from the customer (we have done all our Behat feature files nicely), I know I will discover new things I will need, as soon as I sit down to write my classes.

What is the simplest thing I want to add? It should tell me if a product as a review.

So let’s do this. Well, not the boring bits. Let MageSpec take care of the boring stuff for us. We just need to tell MageSpec we will be working on the Review module's product class. So running the following command:

```
$ bin/phpspec describe:model 'magespec_reviews/product'
```

Should give us the following output

```
Specification for MageSpec_Reviews_Model_Product created in [...]/spec/public/app/code/local/MageSpec/Reviews/Model/ProductSpec.php
```

Ok. What have we just done? MageSpec has created the spec for us following the standard Magento convention. You can navigate to the spec folder and see the spec there:

```
