title: Mocking fails() and make() on a Validator object
body: <p>I am trying to mock the response I get from a <code>Validator</code> object using <code>Mockery</code>, I am trying eventually for force a pass or a fail on the validation so that I can test what happens after the validation. I have tried the following with no joy.</p>
  
  <pre><code>$validator = Validator::shouldReceive('make')
      -&gt;once()
      -&gt;with([], $this-&gt;rules);
  
  $validator-&gt;shouldReceive('fails')
      -&gt;once()
      -&gt;andReturn(true);
  </code></pre>
  
  <p>And </p>
  
  <pre><code>$validator = Validator::shouldReceive('make')
      -&gt;once()
      -&gt;with([], $this-&gt;rules)
      -&gt;shouldReceive('fails')
      -&gt;once()
      -&gt;andReturn(true);    
  </code></pre>
  
  <p>With both of these I then set the validator property in the class to the object coming back from Mockery</p>
  
  <p>The function I am trying to test looks like this</p>
  
  <pre><code>class JsonModel extends Model
  {
  
      private $validator;
  
      public function createFromJSON(array $inputData, $throwException = false)
      {
          // This calls Validator::make
          $this-&gt;makeValidator(
              $inputData, 
              $this-&gt;getValidationRules() // An internal function that returns the rules for the Model
          );
  
          if($this-&gt;validator-&gt;fails()) {
               if($throwException === true) {
                   throw new Exception('Validation failed');
               } else {
                   return null;
               }
           }
          return null;
  
          /** @var Model $model */
          $model = self::create($inputData);
          return $model;
      }
  
      private function makeValidator($inputData, $ruleData)
      {
          $this-&gt;validator = Validator::make($inputData, $ruleData);
      }
  }
  </code></pre>
  
  <p>I'm open to suggestions for other approaches, not essential that I fix it because I can just go down the return null path, remove the exception and assume Validator will do it's job but it's bugging me.</p>