visithor / visithor
PHP 的 Visithor
Requires
- php: ^5.4|^7.0
- guzzlehttp/guzzle: >=4.0.0
- symfony/console: ^2.7|^3.0
- symfony/stopwatch: ^2.7|^3.0
- symfony/yaml: ^2.7|^3.0
Requires (Dev)
- fabpot/php-cs-fixer: 1.4.2
- mmoreram/php-formatter: 1.1.0
- phpunit/phpunit: 4.5.0
README
Visithor 是一个 PHP 库,它以简单的方式让您测试应用程序路由与预期的 HTTP 状态码。
当然,这个项目并不打算避免单元测试、功能测试或行为测试的需求,它只是确保您的路由在长时间内仍然可用的快速且简单的方法。
框架
您可以在某些包中找到一些提供 Visithor 与它们集成的包。为了使用特定功能,请检查这些存储库。
标签
安装
以这种方式安装 Visithor
$ composer global require visithor/visithor=dev-master
如果您是第一次全局安装依赖项,请确保您已将 ~/.composer/vendor/bin
添加到 $PATH,如此处所示。
始终保持 Visithor 安装最新
$ composer global update visithor/visithor
.phar 文件
您还可以使用已构建的最新 .phar
。
$ git clone git@github.com:visithor/visithor.git
$ cd visithor
$ php build/visithor.phar
您可以复制 .phar
文件作为全局脚本
$ cp build/visithor.phar /usr/local/bin/visithor
编译
最后,您还可以编译自己版本的包。(您需要在 php.ini 中设置 phar.readonly = Off
)。
$ git clone git@github.com:visithor/visithor.git
$ cd visithor
$ composer update
$ php bin/compile
$ sudo chmod +x build/visithor.phar
$ build/visithor.phar
您可以复制 .phar
文件作为全局脚本
$ cp build/visithor.phar /usr/local/bin/visithor
配置
Visithor 使用 yml 配置格式进行 URL 定义。这是包含所有可能的配置的主文档。
defaults: # # This value can be a simple HTTP Code or an array of acceptable HTTP Codes # - 200 # - [200, 301] # http_codes: [200, 302] options: verb: GET urls: # # By default, is there is no specified HTTP Code, then default one is used # as the valid one # - http://google.es - http://elcodi.io # # There are some other formats available as well # - [http://shopery.com, 200] - [http://shopery.com, 200, {verb: POST}] - [http://shopery.com, [200, 302]]
您的配置文件可以命名为 visithor.yml
或 visithor.yml.dist
,其中最后一个为首选。
选项
您可以为每个 URL 定义一组选项。每个选项都将可用于在此库之上实现的实现。
urls: - [http://shopery.com, 200, {option1: value1, option2: value2}]
您也可以使用默认:options 路径以全局方式定义这些选项。
defaults: options: option3: value3 urls: - [http://shopery.com, 200, {option1: value1, option2: value2}]
在此示例中,Visithor 将使用默认选项数组作为 URL 的基本选项集,并将最终与每个 URL 中定义的特定选项集合并。
合并意味着如果在两个地方都定义了选项,则 URL 中特别定义的选项将覆盖全局定义的选项。
配置文件
您可以通过创建配置文件来分组一组选项。配置文件是一组用于一组 URL 的选项。
profiles: admin: option1: value1 option2: value2 urls: - [http://shopery.com, 200, {profile: admin}] - [http://elcodi.io, 200, {profile: admin}]
在此示例中,Visithor 将添加给定配置文件内的所有选项,并将其附加到 URL 定义中。所以,最后一个示例与这个示例等价
urls: - [http://shopery.com, 200, {option1: value1, option2: value2}] - [http://elcodi.io, 200, {option1: value1, option2: value2}]
您也可以将配置文件作为全局选项默认分配,通过将其添加为全局选项。最后一个示例与这个示例等价
defaults: options: profile: admin profiles: admin: option1: value1 option2: value2 urls: - [http://shopery.com, 200] - [http://elcodi.io, 200]
动词
您可以在默认选项块中定义首选动词。此值将用作所有 URL 的默认动词,但您可以通过在特定 URL 行中添加新动词来覆盖此值。
defaults: options: verb: GET urls: - [http://shopery.com, 200, {verb: POST}]
命令
要执行 visithor,您需要使用预构建的命令 visithor:go
。
visithor.phar visithor:go [--format|-f] [--config|-c]
执行它后,您将收到此输出(使用最后一个示例)以及 0
作为执行结果的最终值。
Visithor by Marc Morera and contributors.
Configuration read from /var/www/visithor/visithor
[200] http://google.es -- OK
[200] http://elcodi.io -- OK
[200] http://shopery.com -- OK
[200] http://shopery.com -- OK
Time: 1221 ms, Memory: 4Mb
点号格式
您可以使用非显式格式 dots
(使用 --format|-f
选项)。此格式对于非调试环境(如 travis 或类似环境)非常有用。
visithor.phar visithor:go --format=dots
执行它后,您将收到此输出(使用最后一个示例)以及 0
作为执行结果的最终值。
Visithor by Marc Morera and contributors.
Configuration read from /var/www/visithor/visithor
....
Time: 1118 ms, Memory: 4Mb
配置
您可以使用 --config|-c
选项选择 Visithor 配置的位置。
visithor.phar visithor:go --config=/var/www/another/folder