承接 hermeslin/mockery-overload-properties 相关项目开发

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

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

hermeslin/mockery-overload-properties

最新稳定版本:v1.0.1

Composer 安装命令:

composer require hermeslin/mockery-overload-properties

包简介

mock instance's properties via Mockery's overload keyword

README 文档

README

mock instance's properties via Mockery's overload keyword

installation

use composer to install mockery-overload-properties

$ composer require --dev hermeslin/mockery-overload-properties

test legacy sample code

under the example folder, you can see the sample code taht we want to test:

  1. User.php
  2. Vip.php

and you'll find the hard dependencies in Vip.php.

hard dependencies are not a big deal, you can use Mockery's overload keyword to mock User instance easily, but it difficult to mock User instance properties when User set the properties on its __construct phase.

test case

under the tests folder, there are two test cases here:

  1. LegacyCodeFailTest.php
  2. LegacyCodeSuccessTest.php

see tests\LegacyCodeSuccessTest.php will show you how to use mockery-overload-properties to mock User

    /**
     * @test
     */
    public function notVipUserBonusShouldCorrect()
    {
        $properties = [
            'id' => 2,
            'isVip' => false,
            'rank' => 99
        ];
        $user = mop::mock('\User', $properties);

        // bounus should be 149
        $bunus = 100 * 0.5 + 99;

        $vip = new Vip;
        $this->assertEquals($bunus, $vip->bonus($userId = 2));
    }

when mock instance whith properties, you still can use Expectation Declarations from Mockery to test you code.

    /**
     * @test
     */
    public function notVipUserBonusShouldCorrect()
    {
        $properties = [
            'id' => 2,
            'isVip' => false,
            'rank' => 99
        ];
        $user = mop::mock('\User', $properties);

        // Expectation
        $user->shouldReceive('name_of_method');
            ->with($arg1, $arg2, ...);
            ->andReturn($value);

        // etc...
    }

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2018-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固