Skip to content

Instantly share code, notes, and snippets.

@fangel
Created May 19, 2009 10:21
Show Gist options
  • Save fangel/114033 to your computer and use it in GitHub Desktop.
Save fangel/114033 to your computer and use it in GitHub Desktop.
<?php
class OAuthServerTest extends PHPUnit_Framework_TestCase {
public function testRejectInvalidConsumer() {
$unknown_consumer = new OAuthConsumer('unknown', '__unused__');
$stub = $this->getMock('OAuthDataStore');
$stub->expects($this->any())
->method('lookup_consumer')
->with($unknown_consumer->key)
->will($this->returnValue( NULL ));
$request = OAuthRequest::from_consumer_and_token( $unknown_consumer, $this->consumer_token, 'POST', 'http://example.com');
$request->sign_request( $this->hmac_sha1, $unknown_consumer, $this->consumer_token );
$server = new OAuthServer( $stub );
$server->add_signature_method( $this->hmac_sha1 );
$this->setExpectedException('OAuthException');
$server->verify_request( $request );
}
}
/*
Error _WITHOUT_ setExpectedException
--
1) testRejectInvalidConsumer(OAuthServerTest)
OAuthException: Invalid consumer
/Users/fangel/Sites/oauth/oauth-full-repo/code/php/OAuth.php:537
/Users/fangel/Sites/oauth/oauth-full-repo/code/php/OAuth.php:485
/Users/fangel/Sites/oauth/oauth-full-repo/code/php/tests/OAuthServerTest.php:74
--
Error with setExpectedException
--
1) testRejectInvalidConsumer(OAuthServerTest)
Expectation failed for method name is equal to <string:lookup_consumer> when invoked zero or more times.
Mocked method does not exist.
/Users/fangel/php/lib/php/PHPUnit/Framework/MockObject/Mock.php(228) : eval()'d code:21
--
Contents of $this->data_store in OAuthServer::lookup_consumer
--
object(Mock_OAuthDataStore_a01da5be)#38 (1) {
["invocationMocker:private"]=>
object(PHPUnit_Framework_MockObject_InvocationMocker)#37 (2) {
["matchers:protected"]=>
array(1) {
[0]=>
object(PHPUnit_Framework_MockObject_Matcher)#34 (6) {
["invocationMatcher"]=>
object(PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount)#36 (1) {
["invocations:protected"]=>
array(0) {
}
}
["afterMatchBuilderId"]=>
NULL
["afterMatchBuilderIsInvoked"]=>
bool(false)
["methodNameMatcher"]=>
object(PHPUnit_Framework_MockObject_Matcher_MethodName)#33 (1) {
["constraint:protected"]=>
object(PHPUnit_Framework_Constraint_IsEqual)#27 (4) {
["value:protected"]=>
string(15) "lookup_consumer"
["delta:protected"]=>
int(0)
["maxDepth:protected"]=>
int(10)
["canonicalizeEol:protected"]=>
bool(false)
}
}
["parametersMatcher"]=>
object(PHPUnit_Framework_MockObject_Matcher_Parameters)#28 (2) {
["parameters:protected"]=>
array(1) {
[0]=>
object(PHPUnit_Framework_Constraint_IsEqual)#29 (4) {
["value:protected"]=>
string(7) "unknown"
["delta:protected"]=>
int(0)
["maxDepth:protected"]=>
int(10)
["canonicalizeEol:protected"]=>
bool(false)
}
}
["invocation:protected"]=>
NULL
}
["stub"]=>
object(PHPUnit_Framework_MockObject_Stub_Return)#30 (1) {
["value:protected"]=>
NULL
}
}
}
["builderMap:protected"]=>
array(0) {
}
}
}
--
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment