title: Mocking the AuthComponent in a Component Unit Test with Cakephp
body: <p>I have figured out how to mock the Auth Component when testing my controllers, but am struggling to mock the Auth Component when testing my components. I am using cakephp2.0 and phpUnit. </p>
  
  <p>When I use the ::generate() I am getting Error: Call to undefined method TestCalendarController::generate.</p>
  
  <p>Is there a way to mock the Auth Component user() function? Or do I need to rewrite the component to avoid using it?</p>
  
  <p>Thanks!</p>
  
  <p>CalendarComponentTest</p>
  
  <pre><code>App::uses('Controller', 'Controller');
  App::uses('CakeRequest', 'Network');
  App::uses('CakeResponse', 'Network');
  App::uses('ComponentCollection', 'Controller');
  App::uses('CalendarComponent', 'Controller/Component');
  App::uses('AuthComponent', 'Controller/Component');
  
  class TestCalendarController extends Controller {
  
  }
  
  class CalendarComponentTest extends CakeTestCase {
      public $CalendarComponent = null;
      public $Controller = null;
  
  public function setUp() {
          parent::setUp();
          // Setup our component and fake test controller
          $Collection = new ComponentCollection();
          $this-&gt;CalendarComponent = new CalendarComponent($Collection);
          $CakeRequest = new CakeRequest();
          $CakeResponse = new CakeResponse();
          $this-&gt;Controller = new TestCalendarController($CakeRequest, $CakeResponse);
          $this-&gt;CalendarComponent-&gt;startup($this-&gt;Controller);
  }
  
  //Here I am trying to mock the Auth component. I've tried a number of different things, and I'm not getting anything to work.
  public function testAdjust() {
      $TestCalendar = $this-&gt;Controller-&gt;generate('TestCalendar', array(
          'components' =&gt; array(
              'Auth' =&gt; array('user')
          )
      ));
      $TestCalendar-&gt;Auth-&gt;staticExpects($this-&gt;any())
          -&gt;method('user')
          -&gt;will($this-&gt;returnValue(array('id'=&gt;1, 'timezone'=&gt;'America/Los_Angeles', 'type'=&gt;'student')));
  
      // Test our adjust method with different parameter settings
      $this-&gt;CalendarComponent-&gt;calculate_parameters();
  
  
  
  }
  
   public function tearDown() {
        parent::tearDown();
        // Clean up after we're done
        unset($this-&gt;CalendarComponent);
        unset($this-&gt;Controller);
    }
  
  
  } 
  </code></pre>