title: Testing Laravel models with relations in repositories and phpspec
body: <p>I have an EloquentUserRepository and I want to test its methods but I don't really know where to start from. Anyone could provide any light to this?</p>
  
  <pre><code>public function findByProvider($provider, $user)
  {
      if (is_object($user))
      {
          $user = $user-&gt;id;
      }
  
      return $this-&gt;instance()-&gt;whereHas('socialProviders', function ($q) use ($provider, $user)
      {
          $q-&gt;where('name', $provider);
      })-&gt;first();
  }
  </code></pre>
  
  <p>This is an example of the functions I would like to test. It's finding users that have one socialProvider, let's say, github for instance. The basic structure of an User that has social providers would be something like this:</p>
  
  <pre><code>$data = [
          'user' =&gt; [
              'id' =&gt; 1,
              'email' =&gt; 'test@test.com',
              'socialProvider' =&gt; [
                  [
                      'name' =&gt; 'github',
                      'provider_id' =&gt; '00000000'
                  ]
              ]
          ]
      ];
  </code></pre>
  
  <p>Setting this, how can I test the model based on this structure? Is it really needed to create a memory db, migrate and seed for this purpose or can be tested without that?</p>
  
  <p>I am using phpspec because of the laracasts videos, but I'm not really sure if it is the right option... I hope some of you might help!</p>