xp-framework/webtest 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

xp-framework/webtest

最新稳定版本:v7.1.0

Composer 安装命令:

composer require xp-framework/webtest

包简介

Web tests for the XP Framework

关键字:

README 文档

README

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.0+ Supports PHP 8.0+ Latest Stable Version

Web tests for the XP Framework

Example

The following web test case consists of opening GitHub's homepage and asserting the title to equal the company's name:

use unittest\web\{WebTestCase, Webtest};
use unittest\Test;

#[Webtest(url: 'https://github.com/')]
class GitHubTestCase extends WebTestCase {

  #[Test]
  public function home() {
    $this->beginAt('/');
    $this->assertStatus(200);
    $this->assertTitleEquals('GitHub: Where the world builds software · GitHub');
  }
}

Running it works as with normal test cases:

$ xp test GitHubTestCase
[.]

✓: 1/1 run (0 skipped), 1 succeeded, 0 failed
Memory used: 1861.12 kB (2474.66 kB peak)
Time taken: 1.225 seconds

To overwrite the default URL specified in the annotation, supply it as command line argument, e.g. unittest GitHubTestCase -a https://github.staging.lan/.

Assertion methods

On top of the assertion methods provided by the unittest library, the following response-related assertions are available:

public void assertStatus(int $status)
public void assertUrlEquals(peer.URL $url)
public void assertContentType(string $ctype)
public void assertHeader(string $header, string $value)
public void assertElementPresent(string $id)
public void assertTextPresent(string $text)
public void assertImagePresent(string $src)
public void assertLinkPresent(string $url)
public void assertLinkPresentWithText(string $text)
public void assertFormPresent(string $name= null)
public void assertTitleEquals($title)

Navigation

To follow links inside a page, a web test can utilize the click methods:

protected void clickLink(string $id);
protected void clickLinkWithText(string $text);

Forms

To work with forms, the getForm() method can be used:

use unittest\web\{WebTestCase, Webtest};
use unittest\Test;

#[Webtest(url: 'https://github.com/')]
class GitHubTestCase extends WebTestCase {

  #[Test]
  public function search_for() {
    $this->beginAt('/');
    $form= $this->getForm();
    $form->getField('q')->setValue('XP Framework');
    $form->submit();
    $this->assertStatus(200);
    $this->assertTitleEquals('Search · XP Framework · GitHub');
  }
}

See also

xp-framework/rfc#169

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-07-31