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

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

ciaranmcnulty/phpspec-typehintedmethods
=======================================

Extension for phpspec to enhance generated methods

4.0.0(7y ago)3089.3k12[3 PRs](https://github.com/ciaranmcnulty/phpspec-typehintedmethods/pulls)20MITPHPPHP ^7.1

Since Apr 13Pushed 6y ago2 watchersCompare

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

READMEChangelog (9)Dependencies (4)Versions (10)Used By (20)

[![Build Status](https://camo.githubusercontent.com/3d427dad5eadf91551dec719cde9a389a591264cb557be0e2eb68b93e770415f/68747470733a2f2f7472617669732d63692e6f72672f63696172616e6d636e756c74792f706870737065632d7479706568696e7465646d6574686f64732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ciaranmcnulty/phpspec-typehintedmethods)

\#PhpSpec Typehinted Methods Extension

\##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

Add this extension as a composer dependency:

```
composer require --dev ciaranmcnulty/phpspec-typehintedmethods
```

Add the following to your phpspec.yml:

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

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

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

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 63.2% 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

2856d 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/e7c4612e19ba73b517d8c3e15890af6687f8a206eb56676c1714209534378429?d=identicon)[ciaranmcnulty](/maintainers/ciaranmcnulty)

---

Top Contributors

[![ciaranmcnulty](https://avatars.githubusercontent.com/u/237866?v=4)](https://github.com/ciaranmcnulty "ciaranmcnulty (24 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)")[![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/ciaranmcnulty-phpspec-typehintedmethods/health.svg)

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

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.5k](/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.0k](/packages/orchestra-testbench)[orchestra/testbench-core

Testing Helper for Laravel Development

27043.7M308](/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)
