Download the PHP package box/shmock without Composer
On this page you can find all versions of the php package box/shmock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package shmock
Short Description Shorthand for (PHPUnit) Mocking
License Apache 2.0
Homepage http://github.com/box/shmock
Informations about the package shmock
Shmock (SHorthand for MOCKing)
What is this?
Shmock is a smooth alternative for creating mocks with PHPUnit that uses the mock/replay concept from EasyMock but uses closures to define the scope for mocking.
Installation
Shmock can be installed directly from Packagist.
Alternatively you can download Shmock.php and Shmockers.php into your test directory and run
PHPUnit should already be on the load path for this to work.
Type Safety
Shmock is typesafe by default and will attempt to tell you when you're using the wrong mocking approach. Shmock will throw errors in cases where:
- You mock a static method as though it were an instance method or vice versa.
- You mock a private method as though it were protected or public.
- You mock a method that does not exist and there is no call / callStatic magic method provided.
These checks can be disabled by calling $mock_object->disable_strict_method_checking()
inside the shmock closure. We also plan on supporting parameter and return value checking if it complies with yet-to-be-defined PHPDoc conventions.
Documentation:
http://box.github.io/shmock/namespaces/Shmock.html
Full list of Shmock features:
- Shmock lets you configure a mock object inside a closure. You work with a proxy object that feels like the real thing.
- Invoking a method sets up the expectation that it will be called once.
- Invoking a method with arguments causes it to expect those arguments when actually invoked.
- You can return values from specific invocations. In the example, the value 100 will be returned when you call the method.
- You can specify an expectation for the number of times a method will be called. By default it's expected once.
- Or you can specify "0 or more" times with any()
- You can nest your Shmock invocations, letting you define your mock dependencies elegantly. (If you have a two-way dependency, you can always just
return_value($other_shmock)
and define it somewhere else ) - On an object-level you can specify "order matters", meaning that the ordering of function invocations should be asserted against as well. Under the hood, this uses PHPUnit's
at(N)
calls automatically - You have some options as far as defining constructor arguments. a) You can opt to disable the original constructor. Normally PHPUnit will run the original constructor. b) You can run the original constructor with the given arguments.
- Instead of returning a value, you can throw an exception when a method gets called.
- Even more sophisticated, you can execute an arbitrary closure when the function gets called.
- If you want to mock static functions, you call
shmock_class
which will give you all the same Shmock semantics as instances (where it makes sense). This is particularly useful when you want to partially mock an object, keeping some of the original behavior, but mocking out static / protected methods that may exist that the method you are testing is dependent on. - You can also mock a class independently of a mock instance.
Copyright and License
Copyright 2014 Box, Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
All versions of shmock with dependencies
phpunit/phpunit Version >=3.7
nicmart/string-template Version 0.1.0
sebastian/diff Version >=1.1