bossa/phpspec2-expect
Adds an expect() helper to PhpSpec for simple, expressive assertions like expect($value)->toBe(true). Install via Composer as a dev dependency and use in specs for quick expectation-style checks.
Install as a dev dependency: composer require --dev bossa/phpspec2-expect. Once installed, use expect() anywhere in your PhpSpec specs (e.g., in spec/ or standalone scripts run with phpspec run) to assert on any value—scalars, arrays, objects—without wrapping it in a mock or stub. For example:
expect(strlen('hello'))->toBe(5);
expect(['a', 'b'])->toContain('a');
This is the fastest way to bring RSpec-style ergonomics to PhpSpec—ideal for quick property checks, utility function specs, or validating procedural code.
expect($scalar) directly instead of creating a dummy object just to assert on it—no need for given($value)->willReturn(...) boilerplate.expect(json_encode($data))->toContain('"key"') to test helper utilities or legacy code.expect() lets you validate cross-cutting behaviors (e.g., logging, routing behavior) without full object instantiation.expect() for simple external condition checks (e.g., filesystem, config), and keep object-oriented matchers (shouldHaveType(), shouldBeCalled()) for method-level contract verification.expect() is auto-loaded by placing require_once __DIR__.'/../vendor/autoload.php'; in bootstrap.php or relying on Composer’s autoloader (the package registers the helper via its phpspec.yml extension).phpspec/expectation).expect(file_exists('x')) evaluates immediately, defeating lazy testing semantics. Wrap in closures to defer: expect(fn() => file_exists('x'))->toBeTrue();expect() is a runtime helper (not a method on a class), IDE auto-completion for matchers may lag—install phpspec/phpspec in your IDE’s PHPStan/PHPStan-Extension setup.expect_spec.php—the helper function is global and may conflict with class/method names.expect() entry point. Custom matchers must be built using standard Phpspec Matcher classes—not via this package’s internals. Use it as a bridge, not a DSL extension layer.How can I help you explore Laravel packages today?