<?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 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.uopz-set-mock.php',
    1 => 'uopz_set_mock',
    2 => 'Utilise une simulation au lieu d\'une classe pour de nouveaux objets',
  ),
  'up' => 
  array (
    0 => 'ref.uopz.php',
    1 => 'Fonctions Uopz',
  ),
  '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' => 'fr',
    '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">Utilise une simulation au lieu d&#039;une classe pour de nouveaux objets</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">
   Si <code class="parameter">mock</code> est une chaîne contenant le nom d&#039;une classe alors elle sera instanciée à la place de
   <code class="parameter">class</code>. <code class="parameter">mock</code> peut aussi être un objet.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Seul l&#039;accès dynamique aux propriétés et méthodes utilisera l&#039;objet <code class="parameter">mock</code>.
    L&#039;accès statique utilise toujours la <code class="parameter">class</code> originale.
    Voir l&#039;<a href="function.uopz-set-mock.php#uopz_set_mock.example.static" class="link">exemple</a> ci-dessous.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.uopz-set-mock-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <dl>
   
    <dt><code class="parameter">class</code></dt>
    <dd>
     <p class="para">
      Le nom de la classe à simuler.
     </p>
    </dd>
   
   
    <dt><code class="parameter">mock</code></dt>
    <dd>
     <p class="para">
      La simulation à utiliser sous forme de chaîne contenant le nom de la classe à utiliser ou un objet.
      Si une chaîne est passée, elle doit être le nom de la classe entièrement qualifié. Il est
      recommandé d&#039;utiliser la constante magique <code class="code">::class</code> dans ce cas.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.uopz-set-mock-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Aucune valeur n&#039;est retournée.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.uopz-set-mock-changelog">
  <h3 class="title">Historique</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>
       Simuler les membres statiques n&#039;est plus supporté par cette fonction.
       <span class="function"><a href="function.uopz-redefine.php" class="function">uopz_redefine()</a></span> et <span class="function"><a href="function.uopz-set-return.php" class="function">uopz_set_return()</a></span>,
       ou <a href="book.componere.php" class="link">Componere</a> peuvent être utilisés à la place.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.uopz-set-mock-examples">
  <h3 class="title">Exemples</h3>
  <div class="example" id="example-1">
   <p><strong>Exemple #1 Exemple de <span class="function"><strong>uopz_set_mock()</strong></span></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>L&#039;exemple ci-dessus va afficher :</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>Exemple #2 Exemple de <span class="function"><strong>uopz_set_mock()</strong></span></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>L&#039;exemple ci-dessus va afficher :</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>Exemple #3 <span class="function"><strong>uopz_set_mock()</strong></span> et membres statiques</strong></p>
   <div class="example-contents"><p>
    Depuis uopz 6.0.0, la simulation des membres statiques n&#039;est plus supportée.
   </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>L&#039;exemple ci-dessus va afficher :</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">A
A</pre>
</div>
   </div>
    <div class="example-contents"><p>
     L&#039;exemple ci-dessus affiche avec 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">Voir aussi</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.uopz-get-mock.php" class="function" rel="rdfs-seeAlso">uopz_get_mock()</a> - Renvoie la simulation actuelle d'une classe</span></li>
   <li><span class="function"><a href="function.uopz-unset-mock.php" class="function" rel="rdfs-seeAlso">uopz_unset_mock()</a> - Supprime la simulation pr&eacute;c&eacute;demment d&eacute;finie</span></li>
  </ul>
 </div>


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