Mockery - Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library

Overview

Mockery

Build Status Latest Stable Version 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:

[new Book(), new Book()], ]);">
$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:

[new Book(), new Book()], ]);">
$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.

Comments
  • 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 `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
  • 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
  • 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
  • Change parameter type integer to int

    Change parameter type integer to int

    Change parameter type integer to int to fix php 7 type definition.

    Example: This code:

    class php7
    
    public function getId(int $id)
    {
    }
    

    Generate:

    class php7
    
    public function getId(integer $id)
    {
    }
    

    But is don't work because php don't recognize it code.

    With replace genarete:

    class php7
    
    public function getId(int $id)
    {
    }
    
    opened by emtudo 23
  • Change dependency to correct Hamcrest GitHub repo

    Change dependency to correct Hamcrest GitHub repo

    Together with @cordoval and @davedevelopment we've updated @cordoval version of Hamcrest-php library on GitHub (to 1.1.0) and published it on Composer as well.

    Then fork of @davedevelopment (based on 1.0.0) would be deleted and your tests would break. To prevent that I've changed a dependency to correct Composer package.

    I've also made tests use Hamcrest from Composer, rather one from PEAR. I've checked, that all tests pass (some were skipped) after the changes.

    opened by aik099 23
  • [Question] Mocks already loaded in coverage phpunit task.

    [Question] Mocks already loaded in coverage phpunit task.

    I have a problem that I don't know if it's a problem or it's normal.

    I have a PHP class with static methods that I want to mock with Mockery to check that the code executed when an exception is thrown works.

    The test works fine and does what I ask of it (The code tests the handling of an exception). ✔ Should throw exception [90.20 ms]

    But when I want to pass the coverage with phpunit this happens:

    Generating code coverage report in HTML format ...
    Script phpunit --testdox --configuration ../phpunit.xml ../tests handling the test:coverage event returned with error code 255
    Fatal error: Cannot declare class BackBase\Tools\Email\EmailManager, because the name is already in use in
    

    I have seen in a thousand places that if I add

          * @runInSeparateProcess
          * @preserveGlobalState disable
    

    in my test, everything is fixed.

    But the times that each test takes increase a lot. ✔ Should throw exception [3331.97 ms]

    I have many tests of this style and the test time increases exponentially.

    Does this have a solution? I am doing something wrong? If more information is needed, ask me.

    Thank you!

    opened by ciltocruz 4
  • Failed to mock method for the Proxied partial

    Failed to mock method for the Proxied partial

    final class Foo
    {
        public function foo() {
            return 123;
        }
    
        public function bar() {
            return $this->foo();
        }
    }
    
    // Tests
    public function testFoo()
    {
        $foo = new Foo();
        $mock = \Mockery::mock($foo);
        $mock->shouldReceive('foo')->andReturn(456);
        self::assertSame(456,$mock->bar());
    }
    

    I got an error message Failed asserting that 123 is identical to 456.

    version

    • php: 8.1
    • phpunit: 9.5.26
    • mockery: 1.5.1
    opened by yankewei 0
  • Unexpected behaviour with instance mocks/overload

    Unexpected behaviour with instance mocks/overload

    The Mockery docs about overloading mention:

    Using alias/instance mocks across more than one test will generate a fatal error since we can’t have two classes of the same name. To avoid this, run each test of this kind in a separate PHP process (which is supported out of the box by both PHPUnit and PHPT).

    Instead of a fatal error, I see some odd behaviour that could either be a bug or something that should be documented:

    I can overload the same class multiple times in the same PHP process. When I overload a class twice in the same test (which I did to find the limits of creating instance mocks), I found that only the expectations of the first overload are taken into account. Any assertions on a second overload of the same class are ignored without warning.

    Here's the code that I used: https://github.com/jrfnl/bug-report-reproduction-scenarios/tree/mockery/overload-implementation-question

    Am I interpreting the docs incorrectly? When should I expect a fatal error when creating instance mocks?

    opened by diedexx 0
  • Function with enum argument causes error

    Function with enum argument causes error

    Calling the function on the mock results in an unexpected Undefined Constant error.

    enum SimpleEnum {
        case single;
    }
    class EnumTest {
        public function call(SimpleEnum $enum = SimpleEnum::single) {
            echo $enum->name;
        }
    }
    
    $mock = Mockery::mock('EnumTest');
    $mock->shouldReceive('call')->once();
    $log = $mock->call();
    
       Error 
    
      Undefined constant "SimpleEnum"
    
      at vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php:34
         30▕         if (class_exists($definition->getClassName(), false)) {
         31▕             return;
         32▕         }
         33▕ 
      ➜  34▕         eval("?>" . $definition->getCode());
         35▕     }
         36▕ }
         37▕ 
    
      1   test.php:29
          Mockery_0_EnumTest::call()
    

    Calling normally works as expected.

    (new EnumTest())->call();
    
    single
    
    opened by murrant 1
  • Requesting recipes on how to deal with setting properties on Mocks with PHP 8.2+

    Requesting recipes on how to deal with setting properties on Mocks with PHP 8.2+

    PHP 8.2 deprecated the use of dynamic properties. This impacts the use of Mockery when using anonymous mocks or mocks for classes which are not available.

    The remaining 11 test failures for Mockery itself on PHP 8.2 are all related to this.

    I'll be the first to admit I'm no Mockery expert, so I've been experimenting with how to work round the deprecation and so far I've not had much luck finding elegant solutions.

    Now of course, one shouldn't mock what you do not own, but there are test situations where certain external dependencies (framework) may not be available during testing, so there's not much which can done about that.

    Findings so far:

    • Making the mock extend stdClass doesn't seem to work as this seems to run into trouble when the method under test has a class based parameter type declaration.
    • Using Mockery::namedMock() and having the named mock extend stdClass, works for the first test case, but that's it. (also noted as such in the documentation). Re-using the mock object isn't really an option as the object won't be "clean" anymore if properties are being assigned from the tests.
    • Along the same lines, using alias: mocks would require most tests to run in a separate process, which makes the test suite a lot slower as well as less stable.

    Suggestions and "recipes" to solve this very welcome!

    opened by jrfnl 1
Releases(1.5.1)
  • 1.5.1(Sep 7, 2022)

    [PHP 8.2] Various tests: explicitly declare properties #1170 [PHP 8.2] Fix "Use of "parent" in callables is deprecated" notice #1169 [PHP 8.1] Support intersection types #1164 Handle final __toString methods #1162

    Source code(tar.gz)
    Source code(zip)
  • 1.3.6(Sep 7, 2022)

  • 1.5.0(Jan 20, 2022)

    • Override default call count expectations via expects() #1146
    • Mock methods with static return types #1157
    • Mock methods with mixed return type #1156
    • Mock classes with new in initializers on PHP 8.1 #1160
    • Removes redundant PHPUnitConstraint #1158
    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.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.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.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.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.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
vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with any unit test framework, like PHPUnit or SimpleTest.

vfsStream vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with

null 1.4k Dec 23, 2022
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
SimpleTest is a framework for unit testing, web site testing and mock objects for PHP

SimpleTest SimpleTest is a framework for unit testing, web site testing and mock objects for PHP. Installation Downloads All downloads are stored on G

SimpleTest 147 Jun 20, 2022
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 25 Jan 2, 2023
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 6 Nov 24, 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 386 Dec 27, 2022
Mock built-in PHP functions (e.g. time(), exec() or rand())

PHP-Mock: mocking built-in PHP functions PHP-Mock is a testing library which mocks non deterministic built-in PHP functions like time() or rand(). Thi

null 331 Jan 3, 2023
A simple way to mock a client

Mocked Client A simple way to mock a client Install Via Composer $ composer require doppiogancio/mocked-client guzzlehttp/guzzle php-http/discovery No

Fabrizio Gargiulo 17 Oct 5, 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
A drop in fake logger for testing with the Laravel framework.

Log fake for Laravel A bunch of Laravel facades / services are able to be faked, such as the Dispatcher with Bus::fake(), to help with testing and ass

Tim MacDonald 363 Dec 19, 2022
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 777 Dec 12, 2022
: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 2k Dec 31, 2022
Rector upgrades rules for PHPUnit

Rector Rules for PHPUnit See available PHPUnit rules Install composer require rector/rector-phpunit Use Sets To add a set to your config, use Rector\P

RectorPHP 34 Dec 27, 2022
Add mocking capabilities to Pest or PHPUnit

This repository contains the Pest Plugin Mock. The Mocking API can be used in regular PHPUnit projects. For that, you just have to run the following c

PEST 16 Dec 3, 2022
A sample RESTful API in Laravel with PHPunit test.

Laravel PHP Framework URL | URI | Action |

Fasil 9 Jul 11, 2020
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 19 Dec 11, 2022
PHPUnit to Pest Converter

PestConverter PestConverter is a PHP library for converting PHPUnit tests to Pest tests. Before use Before using this converter, make sure your files

null 10 Nov 21, 2022
Allows the running of PHPUnit within ExpressionEngine

EE Unit Tests EE Unit Tests is an Add-on for ExpressionEngine that allows developers to execute unit tests from the Command Line. EE Unit Tests uses P

Eric Lamb 6 Jan 14, 2022
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. 219 Dec 17, 2022