Example #1
0
 /**
  * Handle a method call being directed by this instance
  *
  * @param array $args
  * @return mixed
  */
 public function call(array $args)
 {
     $expectation = $this->findExpectation($args);
     if (is_null($expectation)) {
         $exception = new ehough_mockery_mockery_exception_NoMatchingExpectationException('No matching handler found for ' . $this->_mock->mockery_getName() . '::' . ehough_mockery_Mockery::formatArgs($this->_name, $args) . '. Either the method was unexpected or its arguments matched' . ' no expected argument list for this method' . PHP_EOL . PHP_EOL . ehough_mockery_Mockery::formatObjects($args));
         $exception->setMock($this->_mock)->setMethodName($this->_name)->setActualArguments($args);
         throw $exception;
     }
     return $expectation->verifyCall($args);
 }
 public function testFetchAccessTokens()
 {
     $tempCredentials = new ehough_coauthor_api_v1_Credentials('a', 'b');
     $this->_mockHttpClient->shouldReceive('execute')->once()->with(ehough_mockery_Mockery::on(array($this, '__callbackFetchTokensHttpRequest')))->andReturn($this->_mockHttpResponse);
     $this->_mockSigner->shouldReceive('signForAccessTokenRequest')->once()->with(ehough_mockery_Mockery::on(array($this, '__callbackFetchTokensHttpRequest')), $this->_mockClientCredentials, $tempCredentials, 'some-code');
     $this->_mockServer->shouldReceive('onCredentialsOrTokenRequest')->once()->with(ehough_mockery_Mockery::on(array($this, '__callbackFetchTokensHttpRequest')));
     $this->_mockServer->shouldReceive('onAfterCredentialsOrTokenRequest')->once()->with(ehough_mockery_Mockery::on(array($this, '__callbackFetchTokensHttpRequest')), $this->_mockHttpResponse);
     $result = $this->_sut->fetchToken($this->_mockClientCredentials, $this->_mockServer, $tempCredentials, 'some-code');
     $this->assertEquals('token', $result->getIdentifier());
 }
Example #3
0
 public function testCommence()
 {
     $mockCreds = new ehough_coauthor_api_v1_Credentials('a', 'z');
     $this->_mockCredentialsFetcher->shouldReceive('fetchTemporaryCredentials')->once()->with($this->_mockClientCredentials, $this->_mockServer, $this->_mockRedirectUrl)->andReturn($mockCreds);
     $this->_mockCredentialsStorage->shouldReceive('store')->once()->with($mockCreds);
     $this->_sut->commenceNewAuthorization($this->_mockServer, $this->_mockRedirectUrl, $this->_mockClientCredentials);
 }
Example #4
0
 /**
  * Sets up expectations on the members of the CompositeExpectation and
  * builds up any demeter chain that was passed to shouldReceive
  *
  * @param ehough_mockery_mockery_MockInterface $mock
  * @param string $arg
  * @param Closure $add
  * @return ehough_mockery_mockery_ExpectationDirector
  */
 protected static function _buildDemeterChain(ehough_mockery_mockery_MockInterface $mock, $arg, $add)
 {
     $container = $mock->mockery_getContainer();
     $names = explode('->', $arg);
     reset($names);
     if (!ehough_mockery_Mockery::getConfiguration()->mockingNonExistentMethodsAllowed() && method_exists($mock, "mockery_getMockableMethods") && !in_array(current($names), $mock->mockery_getMockableMethods())) {
         throw new ehough_mockery_mockery_Exception('Mockery\'s configuration currently forbids mocking the method ' . current($names) . ' as it does not exist on the class or object ' . 'being mocked');
     }
     $exp = null;
     $nextExp = array('ehough_mockery_Mockery', '_callbackNextExp1');
     //function ($n) use ($add) {return $add($n);};
     $useArg = $add;
     while (true) {
         $method = array_shift($names);
         $exp = $mock->mockery_getExpectationsFor($method);
         $needNew = false;
         if (is_null($exp) || empty($names)) {
             $needNew = true;
         }
         if ($needNew) {
             $exp = call_user_func($nextExp, $method, $useArg);
         }
         //$nextExp($method);
         if (empty($names)) {
             break;
         }
         if ($needNew) {
             $mock = $container->mock('demeter_' . $method);
             $exp->andReturn($mock);
         }
         $nextExp = array('ehough_mockery_Mockery', '_callbackNextExp2');
         //function ($n) use ($mock) {return $mock->shouldReceive($n);};
         $useArg = $mock;
     }
     return $exp;
 }