title: Mocking Laravel's Request::segment method
body: <p>This is related to <a href="https://stackoverflow.com/questions/21369584/mocking-input-facade-in-laravel-4">this question</a>, but following that solution did not fix my issue. I also realize that <a href="http://laravel.com/docs/testing#mocking-facades" rel="nofollow noreferrer">Laravel's own documentation</a> states that you should not mock the <code>Request</code> object, but I'm not sure how else to go about writing this test.</p>
  
  <p>Here's a semblance of the code I want to test:</p>
  
  <pre><code>public function getThirdSegment()
  {
      return Request::segment(3);
  }
  </code></pre>
  
  <p>Here's a test I currently have:</p>
  
  <pre><code>/**
   * @test
   */
  public function indexReturnsOk()
  {
      $this-&gt;prepareForTests();
      $this-&gt;call('GET', '/api/v1/courses');
      $this-&gt;assertResponseOk();
      $this-&gt;assertResponseStatus(200);
  }
  </code></pre>
  
  <p>This is failing because <code>Request::segment(3)</code> is returning null when running PHPUnit.  I first tried to mock the Request object like this:</p>
  
  <pre><code>Request::shouldReceive('segment')-&gt;andReturn('courses');
  </code></pre>
  
  <p>But it still returns null.  Then I tried this:</p>
  
  <pre><code>$request = m::mock('Illuminate\Http\Request');
  $request-&gt;shouldReceive('segment')-&gt;andReturn('courses');
  Input::swap($request);
  </code></pre>
  
  <p>And the <code>segment</code> method is still returning null.  Is there any way to mock the return value of this method?</p>
  
  <p><strong>Update</strong></p>
  
  <p>This code is within a service provider's register method, but I don't think that's the cause of the issue.  Hitting the site from a browser does what I would expect it to do, yet running PHPUnit doesn't seem to flesh out either the route or the URL, or anything having to do with the request itself.</p>