定制 devel0pmenthero/crash 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

devel0pmenthero/crash

Composer 安装命令:

composer require devel0pmenthero/crash

包简介

A small library for unit- and pentesting code.

README 文档

README

A small unit- and pentest library for PHP.

Installation

composer require devel0pmenthero/crash

Usage

Note: Any parameters can be specified with a leading capital letter.

Generating tests

Single classes

Crash::Create(Subject::class, true, false);
php Crash.php -c[--create] --class="Subject"

Directories

Crash::CreateFromPath("./targetdir", true, false);
php Crash.php -c[--create] -p[--path]="./targetdir"

Inherited methods can be included via passing an optional "inherit"-parameter.

php Crash.php -c[--create] -p[--path]="" -i[--inherit]

Existing test classes can be overwritten by passing an optional "overwrite"-parameter.

php Crash.php -c[--create] -p[--path]="" -o[--overwrite]

Running tests

Crash::Test("./targetdir");
php Crash.php -t[--test] -p[--path]="./targetdir"

Omitting the path will default to the path stored in the public Crash::Tests constant.

Attributes

Crash allows the user to control the execution of specific tests via defining custom attributes. While generating Crash\Tests from existing source, the library will copy over any existing (Crash-)Attributes to the final test classes.

Repeat

#[Repeat(Amount: int, Interval: int)]

The "Repeat"-Attribute allows to execute a test case multiple times in an optional specified interval of microseconds.

Crash

#[Crash(Amount: int, Interval: int)]

The "Crash"-Attribute acts like the former one but passes a random amount of random values to the desired test case instead.

Values

#[Values(Random: int, Interval: int, ...$Values)]

The "Values"-Attribute allows specifying custom values being passed as parameters to the desired test case. Alternatively, the Attribute can generate a specified random amount of values.

Skip

#[Skip]

The "Skip"-Attribute simply instructs the library to skip the test- or case.

Writing Tests

Test are simple php classes and must be located in the "Crash\Tests"-namespace to be recognized as a test.

<?php
declare(strict_types=1);

namespace Crash\Tests;

use Crash\Test\Skip;
use Crash\Test\Method;
use Crash\Test\Method\Repeat;
use Crash\Test\Method\Values;
use Crash\Test\Method\Crash;

#[Skip]
class MyTest extends \Crash\Test {

    private int $Repetitions = 0;

    #[Repeat(5)]
    public function Repeat() {
        $this->Repetitions++;
    }

    public function RepeatedEnough(): void{
        \assert($this->Repetitions === 5);
    }
    
    #[Method\Skip]
    public function FailsAnyway(): void {
        \assert(false);
    }
    
    #[Values("a", 12, true)]
    public function Values($A, $B, $C): void {
        \assert($A === "a");
        \assert($B === 12);
        \assert($C === true);
    }    
    
    #[Values(Random: 8)]
    public function RandomValues(...$Values): void {
        \assert(\count($Values) === 8);
    }    
    
    #[Crash(Amount: 1000000, Interval: 20)]
    public function Crash(...$Values): void {
        ClassToTest::Method(...$Values);
    }

}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固