← 返回命令列表

Linux command

phpspec 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Run all specifications

phpspec run

Generate a new specification

phpspec describe "[App\\Calculator]"

Run a single spec file

phpspec run [spec/App/CalculatorSpec.php]

Use a specific output formatter

phpspec run --format [pretty]

Run without prompting

phpspec run --no-interaction

Stop on the first failure

phpspec run --stop-on-failure

Show full backtraces

phpspec run -vvv

说明

phpspec is a SpecBDD (Specification Behaviour-Driven Development) tool for PHP. Rather than verifying existing implementations like a traditional unit test runner, it drives the design of objects: you write a spec describing how a class should behave, run phpspec, and it offers to scaffold the missing class, methods, and return statements for you. Specs are plain PHP classes that extend PhpSpec\\ObjectBehavior. Each `it_*` / `its_*` method is a single example. Collaborators are described as type-hinted parameters and phpspec automatically supplies prophecy-based test doubles for them. Configuration lives in `phpspec.yml` (or `phpspec.yml.dist`) at the project root and controls suites, bootstrap files, formatters, and matchers/extensions. PhpSpec is intentionally narrower than PHPUnit — it focuses on isolated, design-first object specs and pairs naturally with a higher-level acceptance tool such as Behat.

参数

-c, --config _FILE_
Use a specific configuration file (default: phpspec.yml or phpspec.yml.dist).
-f, --format _NAME_
Output formatter: progress (default), pretty, junit, dot, tap, html.
--stop-on-failure
Halt the run as soon as a spec fails.
--fake
Make generated dummy methods return realistic fake data.
-n, --no-interaction
Do not ask any interactive questions; assume defaults.
-v / -vv / -vvv
Increase verbosity. -vvv prints exception traces.
--ansi / --no-ansi
Force or disable ANSI color output.
-q, --quiet
Suppress all output.
-V, --version
Display the phpspec version.

FAQ

What is the phpspec command used for?

phpspec is a SpecBDD (Specification Behaviour-Driven Development) tool for PHP. Rather than verifying existing implementations like a traditional unit test runner, it drives the design of objects: you write a spec describing how a class should behave, run phpspec, and it offers to scaffold the missing class, methods, and return statements for you. Specs are plain PHP classes that extend PhpSpec\\ObjectBehavior. Each `it_*` / `its_*` method is a single example. Collaborators are described as type-hinted parameters and phpspec automatically supplies prophecy-based test doubles for them. Configuration lives in `phpspec.yml` (or `phpspec.yml.dist`) at the project root and controls suites, bootstrap files, formatters, and matchers/extensions. PhpSpec is intentionally narrower than PHPUnit — it focuses on isolated, design-first object specs and pairs naturally with a higher-level acceptance tool such as Behat.

How do I run a basic phpspec example?

Run `phpspec run` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c, --config _FILE_ do in phpspec?

Use a specific configuration file (default: phpspec.yml or phpspec.yml.dist).