定制 albertcht/lumen-testing 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

albertcht/lumen-testing

Composer 安装命令:

composer require --dev albertcht/lumen-testing

包简介

Testing Suite For Lumen like Laravel does.

README 文档

README

php-badge packagist-badge Total Downloads travis-badge

Description

A testing suite for Lumen like Laravel does.

Requirements

  • >= PHP 7.1
  • >= Lumen 5.3

Installation

composer require --dev albertcht/lumen-testing
  • Make your test case extend AlbertCht\Lumen\Testing\TestCase

You're all done! Enjoy your testing like in Laravel!

Concerns

There are some traits you can use in your test case (including original ones in Lumen):

  • AlbertCht\Lumen\Testing\Concerns\RefreshDatabase
  • AlbertCht\Lumen\Testing\Concerns\WithFaker
  • AlbertCht\Lumen\Testing\Concerns\InteractsWithRedis
  • AlbertCht\Lumen\Testing\Concerns\InteractsWithConsole
  • AlbertCht\Lumen\Testing\Concerns\InteractsWithContainer
  • Laravel\Lumen\Testing\DatabaseMigrations
  • Laravel\Lumen\Testing\DatabaseTransactions
  • Laravel\Lumen\Testing\WithoutMiddleware
  • Laravel\Lumen\Testing\WithoutEvents

RefreshDatabase = DatabaseMigrations + DatabaseTransactions, so if you use RefreshDatabase, you don't need to use the other two traits anymore.

Response Assertions

Laravel provides a variety of custom assertion methods for your PHPUnit tests. These assertions may be accessed on the response that is returned from the json, get, post, put, and delete test methods:

Method Description
$response->assertSuccessful(); Assert that the response has a successful status code.
$response->assertStatus($code); Assert that the response has a given code.
$response->assertRedirect($uri); Assert that the response is a redirect to a given URI.
$response->assertHeader($headerName, $value = null); Assert that the given header is not present on the response.
$response->assertHeaderMissing($headerName); Assert that the given header is present on the response.
$response->assertCookie($cookieName, $value = null); Assert that the response contains the given cookie.
$response->assertPlainCookie($cookieName, $value = null); Assert that the response contains the given cookie (unencrypted).
$response->assertCookieExpired($cookieName); Assert that the response contains the given cookie and it is expired.
$response->assertCookieNotExpired($cookieName); Assert that the response contains the given cookie and it is not expired.
$response->assertCookieMissing($cookieName); Assert that the response does not contains the given cookie.
$response->assertJson(array $data); Assert that the response contains the given JSON data.
$response->assertJsonCount(int $count, $key = null); Assert that the response JSON has the expected count of items at the given key.
$response->assertJsonFragment(array $data); Assert that the response contains the given JSON fragment.
$response->assertJsonMissing(array $data); Assert that the response does not contain the given JSON fragment.
$response->assertJsonMissingExact(array $data); Assert that the response does not contain the exact JSON fragment.
$response->assertExactJson(array $data); Assert that the response contains an exact match of the given JSON data.
$response->assertJsonStructure(array $structure); Assert that the response has a given JSON structure.
$response->assertJsonValidationErrors($keys); Assert that the response has the given JSON validation errors for the given keys.
$response->assertViewIs($value); Assert that the given view was returned by the route.
$response->assertViewHas($key, $value = null); Assert that the response view was given a piece of data.
$response->assertViewHasAll(array $data); Assert that the response view has a given list of data.
$response->assertViewMissing($key); Assert that the response view is missing a piece of bound data.
$response->assertSee($value); Assert that the given string is contained within the response.
$response->assertDontSee($value); Assert that the given string is not contained within the response.
$response->assertSeeText($value); Assert that the given string is contained within the response text.
$response->assertDontSeeText($value); Assert that the given string is not contained within the response text.
$response->assertSeeInOrder(array $values); Assert that the given strings are contained in order within the response.
$response->assertSeeTextInOrder(array $values); Assert that the given strings are contained in order within the response text.

Authentication Assertions

Laravel also provides a variety of authentication related assertions for your PHPUnit tests:

Method Description
$this->assertAuthenticated($guard = null); Assert that the user is authenticated.
$this->assertGuest($guard = null); Assert that the user is not authenticated.
$this->assertAuthenticatedAs($user, $guard = null); Assert that the given user is authenticated.
$this->assertCredentials(array $credentials, $guard = null); Assert that the given credentials are valid.
$this->assertInvalidCredentials(array $credentials, $guard = null); Assert that the given credentials are invalid.

Database Assertions

Laravel provides several database assertions for your PHPUnit tests:

Method Description
$this->assertDatabaseHas($table, array $data); Assert that a table in the database contains the given data.
$this->assertDatabaseMissing($table, array $data); Assert that a table in the database does not contain the given data.
$this->assertSoftDeleted($table, array $data); Assert that the given record has been soft deleted.

Reference

See full document at Laravel's doc:

Support on Beerpay

Hey dude! Help me out for a couple of 🍻!

Beerpay Beerpay

albertcht/lumen-testing 适用场景与选型建议

albertcht/lumen-testing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35.91k 次下载、GitHub Stars 达 43, 最近一次更新时间为 2017 年 12 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「testing」 「phpunit」 「test」 「laravel」 「lumen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 albertcht/lumen-testing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 albertcht/lumen-testing 我们能提供哪些服务?
定制开发 / 二次开发

基于 albertcht/lumen-testing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 35.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 43
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 43
  • Watchers: 5
  • Forks: 23
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-12-30