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.
Latest public signals
Last updated: 23 November 2026 (weekly freshness scan: version refreshed).
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.10 on 17 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
- Spec-first design: Describe behaviour before implementation.
- Code generation: Creates missing classes and methods.
- Readable matchers:
shouldReturn,shouldThrowand more. - Automatic collaborators: Test doubles injected into examples.
Pros
- Free to use: Open source under the MIT licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 8 November 2026.
Cons
- Opinionated: Deliberately limited for testing legacy or framework-heavy code.
- Smaller community: Less popular than PHPUnit or Pest.
Usage and Links (Example)
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.
Recommended for?
- PHP developers practising TDD/BDD at the class-design level.
- 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.
PPHPUnitPHPUnit is the BSD-3-Clause, programmer-oriented testing framework for PHP and an instance of the xUnit architecture, created by Sebastian Bergmann and distributed as a PHAR or via Composer.Compare with phpspec
PPestPest is an MIT-licensed PHP testing framework built on PHPUnit with an expressive, closure-based API; Pest 5 (PHP 8.4+, PHPUnit 13) adds the Tia engine, an agent plugin, evals, PHPStan and Rector support.Compare with phpspec
BBehatBehat is an MIT-licensed behaviour-driven development framework for PHP that runs Gherkin feature files against PHP context classes, often paired with Mink for browser testing.Compare with phpspec
MMockeryMockery is a BSD-3-Clause mock object framework for PHP with a fluent, readable expectation API, usable with PHPUnit, Pest and other frameworks, and bundled with Laravel's testing tools.Compare with phpspec
IInfectionInfection is a BSD-3-Clause AST-based mutation testing framework for PHP that measures test effectiveness with Mutation Score Indicator metrics, supporting PHPUnit, Pest, Codeception and phpspec.Compare with phpspec
CCodeceptionCodeception is an MIT-licensed full-stack PHP testing framework covering unit, functional, API and acceptance tests in one tool, with modules for WebDriver, REST, databases and frameworks such as Laravel and Symfony.Compare with phpspec