Linux unitednationsplay.com 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
nginx/1.20.1
Server IP : 188.130.139.92 & Your IP : 3.133.149.244
Domains :
Cant Read [ /etc/named.conf ]
User : web
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
home /
www /
3 /
mockery /
mockery /
docs /
getting_started /
Delete
Unzip
Name
Size
Permission
Date
Action
index.rst
156
B
-rw-r--r--
2018-10-02 09:00
installation.rst
1.26
KB
-rw-r--r--
2018-10-02 09:00
map.rst.inc
158
B
-rw-r--r--
2018-10-02 09:00
quick_reference.rst
5.02
KB
-rw-r--r--
2018-10-02 09:00
simple_example.rst
2.06
KB
-rw-r--r--
2018-10-02 09:00
upgrading.rst
2.92
KB
-rw-r--r--
2018-10-02 09:00
Save
Rename
.. 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 { private $service; 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; class TemperatureTest extends PHPUnit_Framework_TestCase { public function tearDown() { Mockery::close(); } public function testGetsAverageTemperatureFromThreeServiceReadings() { $service = Mockery::mock('service'); $service->shouldReceive('readTemp') ->times(3) ->andReturn(10, 12, 14); $temperature = new Temperature($service); $this->assertEquals(12, $temperature->average()); } } We create a mock object which our ``Temperature`` class will use and set some expectations for that mock — that it should receive three calls to the ``readTemp`` method, and these calls will return 10, 12, and 14 as results. .. note:: PHPUnit integration can remove the need for a ``tearDown()`` method. See ":doc:`/reference/phpunit_integration`" for more information.