CheckOps home

Tools directory

P

CheckOps

phpspec

phpspec is an MIT-licensed specification-oriented BDD toolset for PHP that helps you design classes by writing specs first, with code generation for missing classes and methods.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

Introduction

phpspec is a tool for specification BDD in PHP. Rather than testing existing code, it encourages you to describe the behaviour of a class before it exists, then helps you write the implementation. It focuses on the design of individual objects and their collaborators, complementing story-level BDD tools such as Behat.

You start with phpspec describe App/Pricing, which creates a spec class. Examples are methods such as it_applies_a_discount(), where $this refers to the object being specified and matchers read naturally: $this->apply(100, 10)->shouldReturn(90). When a class or method does not exist, phpspec offers to generate it for you. Collaborators are injected as test doubles automatically (using Prophecy), encouraging small, well-designed objects. The phpspec run command executes specs with readable output. Version 9 was in release-candidate stage (9.0.0-rc.7 on 8 November 2026).

The source code is at phpspec/phpspec on GitHub under the MIT licence, with about 1,900 stars; the most recent commit was on 8 November 2026.

Features

  1. Spec-first design: Describe behaviour before implementation.
  2. Code generation: Creates missing classes and methods.
  3. Readable matchers: shouldReturn, shouldThrow and more.
  4. Automatic collaborators: Test doubles injected into examples.

Pros

  1. Free to use: Open source under the MIT licence, so the core tool costs nothing to use.
  2. Actively maintained: The repository had commits as recent as 8 November 2026.

Cons

  1. Opinionated: Deliberately limited for testing legacy or framework-heavy code.
  2. Smaller community: Less popular than PHPUnit or Pest.
composer require --dev phpspec/phpspec
vendor/bin/phpspec describe App/Pricing
namespace spec\App;

use App\Pricing;
use PhpSpec\ObjectBehavior;

class PricingSpec extends ObjectBehavior
{
    function it_is_initializable() { $this->shouldHaveType(Pricing::class); }

    function it_applies_a_discount() { $this->apply(100, 10)->shouldReturn(90); }
}
vendor/bin/phpspec run

Resources:

Pricing

phpspec is free and open source under the MIT licence.

  1. PHP developers practising TDD/BDD at the class-design level.
  2. Teams building domain models with clean collaborators.

Conclusion

phpspec is a focused design tool for PHP developers who want specs to drive clean object-oriented code.

Alternatives

Other tools on CheckOps that cover similar ground. Open a page, or compare one with phpspec side by side.