Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL).

Overview

Mockery

Build Status Latest Stable Version Coverage Status Total Downloads

Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.

Mockery is released under a New BSD License.

Installation

To install Mockery, run the command below and you will get the latest version

composer require --dev mockery/mockery

Documentation

In older versions, this README file was the documentation for Mockery. Over time we have improved this, and have created an extensive documentation for you. Please use this README file as a starting point for Mockery, but do read the documentation to learn how to use Mockery.

The current version can be seen at docs.mockery.io.

PHPUnit Integration

Mockery ships with some helpers if you are using PHPUnit. You can extend the Mockery\Adapter\Phpunit\MockeryTestCase class instead of PHPUnit\Framework\TestCase, or if you are already using a custom base class for your tests, take a look at the traits available in the Mockery\Adapter\Phpunit namespace.

Test Doubles

Test doubles (often called mocks) simulate the behaviour of real objects. They are commonly utilised to offer test isolation, to stand in for objects which do not yet exist, or to allow for the exploratory design of class APIs without requiring actual implementation up front.

The benefits of a test double framework are to allow for the flexible generation and configuration of test doubles. They allow the setting of expected method calls and/or return values using a flexible API which is capable of capturing every possible real object behaviour in way that is stated as close as possible to a natural language description. Use the Mockery::mock method to create a test double.

$double = Mockery::mock();

If you need Mockery to create a test double to satisfy a particular type hint, you can pass the type to the mock method.

class Book {}

interface BookRepository {
    function find($id): Book;
    function findAll(): array;
    function add(Book $book): void;
}

$double = Mockery::mock(BookRepository::class);

A detailed explanation of creating and working with test doubles is given in the documentation, Creating test doubles section.

Method Stubs 🎫

A method stub is a mechanism for having your test double return canned responses to certain method calls. With stubs, you don't care how many times, if at all, the method is called. Stubs are used to provide indirect input to the system under test.

$double->allows()->find(123)->andReturns(new Book());

$book = $double->find(123);

If you have used Mockery before, you might see something new in the example above — we created a method stub using allows, instead of the "old" shouldReceive syntax. This is a new feature of Mockery v1, but fear not, the trusty ol' shouldReceive is still here.

For new users of Mockery, the above example can also be written as:

$double->shouldReceive('find')->with(123)->andReturn(new Book());
$book = $double->find(123);

If your stub doesn't require specific arguments, you can also use this shortcut for setting up multiple calls at once:

$double->allows([
    "findAll" => [new Book(), new Book()],
]);

or

$double->shouldReceive('findAll')
    ->andReturn([new Book(), new Book()]);

You can also use this shortcut, which creates a double and sets up some stubs in one call:

$double = Mockery::mock(BookRepository::class, [
    "findAll" => [new Book(), new Book()],
]);

Method Call Expectations 📲

A Method call expectation is a mechanism to allow you to verify that a particular method has been called. You can specify the parameters and you can also specify how many times you expect it to be called. Method call expectations are used to verify indirect output of the system under test.

$book = new Book();

$double = Mockery::mock(BookRepository::class);
$double->expects()->add($book);

During the test, Mockery accept calls to the add method as prescribed. After you have finished exercising the system under test, you need to tell Mockery to check that the method was called as expected, using the Mockery::close method. One way to do that is to add it to your tearDown method in PHPUnit.

public function tearDown()
{
    Mockery::close();
}

The expects() method automatically sets up an expectation that the method call (and matching parameters) is called once and once only. You can choose to change this if you are expecting more calls.

$double->expects()->add($book)->twice();

If you have used Mockery before, you might see something new in the example above — we created a method expectation using expects, instead of the "old" shouldReceive syntax. This is a new feature of Mockery v1, but same as with accepts in the previous section, it can be written in the "old" style.

For new users of Mockery, the above example can also be written as:

$double->shouldReceive('find')
    ->with(123)
    ->once()
    ->andReturn(new Book());
$book = $double->find(123);

A detailed explanation of declaring expectations on method calls, please read the documentation, the Expectation declarations section. After that, you can also learn about the new allows and expects methods in the Alternative shouldReceive syntax section.

It is worth mentioning that one way of setting up expectations is no better or worse than the other. Under the hood, allows and expects are doing the same thing as shouldReceive, at times in "less words", and as such it comes to a personal preference of the programmer which way to use.

Test Spies 🕵️

By default, all test doubles created with the Mockery::mock method will only accept calls that they have been configured to allow or expect (or in other words, calls that they shouldReceive). Sometimes we don't necessarily care about all of the calls that are going to be made to an object. To facilitate this, we can tell Mockery to ignore any calls it has not been told to expect or allow. To do so, we can tell a test double shouldIgnoreMissing, or we can create the double using the Mocker::spy shortcut.

// $double = Mockery::mock()->shouldIgnoreMissing();
$double = Mockery::spy();

$double->foo(); // null
$double->bar(); // null

Further to this, sometimes we want to have the object accept any call during the test execution and then verify the calls afterwards. For these purposes, we need our test double to act as a Spy. All mockery test doubles record the calls that are made to them for verification afterwards by default:

$double->baz(123);

$double->shouldHaveReceived()->baz(123); // null
$double->shouldHaveReceived()->baz(12345); // Uncaught Exception Mockery\Exception\InvalidCountException...

Please refer to the Spies section of the documentation to learn more about the spies.

Utilities 🔌

Global Helpers

Mockery ships with a handful of global helper methods, you just need to ask Mockery to declare them.

Mockery::globalHelpers();

$mock = mock(Some::class);
$spy = spy(Some::class);

$spy->shouldHaveReceived()
    ->foo(anyArgs());

All of the global helpers are wrapped in a !function_exists call to avoid conflicts. So if you already have a global function called spy, Mockery will silently skip the declaring its own spy function.

Testing Traits

As Mockery ships with code generation capabilities, it was trivial to add functionality allowing users to create objects on the fly that use particular traits. Any abstract methods defined by the trait will be created and can have expectations or stubs configured like normal Test Doubles.

trait Foo {
    function foo() {
        return $this->doFoo();
    }

    abstract function doFoo();
}

$double = Mockery::mock(Foo::class);
$double->allows()->doFoo()->andReturns(123);
$double->foo(); // int(123)

Versioning

The Mockery team attempts to adhere to Semantic Versioning, however, some of Mockery's internals are considered private and will be open to change at any time. Just because a class isn't final, or a method isn't marked private, does not mean it constitutes part of the API we guarantee under the versioning scheme.

Alternative Runtimes

Mockery 1.3 was the last version to support HHVM 3 and PHP 5. There is no support for HHVM 4+.

A new home for Mockery

⚠️ ️ Update your remotes! Mockery has transferred to a new location. While it was once at padraic/mockery, it is now at mockery/mockery. While your existing repositories will redirect transparently for any operations, take some time to transition to the new URL.

$ git remote set-url upstream https://github.com/mockery/mockery.git

Replace upstream with the name of the remote you use locally; upstream is commonly used but you may be using something else. Run git remote -v to see what you're actually using.

Issues
  • Hamcrest conflicts with PHPUnit

    Hamcrest conflicts with PHPUnit

    opened by Ocramius 40
  • Mockery does not provide integration with PHPUnit

    Mockery does not provide integration with PHPUnit

    PHPUnit has a test mode designed to "report useless tests" which marks tests that do not perform any assertions or expectations. However, PHPUnit is ignorant to any expectations performed on Mockery objects since Mockery has no integration with PHPUnit.

    documentation 
    opened by Bilge 34
  • Massive Documentation Improvements

    Massive Documentation Improvements

    I've corrected a few typos and formatting derps, and I have moved all the documentation to a docs folder. Each h2 heading now has it's own file. I have updated the contents page on the readme for this change.

    opened by GrahamCampbell 31
  • Basic/naive spy implementation

    Basic/naive spy implementation

    Had a play with this tonight, basic use:

    <?php
    
    $spy = m::spy();
    $spy->myMethod();
    $spy->shouldHaveReceived("myMethod");
    

    It wont handle some weird cases, because it tries to verify on the fly, i.e., you don't have to manually call a verify method. Having such a requirement would make it possible to do

    <?php
    
    $spy->shouldNotHaveReceived("find")->with(123)->verify();
    

    However, I'm not really sure I'd ever really write code that would require that, and even if I did, I could always fall back to mocks with expectations.

    Would appreciate thoughts, I'm keen to get some kind of spy implementation in soon so people can give it a good look before we settle on an API for 1.0.

    feature request 
    opened by davedevelopment 29
  • Add options to make all methods as stubs, returning null by default

    Add options to make all methods as stubs, returning null by default

    I'm referring to this documentation of PHPUnit for creating mocked object that all methods are stubs, which return null by default: Unit Testing Tutorial (Do not call setMethods() & Passing an empty array)

    This kind of feature doesn't seems currently available on Mockery.

    One option that close to that is shouldIgnoreMissing(), but this option will always return null even when the method being called is not exists. This is not good when there's a typo in either unit test's class or actual class.

    The additional option of makeStubs() works alike, but will still throw error when a nonexistent method is called.

    opened by yeka 27
  • Add `withArgs()` to validate via closure passed arguments at once

    Add `withArgs()` to validate via closure passed arguments at once

    I think would be handy a method like

    withArgs($closure)
    

    that would work similar to

    with( Mockery::on($closure) );
    

    with the only difference that in first case the $closurereceives all the arguments passed to the target method.

    feature request 
    opened by gmazzap 27
  • PHPUnit - Spy assertions aren't updating expectation count

    PHPUnit - Spy assertions aren't updating expectation count

    When using mocky assertions with PHPUnit 6.3:

    $eventListener = \Mockery::mock(EventListenerInterface::class)
                ->shouldNotReceive('handle')
                ->getMock();
    

    I can update the assertion count by doing something like

    protected function tearDown()
        {
            if ($container = \Mockery::getContainer()) {
                $this->addToAssertionCount($container->mockery_getExpectationCount());
            }
    
            parent::tearDown();
        }
    

    Which is kind of annoying but ok. As long as it gets rid of the warning about no assertions.

    This doesn't work however:

    $eventListener = \Mockery::spy(EventListenerInterface::class);
    $eventListener->shouldHaveNotReceived('handle')
    

    Since apparently spy assertions don't update the exceptations and thus the expectation count.

    Is there a better way to go about this, other than doing something likebeStrictAboutTestsThatDoNotTestAnything="false"?

    bug can't reproduce 
    opened by dallincoons 26
  • Partial mocks do not mock constructor

    Partial mocks do not mock constructor

    After recent changes partial mocking of constructor doesn't work.

    namespace Acme;
    
    class ExampleClass
    {
        public function __construct(DependencyInterface $dep)
        {
        }
    }
    
    \Mockery::mock('Acme\ExampleClass[__construct]');
    

    After running phpunit following error occurs:

    Argument 1 passed to 'Mockery_518b69580914a::__construct() must implement interface Acme\DependencyInterface, none given

    opened by krymen 26
  • Memory usage in long run

    Memory usage in long run

    From my observations the Mockery seems to store all created mock instances (or at least their expectations) somewhere internally. This can cause problems in large tests, when after mock is no longer needed in one of the tests it's not being garbage collected, because Mockery container has reference to it.

    I think, that we can safely assume, that by the time, when Mockery test listener is called by PHPUnit (in tearDownAfterClass), then we can free memory by removing unused mocks.

    If somebody wants to test, then feel free to grab https://github.com/aik099/qa-tools, which test suite is using Mockery extensivery and can eat up till 300MB of memory.

    This was too much for TravisCI and I decided to run tests in parallel to make each process memory consumption smaller.

    opened by aik099 25
  • Partial mock is not working with $this

    Partial mock is not working with $this

    Hi,

    I am having problem with partial mock and use of $this inside of it.

    I will put some code sample to be clearer.

    In my test I have something like below:

    $serviceMock = Mockery::mock('Service');
    $serviceMock->shouldReceive('spam')->andReturn('eggs');
    
    $foobar = Mockery::mock(new Foobar($foo));
    $foobar->shouldReceive('getService')
        ->andReturn($serviceMock);
    
    $foobar->useService();
    

    In my real code I have something like this:

    class Foobar {
        public function __construct($foo) { 
            $this->foo = $foo;
        }
    
        public function useService() {
            $bacon = $this->foo->bacon();
    
            $service = $this->getService();
            $eggs = $service->spam();
    
            return $bacon + $eggs;
        }
    
        public function getService() {
            return new RealService(); // hits network and I don't want to hit it
        }
    }
    

    I was migrating a PHPUnit test to Mockery and I had this problem, I believe one way to do it is using Injection, something like setService($service), but right now I have a huge code base that works with PHPUnit. Is this a bug of Mockery or something expected to happen?

    Thanks for your help!

    opened by cabello 24
  • Mock classes with `new` in initializers on PHP 8.1

    Mock classes with `new` in initializers on PHP 8.1

    This patch resolves #1154, via the following changes:

    • Add tests and fixtures
    • Mock classes with new in initializers
    opened by ghostwriter 1
  • Mockery::mock on Redis (php extension) can't mock `eval` method: should blacklisted methods raise an error when an expectation is set for them?

    Mockery::mock on Redis (php extension) can't mock `eval` method: should blacklisted methods raise an error when an expectation is set for them?

    Me and my co-worker had some fun today figuring out why:

    • I could mock \Redis (the PHP extension)
    • could specify an expectation for the method eval
    • but whenever the eval method on the mocked instance was called, we straight received a RedisException: Redis server went away in …

    To give an example, assuming mockery being installed and use this test script:

    <?php
    require __DIR__ . '/vendor/autoload.php';
    
    $redisMock = Mockery::mock(Redis::class);
    $redisMock->shouldReceive('eval');
    $redisMock->eval('test');
    

    Without extension loaded:

    $ php test.php
    $
    

    Run it with redis extension loaded:

    $ php -d extension=redis test.php
    
    Fatal error: Uncaught RedisException: Redis server went away in test.php:6
    

    There are some obvious things like eval being reserved, you can't even use it as class method. The PHP extension can however it is definitely an outlier.

    The solution in this case was simply to use a custom MockConfigurationBuiler and a custom list of methods to pass to setBlackListedMethods which does not include eval and it just works.

    But I was wondering

    When a method is disallowed to be used for mocking and part of the list, shouldn't any expectation set on such a method actually raise an error maybe? Because effectively it can't work 🤔

    Thanks!

    opened by mfn 0
  • Removes redundant code

    Removes redundant code

    Fixes #1145

    opened by davedevelopment 0
  • PHP 8.1 new in constructor initializers

    PHP 8.1 new in constructor initializers

    Mockery does not support new in constructor initializers. That is, the following cannot be mocked without an error.

    class MyController {
        public function __construct(
            private Logger $logger = new NullLogger(),
        ) {}
    }
    

    Mocking this will generate an error similar to the following:

    PHP Fatal error: Constant expression contains invalid operations in mockery\mockery\library\Mockery\Loader\EvalLoader.php(34) : eval()'d code on line 974

    opened by Bilge 1
  • Proxy support is broken.

    Proxy support is broken.

    According to the docs, passing a object directly to the mock method will proxy the call instead of inheriting and overwriting the class. That seems to be broken though, since it still generates constructs like this:

    class Mockery_2_App_Filter_ProjectFilter_App_Filter_ProjectFilter extends \App\Filter\ProjectFilter implements MockInterface
    

    The problem here is that the Filter extends a 3rd Party class with final functions resulting in an exception during the test:

    Fatal error: Cannot override final method Doctrine\ORM\Query\Filter\SQLFilter::__toString() in /srv/api/vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php(34) : eval()'d code on line 418
    
    Remaining indirect deprecation notices (56)
    Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException^ {#3829
      -id: "kernel"
      -sourceId: null
      -alternatives: []
      #message: "The "kernel" service is synthetic, it needs to be set at boot time before it can be used."
      #code: 0
      #file: "/srv/api/vendor/symfony/dependency-injection/Container.php"
      #line: 254
      -previous: Symfony\Component\ErrorHandler\Error\FatalError^ {#11
        -error: array:4 [
          "type" => 64
          "message" => "Cannot override final method Doctrine\ORM\Query\Filter\SQLFilter::__toString()"
          "file" => "/srv/api/vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php(34) : eval()'d code"
          "line" => 418
        ]
        #message: "Compile Error: Cannot override final method Doctrine\ORM\Query\Filter\SQLFilter::__toString()"
        #code: 0
        #file: "/srv/api/vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php(34) : eval()'d code"
        #line: 418
      }
      trace: {
        /srv/api/vendor/symfony/dependency-injection/Container.php:254 { …}
        /srv/api/vendor/symfony/dependency-injection/Container.php:219 { …}
        /srv/api/var/cache/test/ContainerBUVU0uj/App_KernelTestDebugContainer.php:4842 {
          ContainerBUVU0uj\App_KernelTestDebugContainer->getSensioFrameworkExtra_View_ListenerService()^
          › {
          ›     $this->privates['sensio_framework_extra.view.listener'] = $instance = new \Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener(($this->privates['sensio_framework_extra.view.guesser'] ?? ($this->privates['sensio_framework_extra.view.guesser'] = new \Sensio\Bundle\FrameworkExtraBundle\Templating\TemplateGuesser(($this->services['kernel'] ?? $this->get('kernel', 1))))));
          › 
          arguments: {
            $id: "kernel"
            $invalidBehavior: 1
          }
        }
        /srv/api/var/cache/test/ContainerBUVU0uj/App_KernelTestDebugContainer.php:1257 { …}
        /srv/api/vendor/symfony/event-dispatcher/EventDispatcher.php:245 { …}
        /srv/api/vendor/symfony/event-dispatcher/EventDispatcher.php:76 { …}
        /srv/api/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:293 { …}
        /srv/api/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:148 { …}
        /srv/api/vendor/symfony/http-kernel/HttpKernel.php:140 { …}
        /srv/api/vendor/symfony/http-kernel/HttpKernel.php:74 { …}
        /srv/api/vendor/symfony/http-kernel/EventListener/ErrorListener.php:71 { …}
        /srv/api/vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117 { …}
        /srv/api/vendor/symfony/event-dispatcher/EventDispatcher.php:230 { …}
        /srv/api/vendor/symfony/event-dispatcher/EventDispatcher.php:59 { …}
        /srv/api/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:154 { …}
        /srv/api/vendor/symfony/http-kernel/HttpKernel.php:213 { …}
        /srv/api/vendor/symfony/http-kernel/HttpKernel.php:106 { …}
        /srv/api/vendor/symfony/http-kernel/EventListener/DebugHandlersListener.php:131 { …}
        /srv/api/vendor/symfony/error-handler/ErrorHandler.php:607 { …}
        /srv/api/vendor/symfony/error-handler/ErrorHandler.php:697 { …}
        Symfony\Component\ErrorHandler\ErrorHandler::handleFatalError() {}
      }
    }
    

    So it would be neat if proxying actually worked like described :)

    opened by KDederichs 2
  • PHP 8.1 support

    PHP 8.1 support

    Hi, are you considering/have roadmap for PHP 8.1 support as it is GA now? :)

    opened by carloscz 1
  • mocking laravel db facade on `when` method

    mocking laravel db facade on `when` method

    Hi,

    I am using laravel with mockery to unit test my queries.. how can I mock the when method of laravel db query using mockery? so here is what I want to test..

    <?php
    // ... TestRepo.php
    class TestRepo
    {
        public function testQb()
        {
            DB::table('users')
                ->when(true, function($query) {
                    $query->where('email_verified_at', null);
                })
                ->get();
        }
    }
    

    and here is what my test look like..

    /**
     * A basic test example.
     *
     * @return void
     */
    public function test_example()
    {
        DB::shouldReceive('table')->once()->with('users')->andReturnSelf();
        DB::shouldReceive('get')->once()->andReturn(collect(new User()));
        (new TestRepo())->testQb();
        $this->assertTrue(true);
    }
    

    the only missing on this test is the part where the when method is being called. is this possible to mock also on mockery? and how can I do that? thanks in advance

    opened by besingamkb 1
  • I can't mock static & non static function in same class.

    I can't mock static & non static function in same class.

    I want to mock a class with static functions and non-static functions. But I can't do it.

    I try to use an alias but all function is static.

    opened by khiemnguyen-ffw 0
  • Impossible to use PHPUnitConstraint

    Impossible to use PHPUnitConstraint

    opened by udavka 0
  • How to mock protected properties?

    How to mock protected properties?

    Does mockery support mock protected properties? What should I do if I can?

    opened by kaysonwu 1
Releases(1.3.5)
  • 1.3.5(Sep 13, 2021)

    • Fix auto-generated return values with union types #1143
    • Adds support for tentative types #1130
    • Fixes for PHP 8.1 Support (#1130 and #1140)
    Source code(tar.gz)
    Source code(zip)
  • 1.4.4(Sep 13, 2021)

    • Fixes auto-generated return values #1144
    • Adds support for tentative types #1130
    • Fixes for PHP 8.1 Support (#1130 and #1140)
    • Add method that allows defining a set of arguments the mock should yield #1133
    • Added option to configure default matchers for objects \Mockery::getConfiguration()->setDefaultMatcher($class, $matcherClass) #1120
    Source code(tar.gz)
    Source code(zip)
  • 1.4.3(Feb 24, 2021)

    • Fixes calls to fetchMock before initialisation #1113
    • Allow shouldIgnoreMissing() to behave in a recursive fashion #1097
    • Custom object formatters #766 (Needs Docs)
    • Fix crash on a union type including null #1106
    Source code(tar.gz)
    Source code(zip)
  • 1.3.4(Feb 24, 2021)

  • 1.3.3(Aug 11, 2020)

    • Fix array to string conversion in ConstantsPass (#1086)
    • Fixed nullable PHP 8.0 union types (#1088)
    • Fixed support for PHP 8.0 parent type (#1088)
    • Fixed PHP 8.0 mixed type support (#1088)
    • Fixed PHP 8.0 union return types (#1088)

    Thanks again to @GrahamCampbell

    Source code(tar.gz)
    Source code(zip)
  • 1.4.2(Aug 11, 2020)

    • Fix array to string conversion in ConstantsPass (#1086)
    • Fixed nullable PHP 8.0 union types (#1088, #1089)
    • Fixed support for PHP 8.0 parent type (#1088, #1089)
    • Fixed PHP 8.0 mixed type support (#1088, #1089)
    • Fixed PHP 8.0 union return types (#1088, #1089)

    Big thank you to @GrahamCampbell

    Source code(tar.gz)
    Source code(zip)
  • 1.4.1(Jul 9, 2020)

    • Allow quick definitions to use 'at least once' expectation \Mockery::getConfiguration()->getQuickDefinitions()->shouldBeCalledAtLeastOnce(true) (#1056)
    • Added provisional support for PHP 8.0 (#1068, #1072,#1079)
    • Fix mocking methods with iterable return type without specifying a return value (#1075)
    Source code(tar.gz)
    Source code(zip)
  • 1.3.2(Jul 9, 2020)

    • Fix mocking with anonymous classes (#1039)
    • Fix andAnyOthers() to properly match earlier expectations (#1051)
    • Added provisional support for PHP 8.0 (#1068, #1072,#1079)
    • Fix mocking methods with iterable return type without specifying a return value (#1075)
    Source code(tar.gz)
    Source code(zip)
  • 1.4.0(May 19, 2020)

  • 1.3.1(Dec 26, 2019)

  • 1.3.0(Nov 24, 2019)

    • Added capture Mockery::capture convenience matcher (#1020)
    • Added andReturnArg to echo back an argument passed to a an expectation (#992)
    • Improved exception debugging (#1000)
    • Fixed andSet to not reuse properties between mock objects (#1012)
    Source code(tar.gz)
    Source code(zip)
  • 1.2.4(Sep 30, 2019)

  • 1.2.3(Aug 7, 2019)

    • Allow mocking classes that have allows and expects methods (#868)
    • Allow passing thru __call method in all mock types (experimental) (#969)
    • Add support for ! to blacklist methods (#959)
    • Added withSomeOfArgs to partial match a list of args (#967)
    • Fix chained demeter calls with type hint (#956)
    Source code(tar.gz)
    Source code(zip)
  • 1.2.2(Feb 13, 2019)

  • 0.9.11(Feb 12, 2019)

  • 1.2.1(Feb 8, 2019)

  • 1.2.0(Oct 2, 2018)

    • Starts counting default expectations towards count (#910)
    • Adds workaround for some HHVM return types (#909)
    • Adds PhpStorm metadata support for autocomplete etc (#904)
    • Further attempts to support multiple PHPUnit versions (#903)
    • Allows setting constructor expectations on instance mocks (#900)
    • Adds workaround for HHVM memoization decorator (#893)
    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(May 8, 2018)

    • Allows use of string method names in allows and expects (#794)
    • Finalises allows and expects syntax in API (#799)
    • Search for handlers in a case instensitive way (#801)
    • Deprecate allowMockingMethodsUnnecessarily (#808)
    • Fix risky tests (#769)
    • Fix namespace in TestListener (#812)
    • Fixed conflicting mock names (#813)
    • Clean elses (#819)
    • Updated protected method mocking exception message (#826)
    • Map of constants to mock (#829)
    • Simplify foreach with in_array function (#830)
    • Typehinted return value on Expectation#verify. (#832)
    • Fix shouldNotHaveReceived with HigherOrderMessage (#842)
    • Deprecates shouldDeferMissing (#839)
    • Adds support for return type hints in Demeter chains (#848)
    • Adds shouldNotReceive to composite expectation (#847)
    • Fix internal error when using --static-backup (#845)
    • Adds andAnyOtherArgs as an optional argument matcher (#860)
    • Fixes namespace qualifying with namespaced named mocks (#872)
    Source code(tar.gz)
    Source code(zip)
  • 1.0(Oct 6, 2017)

    About time we had a 1.0.

    Change Log

    • Destructors (__destruct) are stubbed out where it makes sense
    • Allow passing a closure argument to withArgs() to validate multiple arguments at once.
    • Mockery\Adapter\Phpunit\TestListener has been rewritten because it incorrectly marked some tests as risky. It will no longer verify mock expectations but instead check that tests do that themselves. PHPUnit 6 is required if you want to use this fail safe.
    • Removes SPL Class Loader
    • Removed object recorder feature
    • Bumped minimum PHP version to 5.6
    • andThrow will now throw anything \Throwable
    • Adds allows and expects syntax
    • Adds optional global helpers for mock, namedMock and spy
    • Adds ability to create objects using traits
    • Mockery\Matcher\MustBe was deprecated
    • Marked Mockery\MockInterface as internal
    • Subset matcher matches recusively
    • BC BREAK - Spies return null by default from ignored (non-mocked) methods with nullable return type
    • Removed extracting getter methods of object instances
    • BC BREAK - Remove implicit regex matching when trying to match string arguments, introduce \Mockery::pattern() when regex matching is needed
    • Fix Mockery not getting closed in cases of failing test cases
    • Fix Mockery not setting properties on overloaded instance mocks
    • BC BREAK - Fix Mockery not trying default expectations if there is any concrete expectation
    • BC BREAK - Mockery's PHPUnit integration will mark a test as risky if it thinks one it's exceptions has been swallowed in PHPUnit > 5.7.6. Use $e->dismiss() to dismiss.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-alpha1(Feb 6, 2017)

  • 0.9.5(May 22, 2016)

Owner
Mockery
Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework.
Mockery
Mock implementation of the Translation package, for testing with PHPUnit

PoP Translation - Mock Mock implementation of the Translation package, for testing with PHPUnit Install Via Composer composer require getpop/translati

PoP 1 Jan 13, 2022
Mock HTTP requests on the server side in your PHP unit tests

HTTP Mock for PHP Mock HTTP requests on the server side in your PHP unit tests. HTTP Mock for PHP mocks the server side of an HTTP request to allow in

InterNations GmbH 387 Jan 17, 2022
Very simple mock HTTP Server for testing Restful API, running via Docker.

httpdock Very simple mock HTTP Server for testing Restful API, running via Docker. Start Server Starting this server via command: docker run -ti -d -p

Vo Duy Tuan 4 Dec 24, 2021
Provides generic data providers for use with phpunit/phpunit.

data-provider Installation Run composer require --dev ergebnis/data-provider Usage This package provides the following generic data providers: Ergebni

null 16 Jan 10, 2022
The modern, simple and intuitive PHP unit testing framework.

atoum PHP version atoum version 5.3 -> 5.6 1.x -> 3.x 7.2 -> 8.x 4.x (current) A simple, modern and intuitive unit testing framework for PHP! Just lik

atoum 1.4k Jan 17, 2022
A sample RESTful API in Laravel with PHPunit test.

Laravel PHP Framework URL | URI | Action |

Fasil 9 Jul 11, 2020
PHP unit testing framework with built in mocks and stubs. Runs in the browser, or via the command line.

Enhance PHP A unit testing framework with mocks and stubs. Built for PHP, in PHP! Quick Start: Just add EnhanceTestFramework.php and you are ready to

Enhance PHP 67 Jul 16, 2021
The most powerful and flexible mocking framework for PHPUnit / Codeception.

AspectMock AspectMock is not an ordinary PHP mocking framework. With the power of Aspect Oriented programming and the awesome Go-AOP library, AspectMo

Codeception Testing Framework 760 Jan 16, 2022
Qase-phpunit - Qase TMS PHPUnit reporter.

Qase TMS PHPUnit reporter Publish results simple and easy. How to integrate composer require qase/phpunit-reporter Example of usage The PHPUnit report

Qase TMS 3 Jan 10, 2022
The PHP Unit Testing framework.

PHPUnit PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. Installat

Sebastian Bergmann 18.2k Jan 19, 2022
Magic Test allows you to write browser tests by simply clicking around on the application being tested, all without the slowness of constantly restarting the testing environment.

Magic Test for Laravel Magic Test allows you to write browser tests by simply clicking around on the application being tested, all without the slownes

null 369 Jan 16, 2022
Unit testing tips by examples in PHP

Unit testing tips by examples in PHP Introduction In these times, the benefits of writing unit tests are huge. I think that most of the recently start

Kamil Ruczyński 629 Jan 7, 2022
Real-world Project to learning about Unit Testing/TDD with Laravel for everybody

KivaNote - a Laravel TDD Sample Project Let me introduce you to KivaNote, a simple real-world application using Laravel to show you how the TDD & Unit

(Seth) Phat Tran 4 Oct 31, 2021
Package for unit testing Laravel form request classes

Package for unit testing Laravel form request classes. Why Colin DeCarlo gave a talk on Laracon online 21 about unit testing Laravel form requests cla

null 15 Nov 4, 2021
PHPUnit Application Architecture Test

PHPUnit Application Architecture Test Idea: write architecture tests as well as feature and unit tests Installation Install via composer composer requ

null 9 Nov 29, 2021
To run time/IO related unit tests (e.g., sleep function calls, database queries, API calls, etc) faster using Swoole.

To run time/IO related unit tests (e.g., sleep function calls, database queries, API calls, etc) faster using Swoole.

Demin Yin 9 Oct 5, 2021
PHP libraries that makes Selenium WebDriver + PHPUnit functional testing easy and robust

Steward: easy and robust testing with Selenium WebDriver + PHPUnit Steward is a set of libraries made to simplify writing and running robust functiona

LMC s.r.o. 218 Dec 12, 2021
:computer: Parallel testing for PHPUnit

ParaTest The objective of ParaTest is to support parallel testing in PHPUnit. Provided you have well-written PHPUnit tests, you can drop paratest in y

null 1.9k Jan 18, 2022
PHPUnit extension for database interaction testing.

This extension is no longer maintained DbUnit PHPUnit extension for database interaction testing. Installation Composer If you use Composer to manage

Sebastian Bergmann 224 Dec 16, 2021