14 best PHP Mock libraries in 2024

share link

by marketing.admin@openweaver.com dot icon Updated: Mar 12, 2023

technology logo
technology logo

Guide Kit Guide Kit  

Unit testing allows the programmer to refactor code or upgrade system libraries at a later date, and make sure the module still works correctly (e.g., in regression testing). The procedure is a critical element of extreme programming, which relies on frequent releases in short development cycles and emphasizes comprehensive unit testing to ensure application stability. Mock objects can be used as a replacement for real objects in unit testing, they often also record how they were used so that you can make assertions about this after the test has finished. Let's see the 14 best PHP Mock libraries in 2022, mockery - simple yet flexible PHP mock object framework; prophecy - Highly opinionated mocking framework for PHP 5.3; phpunit-mock-objects Mock Object library for PHPUnit.

mockeryby mockery

PHP doticonstar image 10406 doticonVersion:1.5.1doticon
License: Others (Non-SPDX)

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).

Support
    Quality
      Security
        License
          Reuse

            mockeryby mockery

            PHP doticon star image 10406 doticonVersion:1.5.1doticon License: Others (Non-SPDX)

            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).
            Support
              Quality
                Security
                  License
                    Reuse

                      prophecyby phpspec

                      PHP doticonstar image 8544 doticonVersion:v1.17.0doticon
                      License: Permissive (MIT)

                      Highly opinionated mocking framework for PHP 5.3+

                      Support
                        Quality
                          Security
                            License
                              Reuse

                                prophecyby phpspec

                                PHP doticon star image 8544 doticonVersion:v1.17.0doticon License: Permissive (MIT)

                                Highly opinionated mocking framework for PHP 5.3+
                                Support
                                  Quality
                                    Security
                                      License
                                        Reuse

                                          phpunit-mock-objectsby sebastianbergmann

                                          PHP doticonstar image 5027 doticonVersion:1.2.3doticon
                                          License: Others (Non-SPDX)

                                          Mock Object library for PHPUnit

                                          Support
                                            Quality
                                              Security
                                                License
                                                  Reuse

                                                    phpunit-mock-objectsby sebastianbergmann

                                                    PHP doticon star image 5027 doticonVersion:1.2.3doticon License: Others (Non-SPDX)

                                                    Mock Object library for PHPUnit
                                                    Support
                                                      Quality
                                                        Security
                                                          License
                                                            Reuse

                                                              vfsStreamby bovigo

                                                              PHP doticonstar image 1364 doticonVersion:v1.6.11doticon
                                                              License: Permissive (BSD-3-Clause)

                                                              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.

                                                              Support
                                                                Quality
                                                                  Security
                                                                    License
                                                                      Reuse

                                                                        vfsStreamby bovigo

                                                                        PHP doticon star image 1364 doticonVersion:v1.6.11doticon License: Permissive (BSD-3-Clause)

                                                                        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.
                                                                        Support
                                                                          Quality
                                                                            Security
                                                                              License
                                                                                Reuse

                                                                                  AspectMockby Codeception

                                                                                  PHP doticonstar image 758 doticonVersion:4.1.1doticon
                                                                                  License: Permissive (MIT)

                                                                                  The most powerful and flexible mocking framework for PHPUnit / Codeception.

                                                                                  Support
                                                                                    Quality
                                                                                      Security
                                                                                        License
                                                                                          Reuse

                                                                                            AspectMockby Codeception

                                                                                            PHP doticon star image 758 doticonVersion:4.1.1doticon License: Permissive (MIT)

                                                                                            The most powerful and flexible mocking framework for PHPUnit / Codeception.
                                                                                            Support
                                                                                              Quality
                                                                                                Security
                                                                                                  License
                                                                                                    Reuse

                                                                                                      wp_mockby 10up

                                                                                                      PHP doticonstar image 601 doticonVersion:0.5.0doticon
                                                                                                      License: Others (Non-SPDX)

                                                                                                      WordPress API Mocking Framework

                                                                                                      Support
                                                                                                        Quality
                                                                                                          Security
                                                                                                            License
                                                                                                              Reuse

                                                                                                                wp_mockby 10up

                                                                                                                PHP doticon star image 601 doticonVersion:0.5.0doticon License: Others (Non-SPDX)

                                                                                                                WordPress API Mocking Framework
                                                                                                                Support
                                                                                                                  Quality
                                                                                                                    Security
                                                                                                                      License
                                                                                                                        Reuse

                                                                                                                          phakeby phake

                                                                                                                          PHP doticonstar image 472 doticonVersion:v4.4.0doticon
                                                                                                                          License: Others (Non-SPDX)

                                                                                                                          PHP Mocking Framework

                                                                                                                          Support
                                                                                                                            Quality
                                                                                                                              Security
                                                                                                                                License
                                                                                                                                  Reuse

                                                                                                                                    phakeby phake

                                                                                                                                    PHP doticon star image 472 doticonVersion:v4.4.0doticon License: Others (Non-SPDX)

                                                                                                                                    PHP Mocking Framework
                                                                                                                                    Support
                                                                                                                                      Quality
                                                                                                                                        Security
                                                                                                                                          License
                                                                                                                                            Reuse

                                                                                                                                              Phakeby mlively

                                                                                                                                              PHP doticonstar image 456 doticonVersion:v4.0.0doticon
                                                                                                                                              License: Others (Non-SPDX)

                                                                                                                                              PHP Mocking Framework

                                                                                                                                              Support
                                                                                                                                                Quality
                                                                                                                                                  Security
                                                                                                                                                    License
                                                                                                                                                      Reuse

                                                                                                                                                        Phakeby mlively

                                                                                                                                                        PHP doticon star image 456 doticonVersion:v4.0.0doticon License: Others (Non-SPDX)

                                                                                                                                                        PHP Mocking Framework
                                                                                                                                                        Support
                                                                                                                                                          Quality
                                                                                                                                                            Security
                                                                                                                                                              License
                                                                                                                                                                Reuse

                                                                                                                                                                  http-mockby InterNations

                                                                                                                                                                  PHP doticonstar image 387 doticonVersion:Currentdoticon
                                                                                                                                                                  License: Permissive (MIT)

                                                                                                                                                                  Mock HTTP requests on the server side in your PHP unit tests

                                                                                                                                                                  Support
                                                                                                                                                                    Quality
                                                                                                                                                                      Security
                                                                                                                                                                        License
                                                                                                                                                                          Reuse

                                                                                                                                                                            http-mockby InterNations

                                                                                                                                                                            PHP doticon star image 387 doticonVersion:Currentdoticon License: Permissive (MIT)

                                                                                                                                                                            Mock HTTP requests on the server side in your PHP unit tests
                                                                                                                                                                            Support
                                                                                                                                                                              Quality
                                                                                                                                                                                Security
                                                                                                                                                                                  License
                                                                                                                                                                                    Reuse

                                                                                                                                                                                      soft-mocksby badoo

                                                                                                                                                                                      PHP doticonstar image 302 doticonVersion:3.1.1doticon
                                                                                                                                                                                      License: Permissive (MIT)

                                                                                                                                                                                      PHP mocks engine that allows to redefine functions and user methods on-the-fly (provides similar functionality to runkit and uopz extensions)

                                                                                                                                                                                      Support
                                                                                                                                                                                        Quality
                                                                                                                                                                                          Security
                                                                                                                                                                                            License
                                                                                                                                                                                              Reuse

                                                                                                                                                                                                soft-mocksby badoo

                                                                                                                                                                                                PHP doticon star image 302 doticonVersion:3.1.1doticon License: Permissive (MIT)

                                                                                                                                                                                                PHP mocks engine that allows to redefine functions and user methods on-the-fly (provides similar functionality to runkit and uopz extensions)
                                                                                                                                                                                                Support
                                                                                                                                                                                                  Quality
                                                                                                                                                                                                    Security
                                                                                                                                                                                                      License
                                                                                                                                                                                                        Reuse

                                                                                                                                                                                                          Stubby Codeception

                                                                                                                                                                                                          PHP doticonstar image 277 doticonVersion:4.0.2doticon
                                                                                                                                                                                                          License: Permissive (MIT)

                                                                                                                                                                                                          Flexible Stub wrapper for PHPUnit's Mock Builder

                                                                                                                                                                                                          Support
                                                                                                                                                                                                            Quality
                                                                                                                                                                                                              Security
                                                                                                                                                                                                                License
                                                                                                                                                                                                                  Reuse

                                                                                                                                                                                                                    Stubby Codeception

                                                                                                                                                                                                                    PHP doticon star image 277 doticonVersion:4.0.2doticon License: Permissive (MIT)

                                                                                                                                                                                                                    Flexible Stub wrapper for PHPUnit's Mock Builder
                                                                                                                                                                                                                    Support
                                                                                                                                                                                                                      Quality
                                                                                                                                                                                                                        Security
                                                                                                                                                                                                                          License
                                                                                                                                                                                                                            Reuse

                                                                                                                                                                                                                              BrainMonkeyby Brain-WP

                                                                                                                                                                                                                              PHP doticonstar image 267 doticonVersion:2.6.1doticon
                                                                                                                                                                                                                              License: Permissive (MIT)

                                                                                                                                                                                                                              Mocking utility for PHP functions and WordPress plugin API

                                                                                                                                                                                                                              Support
                                                                                                                                                                                                                                Quality
                                                                                                                                                                                                                                  Security
                                                                                                                                                                                                                                    License
                                                                                                                                                                                                                                      Reuse

                                                                                                                                                                                                                                        BrainMonkeyby Brain-WP

                                                                                                                                                                                                                                        PHP doticon star image 267 doticonVersion:2.6.1doticon License: Permissive (MIT)

                                                                                                                                                                                                                                        Mocking utility for PHP functions and WordPress plugin API
                                                                                                                                                                                                                                        Support
                                                                                                                                                                                                                                          Quality
                                                                                                                                                                                                                                            Security
                                                                                                                                                                                                                                              License
                                                                                                                                                                                                                                                Reuse

                                                                                                                                                                                                                                                  php-mock-phpunitby php-mock

                                                                                                                                                                                                                                                  PHP doticonstar image 147 doticonVersion:2.7.1doticon
                                                                                                                                                                                                                                                  License: Permissive (WTFPL)

                                                                                                                                                                                                                                                  Mock built-in PHP functions (e.g. time() or rand()) in PHPUnit.

                                                                                                                                                                                                                                                  Support
                                                                                                                                                                                                                                                    Quality
                                                                                                                                                                                                                                                      Security
                                                                                                                                                                                                                                                        License
                                                                                                                                                                                                                                                          Reuse

                                                                                                                                                                                                                                                            php-mock-phpunitby php-mock

                                                                                                                                                                                                                                                            PHP doticon star image 147 doticonVersion:2.7.1doticon License: Permissive (WTFPL)

                                                                                                                                                                                                                                                            Mock built-in PHP functions (e.g. time() or rand()) in PHPUnit.
                                                                                                                                                                                                                                                            Support
                                                                                                                                                                                                                                                              Quality
                                                                                                                                                                                                                                                                Security
                                                                                                                                                                                                                                                                  License
                                                                                                                                                                                                                                                                    Reuse
                                                                                                                                                                                                                                                                      PHP doticonstar image 115 doticonVersion:v2.6.1doticon
                                                                                                                                                                                                                                                                      License: Permissive (MIT)

                                                                                                                                                                                                                                                                      Simple mock web server in PHP for unit testing.

                                                                                                                                                                                                                                                                      Support
                                                                                                                                                                                                                                                                        Quality
                                                                                                                                                                                                                                                                          Security
                                                                                                                                                                                                                                                                            License
                                                                                                                                                                                                                                                                              Reuse

                                                                                                                                                                                                                                                                                mock-webserverby donatj

                                                                                                                                                                                                                                                                                PHP doticon star image 115 doticonVersion:v2.6.1doticon License: Permissive (MIT)

                                                                                                                                                                                                                                                                                Simple mock web server in PHP for unit testing.
                                                                                                                                                                                                                                                                                Support
                                                                                                                                                                                                                                                                                  Quality
                                                                                                                                                                                                                                                                                    Security
                                                                                                                                                                                                                                                                                      License
                                                                                                                                                                                                                                                                                        Reuse

                                                                                                                                                                                                                                                                                          See similar Kits and Libraries