friends-of-phpspec/phpspec-expect
Adds an expect() helper for PhpSpec, enabling expressive assertions like expect($value)->toBe(true) in your specs. Lightweight, dev-only dependency with compatibility across multiple PhpSpec and PHP versions.
The phpspec-expect package is a testing utility designed to enhance behavior-driven development (BDD) workflows in PHP applications, particularly those using phpspec. While Laravel itself does not mandate its use, it integrates seamlessly with Laravel’s testing ecosystem (e.g., Pest, PHPUnit) as a complementary tool for domain-layer or service-layer testing. The package’s focus on expectation assertions (e.g., mocking, lazy objects) aligns well with Laravel’s modular architecture, where BDD can be applied to non-HTTP logic (e.g., repositories, services). However, its utility is limited to projects actively using phpspec, making it a niche but valuable addition for teams invested in BDD.
expect($obj)->toBe(true)) is intuitive and reduces boilerplate in test suites.rector for automated upgrades or audit composer.json for PHP version constraints.expect() syntax could shadow built-in functions (e.g., Pest’s expect()). Mitigation: Use fully qualified namespaces (e.g., \FriendsOfPhpSpec\PhpSpec\Expect::expect()).--strict-types and address warnings proactively.phpspec 8 supports the same parallelization flags as v7.expect() helper reduce onboarding time, or will it require additional training?should->throw())? What is the effort to refactor them?phpspec-expect v4.0.x (if PHP 8.0 compatibility is critical).phpspec-expect v3.x (PHP 7.1+).phpspec.yml to use the new configuration format.expect() instead of should->).expect() calls.composer.json for PHP version constraints and Laravel dependencies.composer why-not php:8.1 to identify blocking dependencies.composer.json:
"require": {
"php": "^8.1"
}
composer update --with-all-dependencies and resolve conflicts.php -v && ./vendor/bin/phpunit --testdox-html
phpspec/phpspec to ^8.0 and friends-of-phpspec/phpspec-expect to ^4.1:
composer require phpspec/phpspec:^8.0 friends-of-phpspec/phpspec-expect:^4.1 --dev
phpspec.yml to include the new expectation helper:
extensions:
- FriendsOfPhpSpec\PhpSpec\Expect\ExpectationExtension
./vendor/bin/phpspec run --format=pretty
should-> to the new expect()->toBe() style.services:
php: '8.1'
TestCase, RefreshDatabase, and MigrateFresh traits.expect() function:
use function FriendsOfPhpSpec\PhpSpec\Expect\expect as phpspecExpect;
phpspec-expect v4.0.x in custom packages (e.g., internal test utilities).laravel/browsershot) that may use phpspec under the hood.phpspec-expect’s new syntax.expect() helper.How can I help you explore Laravel packages today?