title: How to provide properties for PHPUnit's prophecy objects?
body: <p>I'm mocking an API with <a href="https://github.com/phpspec/prophecy#how-to-use-it" rel="nofollow noreferrer">Prophecy</a>.</p>
  
  <p>A call on the api object to <code>payments()</code> will return an object that has a <code>get($id)</code> method, which returns another object which has a few methods and properties. One of the properties is ID and I want to test that that's what I expect.</p>
  
  <p>Without mocking anything, using the live API, this might work:</p>
  
  <pre><code>$payment = $api-&gt;payments()-&gt;get(12345);
  $this-&gt;assertEquals(12345, $payment-&gt;id);
  </code></pre>
  
  <p>To mock the API I'm setting it up like:</p>
  
  <pre><code>$mock_payment = $this-&gt;prophesize('Api\\Resources\\Payment');
  
  $mock_payments = $this-&gt;prophesize('Api\\Services\\PaymentsService');
  $mock_payments-&gt;get(12345)-&gt;willReturn($mock_payment-&gt;reveal());
  
  $api = $this-&gt;prophesize('Api');
  $api-&gt;payments()-&gt;willReturn($mock_payments-&gt;reveal());
  
  // Now the test code from above:
  $payment = $api-&gt;payments()-&gt;get(12345);
  $this-&gt;assertEquals(12345, $payment-&gt;id)
  </code></pre>
  
  <p>However I can't figure out how to give the <code>reveal()</code>-ed mock payment object  a public ID property, and how to set that to the passed-in ID (<code>12345</code>)?</p>
  
  <h2>Edit: simplification of question.</h2>
  
  <p>I have a 3rd party API that I cannot change and do not wish to test. It returns instances of certain classes of object with data available through a mix of public properties and getters.</p>
  
  <p>SUT:</p>
  
  <pre><code>function doSomething($api) {
    $result = $api-&gt;getResult();
    return "Born: $result-&gt;born, " . $result-&gt;getAge() . " years old.";
  }
  </code></pre>
  
  <p>I want to test:</p>
  
  <pre><code>function testDoSomething() {
     // ...mock the $api so that getResult() returns an object like the 
     // expected one which has a born property set to "1 April 2016" and a 
     // and a getAge method that will return "1".
     // ...
     $result = doSomething($api);
     $this-&gt;assertEquals("Born: 1 April 2016, 1 years old.");
  }
  </code></pre>