2017 © Pedro Peláez
 

library mocktation

PHP Mocking using annotations

image

prodikl/mocktation

PHP Mocking using annotations

  • Wednesday, March 14, 2018
  • by prodikl
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Mocktation

PHP Mocking using annotations, (*1)

Build Status, (*2)

Mocktation lets you define return values of class methods when mocking, instead of having to define each return value in your tests., (*3)

By annotating using @mockReturn "test", the method will return "test" by default when calling the method after creating a mock using $this->createMock(CLASSNAME) in your tests., (*4)

This speeds up development since you can define default mock return values when writing the method, instead of retroactively deciding on mock values., (*5)

  1. Install Mocktation, (*6)

    composer require-dev prodikl/mocktation
    
  2. Extend Mocktation/Testcase instead of PHPUnit TestCases, (*7)

    use Mocktation\TestCase;
    
    class ExampleTest extends TestCase {
        public function testGetNum(){
            /** @var Example|MockObject $mock */
            $mock = $this->createMock(Example::class);
            $this->assertEquals(5, $mock->getNum(234));
        }
    } 
    
  3. Use annotations to describe mocking in your methods, (*8)

    class Example {
        /**
         * Accepts an int $num and returns it
         *
         * @param $num      int     The num to return
         * @return int      The example num
         *
         * @mockReturn      5
         */
        public function getNum($num){
            return $num;
        }
    }
    

Here's a list of Mocktation annotations, (*9)

  • @mockReturn [returnValue] - Returns the [returnValue] when called
  • @mockReturnArgument [argumentNumber] - Returns the [argumentNumber] when called. [argumentNumber] starts from 0.

The Versions

14/03 2018

dev-dev

dev-dev

PHP Mocking using annotations

  Sources   Download

MIT

The Requires

 

by Keith Larson

11/03 2018

dev-master

9999999-dev

PHP Mocking using annotations

  Sources   Download

MIT

The Requires

 

by Keith Larson

11/03 2018

v1.0.3

1.0.3.0

PHP Mocking using annotations

  Sources   Download

MIT

The Requires

 

by Keith Larson

11/03 2018

v1.0.2

1.0.2.0

PHP Mocking using annotations

  Sources   Download

The Requires

 

by Keith Larson

11/03 2018

v1.0.1

1.0.1.0

PHP Mocking using annotations

  Sources   Download

The Requires

 

by Keith Larson

11/03 2018

v1.0.0

1.0.0.0

PHP Mocking using annotations

  Sources   Download

The Development Requires

by Keith Larson