2017 © Pedro Peláez
 

library mockery-overload-properties

mock instance's properties via Mockery's overload keyword

image

hermeslin/mockery-overload-properties

mock instance's properties via Mockery's overload keyword

  • Monday, May 21, 2018
  • by hermes
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

mockery overload properties

mock instance's properties via Mockery's overload keyword, (*1)

installation

use composer to install mockery-overload-properties, (*2)

$ 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, (*3)

and you'll find the hard dependencies in Vip.php., (*4)

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., (*5)

test case

under the tests folder, there are two test cases here: 1. LegacyCodeFailTest.php 2. LegacyCodeSuccessTest.php, (*6)

see tests\LegacyCodeSuccessTest.php will show you how to use mockery-overload-properties to mock User, (*7)

    /**
     * @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., (*8)

    /**
     * @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...
    }

The Versions

21/05 2018

dev-master

9999999-dev https://github.com/hermeslin/mockery-overload-properties

mock instance's properties via Mockery's overload keyword

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

25/02 2018

v1.0.1

1.0.1.0 https://github.com/hermeslin/mockery-overload-properties

mock instance's properties via Mockery's overload keyword

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

25/02 2018

v1.0

1.0.0.0 https://github.com/hermeslin/mockery-overload-properties

mock instance's properties via Mockery's overload keyword

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires