You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
Of these, PHPUnit has had built-in support for stubs and mocks for quite some time.
The stubs and mocks generated by PHPUnit(_MockObject) can be used in every context where an object of the original class is expected. As it should be, the code of the original class is not executed when a method is called on the stub or mock.
Motivation for Test Proxies
When writing integration tests in general and edge-to-edge tests in particular, you generally do not want to stub or mock dependencies. Sometimes, though, the ability to have expectations such as "this method has to be called with these arguments for this test to be successful" would also be useful in tests that have a larger scope than unit tests.
The idea is to have a "Test Proxy" object that provides the same API for expectations as a mock object while at the same time proxying method calls to the original class.
Background
Thanks to Gerard Meszaros, we have the following (names for) categories of test doubles:
Of these, PHPUnit has had built-in support for stubs and mocks for quite some time.
The stubs and mocks generated by PHPUnit(_MockObject) can be used in every context where an object of the original class is expected. As it should be, the code of the original class is not executed when a method is called on the stub or mock.
Motivation for Test Proxies
When writing integration tests in general and edge-to-edge tests in particular, you generally do not want to stub or mock dependencies. Sometimes, though, the ability to have expectations such as "this method has to be called with these arguments for this test to be successful" would also be useful in tests that have a larger scope than unit tests.
The idea is to have a "Test Proxy" object that provides the same API for expectations as a mock object while at the same time proxying method calls to the original class.
Usage Example
Foo.php
Bar.php
FooTest.php
The text was updated successfully, but these errors were encountered: