title: How to test deep cloning with PHPUnit
body: <p>I have implemented <code>__clone</code> on a class to clone the child objects (i.e. Deep cloning.)</p>
  
  <p>I want to write tests to ensure this process is correctly implemented.</p>
  
  <p>When I mock the a child object and try to set an expectation on the '__clone', PHPUnit errors because the method is not defined.  This is an example how I'm trying to write the assertion.</p>
  
  <pre><code>&lt;?php
  
  public function testClone()
  {
      $mockChildObject = $this-&gt;createMock(ChildObject::class);
      $mockChildObjectClone = $this-&gt;createMock(ChildObject::class);
      $mockChildObject-&gt;expects($this-&gt;once())-&gt;method('__clone')-&gt;willReturn($this-&gt;createMock($mockChildObjectClone));
  
      $object = new MyObject();
      $object-&gt;addChild($mockChildObject);
  
      $objectClone = clone $object;
  
      $this-&gt;assertSame($mockChildObjectClone, $objectClone-&gt;getChild());
  }
  </code></pre>
  
  <p>The resulting error reads:</p>
  
  <blockquote>
    <p>Trying to configure method "__clone" which cannot be configured because it does not exist, has not been specified, is final, or is static</p>
  </blockquote>
  
  <p>The <code>__clone</code> method is not implemented on the child objects because the default cloning is sufficient.</p>
  
  <p>I have also tried using <code>$this-&gt;getMockBuilder()</code> with various combinations of <code>disableOriginalClone()</code>/<code>enableOriginalClone()</code> and <code>enableArgumentCloning()</code>/<code>diableArgumentCloning()</code>.</p>
  
  <p>The only way I can think of test cloning is to write an another class that extends the child object and implements <code>__clone()</code>.  But this seems excessive and I'm sure there must be a more practical solution.</p>