public function setUp()
{
$ioStub = $this->getMockBuilder('fkooman\\IO\\IO')->getMock();
$ioStub->method('getRandom')->will($this->onConsecutiveCalls(2, 3, 5, 7));
$db = new PDO($GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']);
$md = new MetadataStorage($db, '', $ioStub);
$md->initDatabase();
$tempFile = tempnam(sys_get_temp_dir(), '');
if (file_exists($tempFile)) {
@unlink($tempFile);
}
mkdir($tempFile);
$this->tempFile = $tempFile;
$document = new DocumentStorage($tempFile);
$remoteStorage = new RemoteStorage($md, $document);
$approvalManagementStorage = new ApprovalManagementStorage($db);
$userAuth = new TestAuthentication();
$apiAuth = new BearerAuthentication(new TestTokenValidator());
$authenticationPlugin = new AuthenticationPlugin();
$authenticationPlugin->register($userAuth, 'user');
$authenticationPlugin->register($apiAuth, 'api');
$this->r = new RemoteStorageService($remoteStorage, $approvalManagementStorage, new TestTemplateManager(), new RemoteStorageClientStorage(), new RemoteStorageResourceServer(), new TestApproval(), new TestAuthorizationCode(), new TestAccessToken(), array('server_mode' => 'production'), $ioStub);
$this->r->getPluginRegistry()->registerDefaultPlugin($authenticationPlugin);
}