jasonmccreary / expect
BDD-style assertions for PHP.
v1.0.1
2016-06-30 16:34 UTC
Requires
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-11-06 18:52:44 UTC
README
Expect is a BDD-style assertion library for PHP - allowing you to express expectations using a natural, fluent interface.
// equality expect(1)->toEqual('1'); expect(2)->toBe(2); // comparison expect(5)->toBeLessThan(7); expect(5)->toBeLessThanOrEqualTo(5); expect(5)->toBeGreaterThan(4); expect(5)->toBeGreaterThanOrEqualTo(5); // true / false / null expect(true)->toBeTrue(); expect('1')->toBeTruthy(); expect(false)->toBeFalse(); expect('0')->toBeFalsy(); expect(null)->toBeNull(); // strings expect('string')->toContain('in'); expect('string')->toStartWith('str'); expect('string')->toEndWith('ing'); expect('string')->toHaveLength(6); expect('string')->toMatchPattern('/string/'); expect('string')->toMatchFormat('%s'); // arrays expect(['a', 'b', 'c'])->toHaveCount(3); expect(['a', 'b', 'c'])->toContain('a'); expect(['key' => 'value'])->toHaveKey('key'); // types expect(1)->toBeType('int'); expect(new Example())->toBeInstanceOf(Example::class); expect('{"key": "value"}')->toBeJson(); expect('<key>value</key>')->toBeXml(); // files expect('file.txt')->toExist(); // negation expect(1)->not()->toEqual(2); expect(true)->not()->toBeFalse(); expect($value)->not()->toBeNull();
Installation
Install Expect as a development dependency to your project using Composer:
composer require --dev jasonmccreary/expect
Usage
Expect is used by PSpec, but can be used within other PHP testing frameworks or as a stand-alone.
Documentation
Documentation and additional examples will be available in the official release.
License
Expect is open-sourced software licensed under the MIT license.
Thanks
Expect was built atop Verify and heavily inspired by RSpec and Jasmine. I want to recognize and thank these projects.