承接 luttje/php-example-tester 相关项目开发

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

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

luttje/php-example-tester

Composer 安装命令:

composer require luttje/php-example-tester

包简介

Use comments in markdown to automatically compile tested examples into your README

README 文档

README

Use comments in markdown to automatically compile tested examples into your README.

run-tests Coverage Status

Warning

This package is still in development. It is not yet ready for production use and the API may change at any time.

Installation

You can install the package via composer:

composer require luttje/php-example-tester

Usage

1. Prepare your README

Add the start and end comments to your README where you want each individual example to appear:

### `exampleMethod`

Document the example method here, as you normally would.

**Here's the example code:**

<!-- #EXAMPLE_COPY_START = \Luttje\ExampleTester\Tests\Fixtures\ExampleClassTest::exampleMethod -->

This will be replaced with the example code.

<!-- #EXAMPLE_COPY_END -->

*🤓 Yay calculations!*

For a full example have a look at 👀 the example README with placeholders.

You must provide a fully qualified path to the method you want to copy. You can also provide a fully qualified path to a class to copy the entire class.

2. Write tests for that example code

Write your tests in a separate static method in your test class. This package can then extract the body of the method and use it as the example code.

use Luttje\ExampleTester\Tests\TestCase;

final class ExampleClassTest extends TestCase
{
    public static function exampleMethod(): void
    {
        // This is an example method.
        $a = 1;
        $b = 25;

        $c = $a + $b;

        echo $c;
        // This is the end of the example method.
    }

    /**
     * @test
     */
    public function testExampleMethod(): void
    {
        ob_start();
        self::exampleMethod();
        $output = ob_get_clean();

        $this->assertSame('26', $output);
    }
}

3. Compile the examples into your README

Run the example-tester command to compile the examples into your README using the vendor/bin/example-tester compile command.

vendor/bin/example-tester compile

After running the command, the examples will be compiled into your README. This is a section in your README may look like after running the command:

exampleMethod

Document the example method here, as you normally would.

Here's the example code:

// This is an example method.
$a = 1;
$b = 25;

$c = $a + $b;

echo $c;
// This is the end of the example method.

🤓 Yay calculations!

For a full example have a look at 🏗 the compiled example README.

Note

You can make your workflow even smoother by adding the example-tester compile command to your composer.json scripts. That way you can run it with composer compile-readme.

{
    "scripts": {
        "compile-readme": [
            "vendor/bin/example-tester compile"
        ]
    }
}

Advanced usage

You've seen the simple syntax to mark the start of an example, but you can also provide some extra options to the #EXAMPLE_COPY_START comment in the form of a JSON object:

<!-- #EXAMPLE_COPY_START = { "symbol": "\\Luttje\\ExampleTester\\Tests\\Fixtures\\ExampleClassTest::exampleMethod" } -->

Is equivalent to this simpler syntax:

<!-- #EXAMPLE_COPY_START = \Luttje\ExampleTester\Tests\Fixtures\ExampleClassTest::exampleMethod -->

However providing a JSON object unlocks the ability to configure additional properties, like the short property.

The short property

The short property defaults to true and ensures only the body of the method or class is copied into the README.md file.

Setting short to false for a method

Setting the short property to false will also copy the entire method signature into the README.md file for this result:

public static function exampleMethod(): void
{
    // This is an example method.
    $a = 1;
    $b = 25;

    $c = $a + $b;

    echo $c;
    // This is the end of the example method.
}

Setting short to false for a class

For classes it may make more sense to set short to false to copy the entire class into the README.md file for this result:

use Luttje\ExampleTester\Tests\TestCase;

final class ExampleClassTest extends TestCase
{
    public static function exampleMethod(): void
    {
        // This is an example method.
        $a = 1;
        $b = 25;

        $c = $a + $b;

        echo $c;
        // This is the end of the example method.
    }

    /**
     * @test
     */
    public function testExampleMethod(): void
    {
        ob_start();
        self::exampleMethod();
        $output = ob_get_clean();

        $this->assertSame('26', $output);
    }
}

Ignoring examples

Especially for the readme in the root of this package, we want to selectively ignore examples. This can be done by wrapping <!-- #EXAMPLE_COPY_IGNORE_START --> and <!-- #EXAMPLE_COPY_IGNORE_END --> comments around the sections of the readme where you want to not copy examples.

<!-- #EXAMPLE_COPY_IGNORE_START -->

#### Ignored example

This example will be ignored.

<!-- #EXAMPLE_COPY_START = { "symbol": "\\Luttje\\ExampleTester\\Tests\\Fixtures\\ExampleClassTest", "short": false } -->

Should not be removed.

<!-- #EXAMPLE_COPY_END -->

<!-- #EXAMPLE_COPY_IGNORE_END -->

Command-line interface

The command has the following signature:

compile [--output OUTPUT] [--input INPUT]

You must run the command from the root of your project. That way the command can find the vendor directory containing the composer autoload file.

--output

The path to the README file to write the compiled examples to. Defaults to README.md in the root of your project.

vendor/bin/example-tester compile --output DOCS.md

--input

The path to the README file to read the examples from. Defaults to the --output path.

Testing

Run the tests with:

composer test

License

The MIT License (MIT). Please see License File for more information.

luttje/php-example-tester 适用场景与选型建议

luttje/php-example-tester 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 805 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-26