peridot-php/leo-http-foundation

Leo 断言用于测试 HttpFoundation 应用程序

1.1.0 2015-02-10 18:03 UTC

This package is not auto-updated.

Last update: 2024-09-10 03:36:57 UTC


README

#Leo Http Foundation

Leo 断言,用于与 HttpFoundation 结合使用

Build Status Scrutinizer Code Quality

这组断言会根据需要不断发展。请随时提交拉取请求和提出功能请求。

##用法

您可以通过扩展 Leo 的 assertion 属性将 HttpFoundation 行为添加到 Leo。

$assertion = Leo::assertion();
$assertion->extend(new LeoHttpFoundation());

##断言

###->allow(methods, [message])

  • @param array $methods
  • @param string $message [optional]

检查响应中是否存在允许的头部,并且它包含 所有methods 数组中传递的值。

expect($response)->to->allow(['POST', 'GET']);
expect($response)->to->not->allow(['GET']);

###->status(status, [message])

  • @param int $status
  • @param string $message [optional]

断言响应状态等于 status

expect($response)->to->have->status(200);
expect($response)->to->not->have->status(400);

###->json

  • @param bool $assoc [optional]
  • @param int $depth [optional]
  • @param int $options [optional]

一个语言链,它将响应体解析为 json 并将其设置为断言链的主题。也可以包含 json_decode() 的选项参数。

expect($response)->json->to->have->property('name');
expect($response)->json->to->loosely->equal($expected);
expect($response)->json(true, 999, JSON_BIGINT_AS_STRING)->to->equal($expected);