定制 fabstract/unit-test 二次开发

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

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

fabstract/unit-test

Composer 安装命令:

composer require fabstract/unit-test

包简介

Unit test library on top of PHP Unit

README 文档

README

Total Downloads Latest Stable Version License

UnitTest

Unit test library on top of PHP Unit.

Installation

Note: PHP 7.1 or higher is required.

  1. Install composer.
  2. Run composer require fabstract/unit-test.

Usage

MethodTestBase

This class is used for separating unit tests by which methods they were written for. Suppose you have the following class:

    
    namespace MyPackage;
    
    class Calculator
    {
        public function add($a, $b) {
            return $a + $b;
        }
        
        public function multiply($a, $b) {
            return $a * $b;
        }
    }

Now in order to write tests for these two methods:

  • Create a directory, preferably the same name with the class name.
  • Inside that directory, create a class for each method you want to test.
  • Name the class as methodName + MethodTest. For example AddMethodTest.
  • Extend the class from MethodTestBase.

Note: Your method should be camelcase.

Here is what it looks like:

    namespace MyPackage\Calculator;

    class AddMethodTest extends \Fabstract\Component\UnitTest\MethodTestBase
    {
        public function testOneAndOneEqualsTwo() {
            $arguments = [1, 1];
            
            $result = $this->call(new Calculator(), $arguments);
            
            $this->assertEquals(2, $result);
        }
        
        public function testOneAndZeroEqualsOne() {
            $arguments = [1, 0];
            
            $result = $this->call(new Calculator(), $arguments);
            
            $this->assertEquals(1, $result);
        }
    }

and

    namespace MyPackage\Calculator;

    class MultiplyMethodTest extends \Fabstract\Component\UnitTest\MethodTestBase
    {
        public function testOneAndOneEqualsOne() {
            $arguments = [1, 1];
            
            $result = $this->call(new Calculator(), $arguments);
            
            $this->assertEquals(1, $result);
        }
        
        public function testOneAndZeroEqualsZero() {
            $arguments = [1, 0];
            
            $result = $this->call(new Calculator(), $arguments);
            
            $this->assertEquals(0, $result);
        }
    }

You can add as many unit tests as you want, without worrying about a method's tests getting mixed up with other method's tests.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固