承接 bakgul/laravel-tests-to-readme 相关项目开发

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

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

bakgul/laravel-tests-to-readme

Composer 安装命令:

composer require bakgul/laravel-tests-to-readme

包简介

A package to output test methods to readme files as a documantation.

README 文档

README

This package aims to generate readme files while tests are being executed. To make this work, you need to call it inside a test method. So, it won't convert each and every test methods to readme file automatically.

Installation and Configuration

sail composer require bakgul/laravel-tests-to-readme --dev
sail artisan vendor:publish --tag=to-readme-config

Now, you can go and change the settings after publishing config file, which is 'to-readme.php'

Finally, we need a folder to store readme files. You can name it as you wish, but it has to be located under one of the folder of the test class path. For example, if your test class is in

base_path('tests/Feature/EndpointTests/UserEndpointTests')

then you can create a folder in

base_path() or base_path('tests') or base_path('tests/Feature') etc.

Some Notes

  1. I suggest you keep readme folder on the root level. That being said, each file will be named based on the testing class. So, if you have multiple classes with the same name, you can't use base_path('readme') for all of them. In that case, you may want to create multiple readme folders.
  2. This package doesn't produce final README.md file. You need to create it manually.
  3. When you add a new test with a call to this package, your new method will be added to the target file.
  4. You can modify the output because it won't be overwritten once it's being printed out.
  5. When you rename a test method, it will be added to the target file. But you need to delete the old one manually.
  6. You can add paragraph, lists, tables in between code blocks. They will be preserved.

How It Works

You should call this package in your test method.

class MyClassTest extends TestCase
{
    /** @test */
    public function my_test_method_does_things(): void
    {
        (new ToReadme([
            'test' => $this->getName();
            'class' => MyClass::class,
            'method' => 'doSomething',
            'args' => [1, 2],
            'message' => 'Anything you want to print.',
            'result' => 3
        ]))->write();

        // Your test ...
    }
}

The code above will generate a readme/MyClass.md file and put the content like between the horizontal lines down below.

MyClass

doSomething

/**
 * If you have Phpdoc, it will be displated here
 */
public function doSomething(int $num1, int $num2): int
// My test method does things.

// Anything you want to print.

(new MyClass)->doSomething(1, 2);

// 3

As you may have noticed, we passed a value as result, and it's printed in the code block. I suggest you do this way, but you don't have to specify the outcome of the method. When the key of "result" doesn't exist, we will try to execute the method and produce the outcome to print.

Phpdoc vs Typehint

This package can use both to produce file. If you make merge_phpdoc_and_method_declaration => true, we will move types from phpdoc to typehint. Otherwise, we won't change anything.

The method down below

/**
 * It does some stuff
 * 
 * @param array $arr
 * @param int   $int
 * @return array
 */
 public function do($arr, $int) { return [$arr, $int]; }

will be printed like this:

/**
 * It does some stuff
 */
 public function do(array $arr, int $int): array

When you use both, and there is an inconsistency between phpdoc and typehints, a warning message will be printed. The method down below

/**
 * It does some stuff
 * 
 * @param array $arr
 * @return array
 */
 public function do(array|string $arr) { return $arr; }

will be printed like this:

WARNINGS:
   - mismatched types.

/**
 * It does some stuff
 */
 public function do(array $arr, int $int): array

There are other inconsistency checks, too. You can find them in to-readme.php

Some Limitations

  1. As it's mentioned before, when you don't pass 'result,' we will try to call the method and get the output. If the class has dependencies, it will probably won't work. In such cases, you better specify the result manually.
  2. The array returned by the method will be converted to Json string and then modifyed through some character replacements to make it looks like a PHP array. It might not turn out well in all cases.
  3. Identifier heading levels cannot be used anywhere else in readme.
  4. First line that starts with '//' has to be the name of the test method.
  5. I couldn't find any way to print out the callable arguments. So, you need to add them manually.

License

This is open-sourced software licensed under the MIT license.

bakgul/laravel-tests-to-readme 适用场景与选型建议

bakgul/laravel-tests-to-readme 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 02 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 bakgul/laravel-tests-to-readme 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-02-09