[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8172":3},{"id":4,"name":5,"fullName":6,"owner":5,"repo":5,"description":7,"homepage":8,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":16,"stars30d":17,"stars90d":15,"forks30d":15,"starsTrendScore":16,"compositeScore":18,"rankGlobal":9,"rankLanguage":9,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":20,"hasPages":22,"topics":23,"createdAt":9,"pushedAt":9,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":15,"starSnapshotCount":15,"syncStatus":33,"lastSyncTime":34,"discoverSource":35},8172,"mockery","mockery\u002Fmockery","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).","http:\u002F\u002Fdocs.mockery.io\u002Fen\u002Fstable\u002F",null,"PHP",10723,465,72,105,0,1,4,68.91,"BSD 3-Clause \"New\" or \"Revised\" License",false,"1.6.x",true,[24,5,25,26,27,28,29],"mock","mocking","php","phpunit","stub","test-doubles","2026-06-12 04:00:37","Mockery\n=======\n\n[![Build Status](https:\u002F\u002Fgithub.com\u002Fmockery\u002Fmockery\u002Factions\u002Fworkflows\u002Ftests.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fmockery\u002Fmockery\u002Factions)\n[![Supported PHP Version](https:\u002F\u002Fbadgen.net\u002Fpackagist\u002Fphp\u002Fmockery\u002Fmockery?color=8892bf)](https:\u002F\u002Fwww.php.net\u002Fsupported-versions)\n[![Code Coverage](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fmockery\u002Fmockery\u002Fbranch\u002F1.6.x\u002Fgraph\u002Fbadge.svg?token=oxHwVM56bT)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fmockery\u002Fmockery)\n[![Type Coverage](https:\u002F\u002Fshepherd.dev\u002Fgithub\u002Fmockery\u002Fmockery\u002Fcoverage.svg)](https:\u002F\u002Fshepherd.dev\u002Fgithub\u002Fmockery\u002Fmockery)\n[![Latest Stable Version](https:\u002F\u002Fposer.pugx.org\u002Fmockery\u002Fmockery\u002Fv\u002Fstable.svg)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fmockery\u002Fmockery)\n[![Total Downloads](https:\u002F\u002Fposer.pugx.org\u002Fmockery\u002Fmockery\u002Fdownloads.svg)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fmockery\u002Fmockery)\n\nMockery is a simple yet flexible PHP mock object framework for use in unit testing\nwith PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a\ntest double framework with a succinct API capable of clearly defining all possible\nobject operations and interactions using a human readable Domain Specific Language\n(DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library,\nMockery is easy to integrate with PHPUnit and can operate alongside\nphpunit-mock-objects without the World ending.\n\nMockery is released under a New BSD License.\n\n## Installation\n\nTo install Mockery, run the command below and you will get the latest\nversion\n\n```sh\ncomposer require --dev mockery\u002Fmockery\n```\n\n## Documentation\n\nIn older versions, this README file was the documentation for Mockery. Over time\nwe have improved this, and have created an extensive documentation for you. Please\nuse this README file as a starting point for Mockery, but do read the documentation\nto learn how to use Mockery.\n\nThe current version can be seen at [docs.mockery.io](http:\u002F\u002Fdocs.mockery.io).\n\n## PHPUnit Integration\n\nMockery ships with some helpers if you are using PHPUnit. You can extend the\n[`Mockery\\Adapter\\Phpunit\\MockeryTestCase`](library\u002FMockery\u002FAdapter\u002FPhpunit\u002FMockeryTestCase.php)\nclass instead of `PHPUnit\\Framework\\TestCase`, or if you are already using a\ncustom base class for your tests, take a look at the traits available in the\n[`Mockery\\Adapter\\Phpunit`](library\u002FMockery\u002FAdapter\u002FPhpunit) namespace.\n\n## Test Doubles\n\nTest doubles (often called mocks) simulate the behaviour of real objects. They are\ncommonly utilised to offer test isolation, to stand in for objects which do not\nyet exist, or to allow for the exploratory design of class APIs without\nrequiring actual implementation up front.\n\nThe benefits of a test double framework are to allow for the flexible generation\nand configuration of test doubles. They allow the setting of expected method calls\nand\u002For return values using a flexible API which is capable of capturing every\npossible real object behaviour in way that is stated as close as possible to a\nnatural language description. Use the `Mockery::mock` method to create a test\ndouble.\n\n``` php\n$double = Mockery::mock();\n```\n\nIf you need Mockery to create a test double to satisfy a particular type hint,\nyou can pass the type to the `mock` method.\n\n``` php\nclass Book {}\n\ninterface BookRepository {\n    function find($id): Book;\n    function findAll(): array;\n    function add(Book $book): void;\n}\n\n$double = Mockery::mock(BookRepository::class);\n```\n\nA detailed explanation of creating and working with test doubles is given in the\ndocumentation, [Creating test doubles](http:\u002F\u002Fdocs.mockery.io\u002Fen\u002Flatest\u002Freference\u002Fcreating_test_doubles.html)\nsection.\n\n## Method Stubs 🎫\n\nA method stub is a mechanism for having your test double return canned responses\nto certain method calls. With stubs, you don't care how many times, if at all,\nthe method is called. Stubs are used to provide indirect input to the system\nunder test.\n\n``` php\n$double->allows()->find(123)->andReturns(new Book());\n\n$book = $double->find(123);\n```\n\nIf you have used Mockery before, you might see something new in the example\nabove &mdash; we created a method stub using `allows`, instead of the \"old\"\n`shouldReceive` syntax. This is a new feature of Mockery v1, but fear not,\nthe trusty ol' `shouldReceive` is still here.\n\nFor new users of Mockery, the above example can also be written as:\n\n``` php\n$double->shouldReceive('find')->with(123)->andReturn(new Book());\n$book = $double->find(123);\n```\n\nIf your stub doesn't require specific arguments, you can also use this shortcut\nfor setting up multiple calls at once:\n\n``` php\n$double->allows([\n    \"findAll\" => [new Book(), new Book()],\n]);\n```\n\nor\n\n``` php\n$double->shouldReceive('findAll')\n    ->andReturn([new Book(), new Book()]);\n```\n\nYou can also use this shortcut, which creates a double and sets up some stubs in\none call:\n\n``` php\n$double = Mockery::mock(BookRepository::class, [\n    \"findAll\" => [new Book(), new Book()],\n]);\n```\n\n## Method Call Expectations 📲\n\nA Method call expectation is a mechanism to allow you to verify that a\nparticular method has been called. You can specify the parameters and you can\nalso specify how many times you expect it to be called. Method call expectations\nare used to verify indirect output of the system under test.\n\n``` php\n$book = new Book();\n\n$double = Mockery::mock(BookRepository::class);\n$double->expects()->add($book);\n```\n\nDuring the test, Mockery accept calls to the `add` method as prescribed.\nAfter you have finished exercising the system under test, you need to\ntell Mockery to check that the method was called as expected, using the\n`Mockery::close` method. One way to do that is to add it to your `tearDown`\nmethod in PHPUnit.\n\n``` php\n\npublic function tearDown()\n{\n    Mockery::close();\n}\n```\n\nThe `expects()` method automatically sets up an expectation that the method call\n(and matching parameters) is called **once and once only**. You can choose to change\nthis if you are expecting more calls.\n\n``` php\n$double->expects()->add($book)->twice();\n```\n\nIf you have used Mockery before, you might see something new in the example\nabove &mdash; we created a method expectation using `expects`, instead of the \"old\"\n`shouldReceive` syntax. This is a new feature of Mockery v1, but same as with\n`allows` in the previous section, it can be written in the \"old\" style.\n\nFor new users of Mockery, the above example can also be written as:\n\n``` php\n$double->shouldReceive('find')\n    ->with(123)\n    ->once()\n    ->andReturn(new Book());\n$book = $double->find(123);\n```\n\nA detailed explanation of declaring expectations on method calls, please\nread the documentation, the [Expectation declarations](http:\u002F\u002Fdocs.mockery.io\u002Fen\u002Flatest\u002Freference\u002Fexpectations.html)\nsection. After that, you can also learn about the new `allows` and `expects` methods\nin the [Alternative shouldReceive syntax](http:\u002F\u002Fdocs.mockery.io\u002Fen\u002Flatest\u002Freference\u002Falternative_should_receive_syntax.html)\nsection.\n\nIt is worth mentioning that one way of setting up expectations is no better or worse\nthan the other. Under the hood, `allows` and `expects` are doing the same thing as\n`shouldReceive`, at times in \"less words\", and as such it comes to a personal preference\nof the programmer which way to use.\n\n## Test Spies 🕵️\n\nBy default, all test doubles created with the `Mockery::mock` method will only\naccept calls that they have been configured to `allow` or `expect` (or in other words,\ncalls that they `shouldReceive`). Sometimes we don't necessarily care about all of the\ncalls that are going to be made to an object. To facilitate this, we can tell Mockery\nto ignore any calls it has not been told to expect or allow. To do so, we can tell a\ntest double `shouldIgnoreMissing`, or we can create the double using the `Mocker::spy`\nshortcut.\n\n``` php\n\u002F\u002F $double = Mockery::mock()->shouldIgnoreMissing();\n$double = Mockery::spy();\n\n$double->foo(); \u002F\u002F null\n$double->bar(); \u002F\u002F null\n```\n\nFurther to this, sometimes we want to have the object accept any call during the test execution\nand then verify the calls afterwards. For these purposes, we need our test\ndouble to act as a Spy. All mockery test doubles record the calls that are made\nto them for verification afterwards by default:\n\n``` php\n$double->baz(123);\n\n$double->shouldHaveReceived()->baz(123); \u002F\u002F null\n$double->shouldHaveReceived()->baz(12345); \u002F\u002F Uncaught Exception Mockery\\Exception\\InvalidCountException...\n```\n\nPlease refer to the [Spies](http:\u002F\u002Fdocs.mockery.io\u002Fen\u002Flatest\u002Freference\u002Fspies.html) section\nof the documentation to learn more about the spies.\n\n## Utilities 🔌\n\n### Global Helpers\n\nMockery ships with a handful of global helper methods, you just need to ask\nMockery to declare them.\n\n``` php\nMockery::globalHelpers();\n\n$mock = mock(Some::class);\n$spy = spy(Some::class);\n\n$spy->shouldHaveReceived()\n    ->foo(anyArgs());\n```\n\nAll of the global helpers are wrapped in a `!function_exists` call to avoid\nconflicts. So if you already have a global function called `spy`, Mockery will\nsilently skip the declaring its own `spy` function.\n\n### Testing Traits\n\nAs Mockery ships with code generation capabilities, it was trivial to add\nfunctionality allowing users to create objects on the fly that use particular\ntraits. Any abstract methods defined by the trait will be created and can have\nexpectations or stubs configured like normal Test Doubles.\n\n``` php\ntrait Foo {\n    function foo() {\n        return $this->doFoo();\n    }\n\n    abstract function doFoo();\n}\n\n$double = Mockery::mock(Foo::class);\n$double->allows()->doFoo()->andReturns(123);\n$double->foo(); \u002F\u002F int(123)\n```\n\n## Versioning\n\nThe Mockery team attempts to adhere to [Semantic Versioning](http:\u002F\u002Fsemver.org),\nhowever, some of Mockery's internals are considered private and will be open to\nchange at any time. Just because a class isn't final, or a method isn't marked\nprivate, does not mean it constitutes part of the API we guarantee under the\nversioning scheme.\n\n### Alternative Runtimes\n\nMockery 1.3 was the last version to support HHVM 3 and PHP 5. There is no support for HHVM 4+.\n\n## A new home for Mockery\n\n⚠️️ Update your remotes! Mockery has transferred to a new location. While it was once\nat `padraic\u002Fmockery`, it is now at `mockery\u002Fmockery`. While your\nexisting repositories will redirect transparently for any operations, take some\ntime to transition to the new URL.\n```sh\n$ git remote set-url upstream https:\u002F\u002Fgithub.com\u002Fmockery\u002Fmockery.git\n```\nReplace `upstream` with the name of the remote you use locally; `upstream` is commonly\nused but you may be using something else. Run `git remote -v` to see what you're actually\nusing.\n","Mockery 是一个简洁且灵活的 PHP 模拟对象框架，适用于与 PHPUnit、PHPSpec 或其他测试框架进行单元测试。其核心功能是通过一种易读的领域特定语言（DSL）清晰地定义所有可能的对象操作和交互，提供了一个具有简洁API的测试替身框架。Mockery 旨在作为 PHPUnit 的 phpunit-mock-objects 库的一个替代方案，易于集成到现有的测试环境中，并且可以与 phpunit-mock-objects 并行使用而不会产生冲突。它特别适合于需要模拟复杂对象行为以提高测试覆盖率和隔离性的场景中使用。",2,"2026-06-11 03:16:35","top_language"]