brunty / kahlan-mink

此包已被弃用且不再维护。未建议替代包。

允许在 Kahlan 中使用 Mink

0.2.5 2017-10-03 23:24 UTC

This package is auto-updated.

Last update: 2022-06-23 11:10:27 UTC


README

Build Status

🌍 为在 Kahlan 中使用 Mink 提供功能。同时提供了一种在运行测试时启动 PHP 服务器的方法。

灵感来源于此: http://radify.io/blog/end-to-end-functional-testing-with-kahan/ - 感谢 Simon JAILLET,不仅提供了 Kahlan,还提供了关于 Kahlan 中端到端测试的博客文章。

需求

  • PHP >= 7.1
  • Kahlan ^3.0
  • Mink ^1.7
  • Mink Goutte Driver ^1.2

安装 & 使用

composer require brunty/kahlan-mink --dev

一旦安装,设置配置文件 kahlan-config.php 以将 Mink 注册到 Kahlan(确保将 $this 传递给方法)

<?php // kahlan-config.php

\Brunty\Kahlan\Mink\Mink::register($this);

如果您希望在测试开始时启动 PHP 服务器并在测试执行完成后停止它,则还可以将 PhpServer 注册到 Kahlan

<?php // kahlan-config.php

\Brunty\Kahlan\Mink\PhpServer::register($this);

如果您想使用 url() 辅助函数,则在配置文件中注册一个基本 URL,在 brunty.kahlan-mink.base-url 键下。所有通过 url() 函数的 URL 都将被添加到此。

<?php

\Kahlan\box('brunty.kahlan-mink.base-url', 'http://localhost:8888');

基于上述内容,调用 url('my-page') 将返回 http://localhost:8888/my-page

完成后,您可以使用这些函数通过 Mink 访问事物

  • \Brunty\Kahlan\Mink\browser(string $sessionName = 'default'): Session 返回我们测试套件中 Mink 的实例。
  • \Brunty\Kahlan\Mink\page($sessionName = 'default'): DocumentElement 返回我们当前访问的页面。
  • \Brunty\Kahlan\Mink\element($locator = 'body', Element $parent = null): Element 在我们浏览的页面上找到一个元素。
<?php // spec/MySiteSpec.php

use function Brunty\Kahlan\Mink\browser;
use function Brunty\Kahlan\Mink\element;

describe('My website', function () {
    it('accesses the site', function () {
        browser()->visit('http://localhost:8888/my-page');
        expect(element('#content p')->getText())->toContain('Hello world!');
    });
});

贡献

这最初是一个小的个人项目。

虽然这个项目很小,但开放性和包容性被认真对待。为此,已采用行为准则(列在贡献指南中)。

贡献指南