Code Monkey home page Code Monkey logo

spec-gen's Introduction

Memio's SpecGen SensioLabsInsight Travis CI

This extension for phpspec provides a powerfull code generator:

  • it typehints object, array and callable arguments
  • it names object arguments after their type
  • it names scalar arguments after a generic name (argument)
  • it adds number on names that could collide (e.g. $argument1, $argument2)

Installation

First install it using Composer:

composer require --dev memio/spec-gen:~0.1

Then enable it in phpspec.yml:

extensions:
  - Memio\SpecGen\MemioSpecGenExtension

Full example

Let's write the following specification:

<?php

namespace spec\Vendor\Project;

use PhpSpec\ObjectBehavior;
use Vendor\Project\Message\Request;

class RequestHandlerSpec extends ObjectBehavior
{
    const MASTER_REQUEST = 1;
    const CATCH_EXCEPTIONS = true;

    function it_catches_exceptions_from_master_request(Request $request)
    {
        $this->handle($request, self::MASTER_REQUEST, self::CATCH_EXCEPTIONS);
    }
}

Running the tests (phpspec run) will generate the following class:

<?php

namespace Vendor\Project;

use Vendor\Project\Message\Request;

class RequestHandler
{
    public function handle(Request $request, $argument1, $argument2)
    {
    }
}

Now we can start naming those generic arguments, and write the code.

Want to know more?

You can see the current and past versions using one of the following:

And finally some meta documentation:

Roadmap

  • Generating constructors
  • Generating method PHPdoc
  • Generating License header (based on composer.json data)

spec-gen's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.