2017 © Pedro Peláez
 

library phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

image

ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

  • Sunday, July 15, 2018
  • by ciaranmcnulty
  • Repository
  • 4 Watchers
  • 27 Stars
  • 43,292 Installations
  • PHP
  • 40 Dependents
  • 0 Suggesters
  • 8 Forks
  • 3 Open issues
  • 10 Versions
  • 9 % Grown

The README.md

Build Status, (*1)

PhpSpec Typehinted Methods Extension

Usage

PhpSpec by default will generate nonexistent methods, but will not add typehints. This extension enables that behaviour., (*2)

Write a phpspec example that uses a non-existent method:, (*3)

function it_does_foo()
{
    $this->foo(new \ArrayObject());
}

And run the spec. After accepting the prompt, the following will appear in your class under specification:, (*4)

public function foo(\ArrayObject $arrayObject)
{
    // TODO: write logic here
}

Installation

Add this extension as a composer dependency:, (*5)

composer require --dev ciaranmcnulty/phpspec-typehintedmethods

Add the following to your phpspec.yml:, (*6)

extensions:
  Cjm\PhpSpec\Extension\TypeHintedMethodsExtension: ~

Who should use this?

There are pros and cons to this extension. It's written to satisfy a particular itch that I (Ciaran) had, because I tend to write examples like this:, (*7)

function it_does_something_with_a_token(TokenInterface $token)
{
    $token->getId()->willReturn(1234);

    $this->foo($token)->shouldReturn(1234);
}

In this case, because I've written my example thinking about the types I want foo to take, it's efficient for me to get a typehinted method., (*8)

However, some people write specs much more in an 'example' frame of mind, so might write something like this:, (*9)

function it_does_something_with_a_token(ArrayToken $token)
{
    $token->getId()->willReturn(1234);

    $this->foo($token)->shouldReturn(1234);
}

In this case the author is using an ArrayToken to illustrate the example, but would prefer the typehint to be TokenInterface. For this author, the typehinting will be irritating because they will have to keep editing the typehint., (*10)

This is the reason the functionality is not in core - we do not want to encourage authors to typehint against implementations (discussion at https://github.com/phpspec/phpspec/issues/230), (*11)

Todo

Future ideas:, (*12)

  1. Analysis/generation of use statements in target file to allow shorter typehints, (*13)

  2. Meta-analysis of examples to work out which parent class(es) could be used in typehint (?), (*14)

The Versions

15/07 2018

dev-master

9999999-dev http://github.com/ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

  Sources   Download

MIT

The Requires

 

The Development Requires

bdd tdd phpspec

15/07 2018

4.0.0

4.0.0.0 http://github.com/ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

  Sources   Download

MIT

The Requires

 

The Development Requires

bdd tdd phpspec

31/07 2017

3.0.0

3.0.0.0 http://github.com/ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

  Sources   Download

MIT

The Requires

 

The Development Requires

bdd tdd phpspec

12/08 2016

2.0.0

2.0.0.0 http://github.com/ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

  Sources   Download

MIT

The Requires

 

The Development Requires

bdd tdd phpspec

19/04 2016

1.1.3

1.1.3.0 http://github.com/ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

  Sources   Download

MIT

The Requires

 

The Development Requires

bdd tdd phpspec

06/12 2015

1.1.2

1.1.2.0 http://github.com/ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

  Sources   Download

MIT

The Requires

 

The Development Requires

bdd tdd phpspec

17/10 2015

1.1.1

1.1.1.0 http://github.com/ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

  Sources   Download

MIT

The Requires

 

The Development Requires

bdd tdd phpspec

21/01 2015

1.0.1

1.0.1.0 http://github.com/ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

  Sources   Download

MIT

The Requires

 

The Development Requires

bdd tdd phpspec

21/01 2015

1.1.0

1.1.0.0 http://github.com/ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

  Sources   Download

MIT

The Requires

 

The Development Requires

bdd tdd phpspec

13/04 2014

1.0.0

1.0.0.0 http://github.com/ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

  Sources   Download

MIT

The Requires

 

bdd tdd phpspec