Home

Awesome

SandboxBundle  

Build Status Scrutinizer Code Quality Latest Stable Version SensioLabsInsight

SandboxBundle is a Symfony2 Bundle which is mostly used in conditions when you don't want to reach your real controller in a sandbox / testing environment.

For example, if you have a controller which handles some action let's say a purchase, you could use a fake response instead of creating a real purchase request. Only by using annotations and in your sandbox / testing environment the controller will be overriden with the response you choose (in JSON or XML format).

Table of contents

Installation

The following instructions outline installation using Composer. If you don't have Composer, you can download it from http://getcomposer.org/

$ composer require "danrevah/sandbox-bundle":"dev-master"    
$ php composer.phar require "danrevah/sandbox-bundle":"dev-master"    

Create a Sandbox environment

    if (in_array($this->getEnvironment(), array('sandbox'))) {
        $bundles[] = new danrevah\SandboxBundle\SandboxBundle();
    }
    sandbox:
      response:
        force: true
        # Force mode means you won't be able to "fall"
        # to the REAL controller if a Sandbox response is not available.
        # It will produce an error instead.

Single Response Annotation

used in situations when you need a constant response while on sandbox enviorment. the response will always be the same.

    /**
     * GET /resource
     *
     * @ApiSandboxResponse(
     *      responseCode=200,
     *      type="json",
     *      parameters={
     *          {"name"="some_parameter", "required"=true}
     *      },
     *      resource="@SandboxBundle/Resources/responses/token.json"
     * )
     */
    public function getAction() {
        return array('foo');
    }

Multi Response Annotation

used in situations when you need to return different responses depending on the parameters which are being sent.

    /**
     * POST /resource
     *
     * @ApiSandboxMultiResponse(
     *      responseCode=200,
     *      type="json",
     *      parameters={
     *          {"name"="some_parameter", "required"=true}
     *      },
     *      responseFallback={
     *          "type"="xml",
     *          "responseCode"=500,
     *          "resource"="@SandboxBundle/Resources/responses/error.xml"
     *      },
     *      multiResponse={
     *          {
     *              "type"="xml",
     *              "resource"="@SandboxBundle/Resources/responses/token.xml",
     *              "caseParams": {"some_parameter"="1", "some_parameter2"="2"}
     *          },
     *          {
     *              "resource"="@SandboxBundle/Resources/responses/token.json",
     *              "caseParams": {"some_parameter"="3", "some_parameter2"="4"}
     *          }
     *      }
     * )
     */
    public function postAction() {
        return array('bar');
    }