jasonmccreary/expect

PHP的BDD风格的断言。

v1.0.1 2016-06-30 16:34 UTC

This package is auto-updated.

Last update: 2024-09-06 18:25:32 UTC


README

Build Status Latest Stable Version

Expect 是一个PHP的BDD风格断言库 - 允许您使用自然流畅的接口表达期望。

// 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();

安装

使用Composer将Expect作为开发依赖安装到您的项目中

composer require --dev jasonmccreary/expect

使用方法

Expect被PSpec使用,但也可以在其他的PHP测试框架中使用或作为独立使用。

文档

官方版本将提供文档和额外的示例。

许可证

Expect 是开源软件,使用MIT许可证

感谢

Expect 是基于 Verify 构建的,并深受 RSpecJasmine 的启发。我要感谢这些项目。