LinuxCommandLibrary

phpspec

Test-driven development with PHP

TLDR

Create a specification for a class

$ phpspec describe [class_name]
copy

Run all specifications in the "spec" directory
$ phpspec run
copy

Run a single specification
$ phpspec run [path/to/class_specification_file]
copy

Run specifications using a specific configuration file
$ phpspec run [[-c|--config]] [path/to/configuration_file]
copy

Run specifications using a specific bootstrap file
$ phpspec run [[-b|--bootstrap]] [path/to/bootstrap_file]
copy

Disable code generation prompts
$ phpspec run --no-code-generation
copy

Enable fake return values
$ phpspec run --fake
copy

SYNOPSIS

phpspec [options] command [arguments]

PARAMETERS

--config
    Specify an alternate configuration file. Defaults to phpspec.yml or phpspec.yml.dist in the project root.

--no-interaction
    Do not ask any interactive question.

--ansi
    Force ANSI output.

--no-ansi
    Disable ANSI output.

--help (-h)
    Display this help message.

--quiet (-q)
    Do not output any message.

--verbose (-v)
    Increase verbosity of messages.

--version (-V)
    Display this application version.

--colors
    Force colors output.

--no-colors
    Disable colors output.

--profile
    Display timing and memory usage information

--no-plugins
    Disable loading of plugins.

--format
    Output format.

--stop-on-failure
    Stop execution upon first failure.

--order
    Run specs in order (asc, desc, rand).

--fail-fast
    Stop execution upon first failure.

DESCRIPTION

phpspec is a command-line tool that facilitates Behavior-Driven Development (BDD) in PHP. It allows you to define the desired behavior of your classes through specifications before you write the actual implementation. This promotes a test-first approach, ensuring that your code meets the specified requirements. phpspec helps to avoid over-engineering by focusing development on only the behavior that is required to meet specifications. It can automatically generate class skeletons and test stubs based on the specification. It integrates with various mocking frameworks to provide dependency injection and test isolation. Through the use of code generation and automated feedback cycles, phpspec is a powerful tool for building robust and well-defined PHP applications. The tool encourages writing testable code, which helps build clean and maintainable software.
This tool is commonly used as part of a BDD workflow with the intent to use tests as specification for classes and methods.

COMMANDS

phpspec supports a variety of commands, including:
describe: Generates a specification for a new class.
run: Executes the specifications.
generate: Generates missing methods based on the specifications.

CONFIGURATION

phpspec is configured using a `phpspec.yml` file in the project root. This file allows you to customize various aspects of the tool, such as namespace, source path, and test path. Configuration is key to make phpspec work properly with the project structure.

SEE ALSO

phpunit(1)

Copied to clipboard