simple_example.rst 0000664 00000003436 15152100342 0010303 0 ustar 00 .. index::
single: Getting Started; Simple Example
Simple Example
==============
Imagine we have a ``Temperature`` class which samples the temperature of a
locale before reporting an average temperature. The data could come from a web
service or any other data source, but we do not have such a class at present.
We can, however, assume some basic interactions with such a class based on its
interaction with the ``Temperature`` class:
.. code-block:: php
class Temperature
{
public function __construct($service)
{
$this->_service = $service;
}
public function average()
{
$total = 0;
for ($i=0;$i<3;$i++) {
$total += $this->_service->readTemp();
}
return $total/3;
}
}
Even without an actual service class, we can see how we expect it to operate.
When writing a test for the ``Temperature`` class, we can now substitute a
mock object for the real service which allows us to test the behaviour of the
``Temperature`` class without actually needing a concrete service instance.
.. code-block:: php
use \Mockery as m;
class TemperatureTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
m::close();
}
public function testGetsAverageTemperatureFromThreeServiceReadings()
{
$service = m::mock('service');
$service->shouldReceive('readTemp')->times(3)->andReturn(10, 12, 14);
$temperature = new Temperature($service);
$this->assertEquals(12, $temperature->average());
}
}
.. note::
PHPUnit integration can remove the need for a ``tearDown()`` method. See
":doc:`/reference/phpunit_integration`" for more information.
installation.rst 0000664 00000004103 15152100342 0007770 0 ustar 00 .. index::
single: Installation
Installation
============
Mockery can be installed using Composer, PEAR or by cloning it from its GitHub
repository. These three options are outlined below.
Composer
--------
You can read more about Composer on `getcomposer.org <https://getcomposer.org>`_.
To install Mockery using Composer, first install Composer for your project
using the instructions on the `Composer download page <https://getcomposer.org/download/>`_.
You can then define your development dependency on Mockery using the suggested
parameters below. While every effort is made to keep the master branch stable,
you may prefer to use the current stable version tag instead (use the
``@stable`` tag).
.. code-block:: json
{
"require-dev": {
"mockery/mockery": "dev-master"
}
}
To install, you then may call:
.. code-block:: bash
php composer.phar update
This will install Mockery as a development dependency, meaning it won't be
installed when using ``php composer.phar update --no-dev`` in production.
PEAR
----
Mockery is hosted on the `survivethedeepend.com <http://pear.survivethedeepend.com>`_
PEAR channel and can be installed using the following commands:
.. code-block:: bash
sudo pear channel-discover pear.survivethedeepend.com
sudo pear channel-discover hamcrest.googlecode.com/svn/pear
sudo pear install --alldeps deepend/Mockery
Git
---
The Git repository hosts the development version in its master branch. You can
install this using Composer by referencing ``dev-master`` as your preferred
version in your project's ``composer.json`` file as the earlier example shows.
You may also install this development version using PEAR:
.. code-block:: bash
git clone git://github.com/padraic/mockery.git
cd mockery
sudo pear channel-discover hamcrest.googlecode.com/svn/pear
sudo pear install --alldeps package.xml
The above processes will install both Mockery and Hamcrest. While omitting
Hamcrest will not break Mockery, Hamcrest is recommended as it adds a wider
variety of functionality for argument matching.
index.rst 0000664 00000000210 15152100342 0006371 0 ustar 00 Getting Started
===============
.. toctree::
:hidden:
installation
upgrading
simple_example
.. include:: map.rst.inc
upgrading.rst 0000664 00000001332 15152100342 0007250 0 ustar 00 .. index::
single: Upgrading
Upgrading
=========
Upgrading to 0.9
----------------
The generator was completely rewritten, so any code with a deep integration to
mockery will need evaluating
Upgrading to 0.8
----------------
Since the release of 0.8.0 the following behaviours were altered:
1. The ``shouldIgnoreMissing()`` behaviour optionally applied to mock objects
returned an instance of ``\Mockery\Undefined`` when methods called did not
match a known expectation. Since 0.8.0, this behaviour was switched to
returning ``null`` instead. You can restore the 0.7.2 behavour by using the
following:
.. code-block:: php
$mock = \Mockery::mock('stdClass')->shouldIgnoreMissing()->asUndefined();
map.rst.inc 0000664 00000000164 15152100342 0006617 0 ustar 00 * :doc:`/getting_started/installation`
* :doc:`/getting_started/upgrading`
* :doc:`/getting_started/simple_example`