承接 teamgantt/phony-kahlan 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

teamgantt/phony-kahlan

Composer 安装命令:

composer require teamgantt/phony-kahlan

包简介

Phony for Kahlan.

README 文档

README

Phony for Kahlan

Current version image

Installation

composer require --dev teamgantt/phony-kahlan

See also

What is Phony for Kahlan?

Phony for Kahlan is a plugin for the Kahlan testing framework that provides general integration with the Phony mocking framework, as well as optional auto-wired test dependencies.

In other words, if a Kahlan test (or suite) requires a mock object, it can be defined to have a parameter with an appropriate type declaration, and it will automatically receive a mock of that type as an argument when run.

Stubs for callable types, and "empty" values for other type declarations are also supported.

Plugin installation

Installation is only required when using the dependency injection features of the plugin. The plugin can be installed in the Kahlan configuration file like so:

<?php // kahlan-config.php

// disable monkey-patching for Phony classes
$this->commandLine()->set('exclude', ['Eloquent\Phony']);

// install the plugin once autoloading is available
Kahlan\Filter\Filters::apply($this, 'run', function (callable $chain) {
    Eloquent\Phony\Kahlan\install();

    return $chain();
});

Dependency injection

Once the plugin is installed, any tests or suites that are defined with parameters will be supplied with matching arguments when run:

describe('Phony for Kahlan', function () {
    it('Auto-wires test dependencies', function (PDO $db) {
        expect($db)->toBeAnInstanceOf(PDO::class);
    });
});

Injected mock objects

Phony for Kahlan supports automatic injection of mock objects. Because Phony doesn't alter the interface of mocked objects, it is necessary to use on() to retrieve the mock handle in order to perform stubbing and verification:

use function Eloquent\Phony\Kahlan\on;

describe('Phony for Kahlan', function () {
    it('Supports stubbing', function (PDO $db) {
        on($db)->exec->with('DELETE FROM users')->returns(111);

        expect($db->exec('DELETE FROM users'))->toBe(111);
    });

    it('Supports verification', function (PDO $db) {
        $db->exec('DROP TABLE users');

        on($db)->exec->calledWith('DROP TABLE users');
    });
});

Injected stubs

Phony for Kahlan supports automatic injection of stubs for parameters with a callable type declaration:

describe('Phony for Kahlan', function () {
    it('Supports callable stubs', function (callable $stub) {
        $stub->with('a', 'b')->returns('c');
        $stub('a', 'b');

        $stub->calledWith('a', 'b')->firstCall()->returned('c');
    });
});

Supported types

The following table lists the supported type declarations, and the value supplied for each:

Parameter type Supplied value
(none) null
bool false
int 0
float .0
string ''
array []
iterable []
object (object) []
stdClass (object) []
callable stub()
Closure function () {}
Generator (function () {return; yield;})()

When using a type declaration that is not listed above, the supplied value will be a mock of the specified type.

By necessity, the supplied value will not be wrapped in a mock handle. In order to obtain a handle, simply use on():

use function Eloquent\Phony\Kahlan\on;

it('Example mock handle retrieval', function (ClassA $mock) {
    $handle = on($mock);
});

License

For the full copyright and license information, please view the LICENSE file.

Note

This is a fork of the now unmaintained eloquent/phony-kahlan. The original purpose of this fork was to allow for compatibility with PHP 8.3. Be aware that we do not intend to regularly maintain this other than to keep it up to date with PHP as needed.

teamgantt/phony-kahlan 适用场景与选型建议

teamgantt/phony-kahlan 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.04k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 teamgantt/phony-kahlan 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-05