Skip to content

Commit

Permalink
addresses #373 - allows for nulling of storages in the Server class
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Apr 21, 2014
1 parent 153fdf3 commit 91c1fa5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/OAuth2/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public function addStorage($storage, $key = null)
{
// if explicitly set to a valid key, do not "magically" set below
if (isset($this->storageMap[$key])) {
if (!$storage instanceof $this->storageMap[$key]) {
if (!is_null($storage) && !$storage instanceof $this->storageMap[$key]) {
throw new \InvalidArgumentException(sprintf('storage of type "%s" must implement interface "%s"', $key, $this->storageMap[$key]));
}
$this->storages[$key] = $storage;
Expand Down
34 changes: 34 additions & 0 deletions test/OAuth2/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,40 @@ public function testAddingClientStorageSetsClientCredentialsStorageByDefault()
$this->assertEquals($client_credentials, $memory);
}

public function testAddStorageWithNullValue()
{
$memory = $this->getMock('OAuth2\Storage\Memory');
$server = new Server($memory);
$server->addStorage(null, 'refresh_token');

$client_credentials = $server->getStorage('client_credentials');

$this->assertNotNull($client_credentials);
$this->assertEquals($client_credentials, $memory);

$refresh_token = $server->getStorage('refresh_token');

$this->assertNull($refresh_token);
}

public function testNewServerWithNullStorageValue()
{
$memory = $this->getMock('OAuth2\Storage\Memory');
$server = new Server(array(
'client_credentials' => $memory,
'refresh_token' => null,
));

$client_credentials = $server->getStorage('client_credentials');

$this->assertNotNull($client_credentials);
$this->assertEquals($client_credentials, $memory);

$refresh_token = $server->getStorage('refresh_token');

$this->assertNull($refresh_token);
}

public function testAddingClientCredentialsStorageSetsClientStorageByDefault()
{
$server = new Server();
Expand Down

0 comments on commit 91c1fa5

Please sign in to comment.