PHPackages                             friends-of-phpspec/phpspec-typehintedmethods - 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. friends-of-phpspec/phpspec-typehintedmethods

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

friends-of-phpspec/phpspec-typehintedmethods
============================================

Extension for phpspec to enhance generated methods

4.0.0(7y ago)042MITPHPPHP ^7.1

Since Apr 13Pushed 7mo agoCompare

[ Source](https://github.com/friends-of-phpspec/phpspec-typehintedmethods)[ Packagist](https://packagist.org/packages/friends-of-phpspec/phpspec-typehintedmethods)[ Docs](http://github.com/ciaranmcnulty/phpspec-typehintedmethods)[ RSS](/packages/friends-of-phpspec-phpspec-typehintedmethods/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (11)Used By (0)

PhpSpec Typehinted Methods Extension
====================================

[](#phpspec-typehinted-methods-extension)

Usage
-----

[](#usage)

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

Write a phpspec example that uses a non-existent method:

```
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:

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

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

[](#installation)

Add this extension as a composer dependency:

```
composer require --dev friends-of-phpspec/phpspec-typehintedmethods
```

Add the following to your phpspec.yml:

```
extensions:
  Cjm\PhpSpec\Extension\TypeHintedMethodsExtension: ~
```

Who should use this?
--------------------

[](#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:

```
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.

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

```
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.

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

Todo
----

[](#todo)

Future ideas:

1. Analysis/generation of `use` statements in target file to allow shorter typehints
2. Meta-analysis of examples to work out which parent class(es) could be used in typehint (?)

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance44

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~194 days

Recently: every ~237 days

Total

9

Last Release

2859d ago

Major Versions

1.1.3 → 2.0.02016-08-12

2.0.0 → 3.0.02017-07-31

3.0.0 → 4.0.02018-07-15

PHP version history (2 changes)3.0.0PHP ^7.0

4.0.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ab317af777924eeefe097aa3e0a423f069eaac20280e3241631e1a950e17f47?d=identicon)[shulard](/maintainers/shulard)

![](https://www.gravatar.com/avatar/5d7eebb96db1721780c3e38450c4408c15b3fde74daaefdd1412508224d4b7b5?d=identicon)[jaylinski](/maintainers/jaylinski)

---

Top Contributors

[![ciaranmcnulty](https://avatars.githubusercontent.com/u/237866?v=4)](https://github.com/ciaranmcnulty "ciaranmcnulty (24 commits)")[![torchello](https://avatars.githubusercontent.com/u/897885?v=4)](https://github.com/torchello "torchello (9 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (7 commits)")[![Sam-Burns](https://avatars.githubusercontent.com/u/6594039?v=4)](https://github.com/Sam-Burns "Sam-Burns (6 commits)")[![jaylinski](https://avatars.githubusercontent.com/u/1668766?v=4)](https://github.com/jaylinski "jaylinski (1 commits)")[![swekaj](https://avatars.githubusercontent.com/u/3137856?v=4)](https://github.com/swekaj "swekaj (1 commits)")

---

Tags

BDDTDDphpspec

###  Code Quality

TestsBehat

### Embed Badge

![Health badge](/badges/friends-of-phpspec-phpspec-typehintedmethods/health.svg)

```
[![Health](https://phpackages.com/badges/friends-of-phpspec-phpspec-typehintedmethods/health.svg)](https://phpackages.com/packages/friends-of-phpspec-phpspec-typehintedmethods)
```

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[codeception/codeception

All-in-one PHP Testing Framework

4.9k86.2M2.9k](/packages/codeception-codeception)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[orchestra/testbench-core

Testing Helper for Laravel Development

27043.7M310](/packages/orchestra-testbench-core)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

36918.1M98](/packages/php-mock-php-mock)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
