<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.uopz.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.uopz-set-mock.php',
    1 => 'uopz_set_mock',
    2 => 'Use mock instead of class for new objects',
  ),
  'up' => 
  array (
    0 => 'ref.uopz.php',
    1 => 'Uopz Functions',
  ),
  'prev' => 
  array (
    0 => 'function.uopz-set-hook.php',
    1 => 'uopz_set_hook',
  ),
  'next' => 
  array (
    0 => 'function.uopz-set-property.php',
    1 => 'uopz_set_property',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/uopz/functions/uopz-set-mock.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.uopz-set-mock" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">uopz_set_mock</h1>
  <p class="verinfo">(PECL uopz 5, PECL uopz 6, PECL uopz 7)</p><p class="refpurpose"><span class="refname">uopz_set_mock</span> &mdash; <span class="dc-title">Use mock instead of class for new objects</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.uopz-set-mock-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>uopz_set_mock</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$class</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$mock</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="para rdfs-comment">
   If <code class="parameter">mock</code> is a string containing the name of a class then it will be instantiated instead of
   <code class="parameter">class</code>. <code class="parameter">mock</code> can also be an object.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Only dynamic access to properties and methods will use the <code class="parameter">mock</code> object.
    Static access still uses the original <code class="parameter">class</code>.
    See <a href="function.uopz-set-mock.php#uopz_set_mock.example.static" class="link">example</a> below.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.uopz-set-mock-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">class</code></dt>
    <dd>
     <p class="para">
      The name of the class to be mocked.
     </p>
    </dd>
   
   
    <dt><code class="parameter">mock</code></dt>
    <dd>
     <p class="para">
      The mock to use in the form of a string containing the name of the class to use or an object.
      If a string is passed, it has to be the fully qualified class name. It is
      recommended to use the <code class="code">::class</code> magic constant in this case.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.uopz-set-mock-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   No value is returned.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.uopz-set-mock-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>PECL uopz 6.0.0</td>
      <td>
       Mocking static members is no longer supported by this function.
       <span class="function"><a href="function.uopz-redefine.php" class="function">uopz_redefine()</a></span> and <span class="function"><a href="function.uopz-set-return.php" class="function">uopz_set_return()</a></span>,
       or <a href="book.componere.php" class="link">Componere</a> can be used instead.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.uopz-set-mock-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>uopz_set_mock()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">A </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">who</span><span style="color: #007700">() {<br />        echo </span><span style="color: #DD0000">"A"</span><span style="color: #007700">;<br />    }<br />}<br /><br />class </span><span style="color: #0000BB">mockA </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">who</span><span style="color: #007700">() {<br />        echo </span><span style="color: #DD0000">"mockA"</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">uopz_set_mock</span><span style="color: #007700">(</span><span style="color: #0000BB">A</span><span style="color: #007700">::class, </span><span style="color: #0000BB">mockA</span><span style="color: #007700">::class);<br />(new </span><span style="color: #0000BB">A</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">who</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>The above example will output:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">mockA</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-2">
   <p><strong>Example #2 <span class="function"><strong>uopz_set_mock()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">A </span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">who</span><span style="color: #007700">() {<br />        echo </span><span style="color: #DD0000">"A"</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">uopz_set_mock</span><span style="color: #007700">(</span><span style="color: #0000BB">A</span><span style="color: #007700">::class, new class {<br />                            public function </span><span style="color: #0000BB">who</span><span style="color: #007700">() {<br />                                echo </span><span style="color: #DD0000">"mockA"</span><span style="color: #007700">;<br />                            }<br />                        });<br />(new </span><span style="color: #0000BB">A</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">who</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>The above example will output:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">mockA</pre>
</div>
   </div>
  </div>
  <div class="example" id="uopz_set_mock.example.static">
   <p><strong>Example #3 <span class="function"><strong>uopz_set_mock()</strong></span> and static members</strong></p>
   <div class="example-contents"><p>
    As of uopz 6.0.0 mocking static members is no longer supported.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">A </span><span style="color: #007700">{<br />    const </span><span style="color: #0000BB">CON </span><span style="color: #007700">= </span><span style="color: #DD0000">'A'</span><span style="color: #007700">;<br />    public static function </span><span style="color: #0000BB">who</span><span style="color: #007700">() {<br />        echo </span><span style="color: #DD0000">"A"</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">uopz_set_mock</span><span style="color: #007700">(</span><span style="color: #0000BB">A</span><span style="color: #007700">::class, new class {<br />                            const </span><span style="color: #0000BB">CON </span><span style="color: #007700">= </span><span style="color: #DD0000">'mockA'</span><span style="color: #007700">;<br />                            public static function </span><span style="color: #0000BB">who</span><span style="color: #007700">() {<br />                                echo </span><span style="color: #DD0000">"mockA"</span><span style="color: #007700">;<br />                            }<br />                        });<br />echo </span><span style="color: #0000BB">A</span><span style="color: #007700">::</span><span style="color: #0000BB">CON</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">A</span><span style="color: #007700">::</span><span style="color: #0000BB">who</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>The above example will output:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">A
A</pre>
</div>
   </div>
    <div class="example-contents"><p>
     Output of the above example in uopz 5:
    </p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">mockA
mockA</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.uopz-set-mock-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.uopz-get-mock.php" class="function" rel="rdfs-seeAlso">uopz_get_mock()</a> - Get the current mock for a class</span></li>
   <li><span class="function"><a href="function.uopz-unset-mock.php" class="function" rel="rdfs-seeAlso">uopz_unset_mock()</a> - Unset previously set mock</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>