aaronhipple/sampler 问题修复 & 功能扩展

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

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

aaronhipple/sampler

Composer 安装命令:

composer require aaronhipple/sampler

包简介

Test inline code samples from your docblocks using PHPUnit

README 文档

README

Latest Stable Version Build Status Maintainability Test Coverage

Test inline code samples from your docblocks using PHPUnit!

caveats

  • This is not particularly mature. Issues and pull requests welcome.
  • The extracted sample code is eval'd for testing, with all those security implications. As always, be mindful only to run trusted code in sensitive environments.
  • Right now it only works on classes, class methods, and functions. It does no magic to expose private or protected methods, so normal rules apply.

usage

First, install sampler as a dependency.

$ composer require aaronhipple/sampler

Then, in your PHPUnit suite, implement a case extending AbstractSampleTestCase.

use AaronHipple\Sampler\AbstractSampleTestCase;

class SampleTest extends AbstractSampleTestCase
{
    /**
     * Provide absolute paths to the directories to scan for samples.
     * 
     * @return []string An array of folder paths.
     */
    protected function paths() 
    {
        return [__DIR__ . '/../src'];
    }
   
    /**
     * (Optional) Provide a list of file extensions to scan.
     */
    protected function extensions() 
    {
        return ['php', 'inc'];
    }
}

Finally, write some samples! You can use our @sample annotation...

/**
 * Say hello to someone!
 *
 * @sample
 *   use PHPUnit\Framework\Assert;
 *   Assert::assertInternalType(
 *     'string',
 *     say_hello('Frank')
 *   );
 * @sample
 *   use PHPUnit\Framework\Assert;
 *   Assert::assertEquals(
 *     'Hello, Aaron!',
 *     say_hello('Aaron')
 *   );
 */
function say_hello($name) {
  return "Hello, $name!";
}

...or good ol' inline markdown.

/**
 * Say hello to someone!
 *
 * # Examples
 *
 * ```
 * use PHPUnit\Framework\Assert;
 * Assert::assertEquals(
 *   'Hello, Aaron!',
 *   say_hello('Aaron')
 * );
 * ```
 *
 * ```
 * use PHPUnit\Framework\Assert;
 * Assert::assertEquals(
 *   'Hello, Frank!',
 *   say_hello('Frank')
 * );
 * ```
 */
function say_hello($name) {
  return "Hello, $name!";
}

Run your test suite as usual, with phpunit.

contributing

  • Pull requests are welcome.
  • More tests please.
  • PSR-2 is good. Use phpcbf.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固