skrepr/dto-tester 问题修复 & 功能扩展

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

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

skrepr/dto-tester

Composer 安装命令:

composer require skrepr/dto-tester

包简介

Skrepr Data Transfer Object Tester

README 文档

README

skrepr

Data Transfer Object - Tester

This is a simple library to make unit tests for DTO's and Entity objects easier. By using this DtoTestCase it will automatically test all public properties and get/set combinations.

Of course this is not just to satisfy the "coverage", but it is to test the basics and makes sure that your DTO's are always behave the same as you expect.

Note that you always must create your own extra tests for specific tasks and any business logic.

Installation

You can install the package using the Composer package manager. It is recommended that you install this only as a development package. You can install it by running this command in your project root:

composer require --dev skrepr/dto-tester

Usage

The abstract class DtoTestCase has 3 required methods for you to implement:

  • getInstance
  • getTestValuesForProperty
  • getTestValuesForMethod

And at this moment one optional setting: - $markEmptyAsSkipped

The getInstance method should return a testable object. This object is only requested twice during all the tests. First for the properties and the second time when the methods are tested.

Next the getTestValuesForProperty and getTestValuesForMethod methods should return an array with possible values that should be tested.

The getTestValuesForProperty method gets the property name and type, here you can check and give values you want to test. You can also give a null value instead of an array, then the tests for that property are skipped (unless it is a nullable-property). The nullable variant will always be tested, it is not possible to use null as a value within the array.

The getTestValuesForMethod method works in the same way, it only gives back the method name extra.

For union types, the property/parameter will be tested for every type in the union.

When you don't have special needs, you can use "match" like this:

    protected function getTestValuesForMethod(string $methodName, string $parameterName, string $parameterType): ?array
    {
        return match ($parameterType) {
            'int' => [1, 42, 1337],
            'string' => ['test', 'skrper'],
            'bool' => [true, false],
            SomeClass::class => [new SomeClass(), $this->createMock(SomeClass::class)]
        };
    }

It is not recommended to use a "default" when using a match like this. In fact, you will get a nice readable exception, so you know what you missed.

Known issues

  • Readonly properties are not supported
  • Not yet possible to test for other result value from getter

skrepr/dto-tester 适用场景与选型建议

skrepr/dto-tester 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.57k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 skrepr/dto-tester 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-23