title: Is it possible to mock a variable value for a method for CakePHP tests (PHP Unit)?
body: <p>I'm testing my API and there's a login method for OAuth that I can't seem to properly test due to how it will not read $_GET values of a variable when POSTing. </p>
  
  <p>The login method. Basically $OAuthParams doesn't get set when using POST because getAuthorizeParams() uses $_GET. <strong>So I want to fill/mock either $_GET or $OAuthParams.</strong></p>
  
  <pre><code>public function login () {
      $OAuthParams = $this-&gt;OAuth-&gt;getAuthorizeParams();
      if ($this-&gt;request-&gt;is('post')) {
          $this-&gt;validateRequest();
          $loginData = array('User' =&gt; array(
                  'username' =&gt; $this-&gt;request-&gt;data['User']['username'],
                  'passwd' =&gt; $this-&gt;request-&gt;data['User']['passwd']
              ));
          //Attempted login
          if ($this-&gt;Auth-&gt;login($loginData['User'])) {
              unset($loginData);
              $userData = $this-&gt;User-&gt;find('first',array(
                  'conditions' =&gt; array(
                      'User.username' =&gt; $this-&gt;request-&gt;data['User']['username']
                  ),
                  'fields' =&gt; array('username','name','id','banned','active','role','private'),
                  'recursive' =&gt; -1
              ));
  
              $this-&gt;Session-&gt;write('Auth.User',$userData['User']); //Update the session
  
              //Write this to session so we can log them out after authenticating
              $this-&gt;Session-&gt;write('OAuth.logout', true);
  
              //Write the auth params to the session for later
              $this-&gt;Session-&gt;write('OAuth.params', $OAuthParams);
  
              //Off we go
              return $this-&gt;redirect(array('action' =&gt; 'authorize'));
          } else {
              $this-&gt;Session-&gt;setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
          }
      }
      $appName = $this-&gt;applicationDetails['name'];
      $this-&gt;set(compact('OAuthParams','appName'));
  }
  </code></pre>
  
  <p>The current test method.</p>
  
  <pre><code>/**
   * testAccessToken method
   * 1. Get the authorization code (/oauth/authorize?response_type=code&amp;client_id=CLIENT_ID&amp;client_secret=CLIENT_SECRET)
   * 2. Retrieve the token (/oauth/token?grant_type=authorization_code&amp;code=CODE_RETURNED&amp;client_id=CLIENT_ID&amp;client_secret=CLIENT_SECRET)
   * 3. Parse the token from the returned data
   * @return void
  */
  public function testAccessToken(){
      //@link http://stackoverflow.com/questions/8183396/dealing-with-security-component-in-a-cakephp-2-test-case
      $this-&gt;OAuth = $this-&gt;generate('OAuth', array(
          'components' =&gt; array(
              'Security' =&gt; array('_validatePost'),
          )
      ));
      $this-&gt;OAuth-&gt;Security-&gt;expects($this-&gt;any())
          -&gt;method('_validatePost')
          -&gt;will($this-&gt;returnValue(true));
  
      $get_data = array(
          'response_type' =&gt; 'code',
          'client_id' =&gt; getenv('THREE_SCALE_APP_ID'),
          'client_secret' =&gt; getenv('THREE_SCALE_APP_KEY'),
      );
      $post_data = array(
          'User' =&gt; array(
              'username' =&gt; 'test_user_1',
              'passwd' =&gt; 'tester'
          )
      );
  
      $resultPost = $this-&gt;testAction(
          '/oauth/login', 
          array(
              'method' =&gt; 'post',
              'data' =&gt; $post_data
          )
      );
      debug($resultPost);
  
      $data_for_code = array(
          'accept' =&gt; 'Yep',
          'Authorize' =&gt; array(
              'client_id' =&gt; getenv('THREE_SCALE_APP_ID'),
              'client_secret' =&gt; getenv('THREE_SCALE_APP_KEY'),
              'response_type' =&gt; 'code',
              'state' =&gt; '',
              'scope' =&gt; ''
          )
      );
      $code = $this-&gt;testAction(
          '/oauth/authorize', 
          array(
              'data' =&gt; $data_for_code, 
              'method' =&gt; 'post'
          )
      );
      debug($code);
      /*$data_for_token = array(
          'grant_type' =&gt; 'authorization_code',
          'code' =&gt; $code,
          'client_id' =&gt; getenv('THREE_SCALE_APP_ID'),
          'client_secret' =&gt; getenv('THREE_SCALE_APP_KEY')
      );
      $token = $this-&gt;testAction(
          '/oauth/token', 
          array(
              'data' =&gt; $data_for_token, 
              'method' =&gt; 'post'
          )
      );*/
      //debug($token);
  }
  </code></pre>
  
  <p>Tried the following with no luck.</p>
  
  <pre><code>$this-&gt;OAuth = $this-&gt;generate(
      'OAuth',
      array(
          'components' =&gt; array(
              'Security' =&gt; array( '_validatePost' ),
              'Auth' =&gt; array('loggedIn','user')
          ),
          'methods' =&gt; array(
              'getAuthorizeParams'
          )
      )
  );
  $data = array(
      'response_type' =&gt; 'code',
      'client_id' =&gt; getenv('THREE_SCALE_APP_ID'),
      'client_secret' =&gt; getenv('THREE_SCALE_APP_KEY')
  );
  $this-&gt;OAuth-&gt;expects($this-&gt;any())
      -&gt;method('getAuthorizeParams')
      -&gt;will($this-&gt;returnValue($data));
  
  $loginData = array(
      'User' =&gt; array(
          'client_id' =&gt; getenv('THREE_SCALE_APP_ID'),
          'client_secret' =&gt; getenv('THREE_SCALE_APP_KEY'),
          'response_type' =&gt; 'code',
          'state' =&gt; '',
          'scope' =&gt; '',
          'redirect_uri' =&gt; 'https://myurl.com/api/myCallbackMethod',
          'username' =&gt; 'test_user_1',
          'passwd' =&gt; 'tester'
      )
  );
  
  //test login action
  $resultPost = $this-&gt;testAction(
      '/oauth/login?response_type=code&amp;client_id=' . getenv('THREE_SCALE_APP_ID') . '&amp;client_secret=' . getenv('THREE_SCALE_APP_KEY'), 
      array(
          'method' =&gt; 'post',
          'data' =&gt; $loginData
      )
  );
  debug($resultPost);
  
  $data = array(
      'accept' =&gt; 'Yep',
      'Authorize' =&gt; array(
          'client_id' =&gt; getenv('THREE_SCALE_APP_ID'),
          'client_secret' =&gt; getenv('THREE_SCALE_APP_KEY'),
          'response_type' =&gt; 'code',
          'state' =&gt; '',
          'scope' =&gt; ''
      )
  );
  
  $result = $this-&gt;testAction(
          '/oauth/authorize', 
          array(
              'data' =&gt; $data, 
              'method' =&gt; 'post'
          )
      );
  debug($result);
  </code></pre>