title: Laravel / PHPUnit: Asserting sameness of two models
body: <p>When integration testing (using a database) in Laravel. What is the best way to assert that two instances of the same Eloquent model are the same?</p>
  <h3>AssertEquals <code>$model $model</code></h3>
  <p>Simply using <code>-&gt;assertEquals($modelOne, $modelTwo);</code> wont work as even if they <strong>are</strong> the same PHPUnit checks class properties such as <code>wasRecentlyCreated</code>  and sometimes model <code>id</code>s can be a string or an integer.</p>
  <h3>AssertEquals <code>$model-&gt;id $model-&gt;id</code></h3>
  <p>The problem here is model one may be an instance of another model e.g:</p>
  <p><code>AssertEquals(Person::find(1)-&gt;id, Animal::find(1)-&gt;id);</code> returns true.</p>
  <h3>AssertEquals <code>$model-&gt;toArray() $model-&gt;toArray()</code></h3>
  <p>The issue here is properties are not always cast as the same type, Im not 100% sure why but there are times a models properties will be an <code>int</code> and other times a number <code>string</code></p>
  <p><code>AssertEquals($address-&gt;toArray(), $user-&gt;address-&gt;toArray())</code></p>
  <pre><code>[ postcode =&gt; 2454 ]
  [ postcode =&gt; &quot;2454&quot; ]
  </code></pre>
  <p><strong>How to assert in a simple, clean and repeatable manner two Eloquent models are the same database record?</strong></p>