public function setUp()
 {
     $this->_tmpDb = tempnam(sys_get_temp_dir(), "oauth_");
     if (FALSE === $this->_tmpDb) {
         throw new Exception("unable to generate temporary file for database");
     }
     $dsn = "sqlite:" . $this->_tmpDb;
     // load default config
     $this->_config = new Config(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "oauth.ini.defaults");
     $this->_config->setValue("accessTokenExpiry", 5);
     // override DB config in memory only
     $this->_config->setValue("storageBackend", "PdoOAuthStorage");
     $this->_config->setSectionValue("PdoOAuthStorage", "dsn", $dsn);
     #        $this->_config->setSectionValue("DummyResourceOwner", "resourceOwnerEntitlement") = array ("foo" => array("fkooman"));
     // intialize storage
     $storage = new PdoOAuthStorage($this->_config);
     $sql = file_get_contents('schema/db.sql');
     $storage->dbQuery($sql);
     // FIXME: apply updates
     // add some clients
     $uaba = array("id" => "testclient", "name" => "Simple Test Client", "description" => "Client for unit testing", "secret" => NULL, "icon" => NULL, "allowed_scope" => "read", "contact_email" => "*****@*****.**", "redirect_uri" => "http://localhost/php-oauth/unit/test.html", "type" => "user_agent_based_application");
     $wa = array("id" => "testcodeclient", "name" => "Simple Test Client for Authorization Code Profile", "description" => "Client for unit testing", "secret" => "abcdef", "icon" => NULL, "allowed_scope" => "read write foo bar foobar", "contact_email" => NULL, "redirect_uri" => "http://localhost/php-oauth/unit/test.html", "type" => "web_application");
     $na = array("id" => "testnativeclient", "name" => "Simple Test Client for Authorization Code Native Profile", "description" => "Client for unit testing", "secret" => NULL, "icon" => NULL, "allowed_scope" => "read", "contact_email" => NULL, "redirect_uri" => "oauth://callback", "type" => "native_application");
     $storage->addClient($uaba);
     $storage->addClient($wa);
     $storage->addClient($na);
 }
<?php

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "autoload.php";
use RestService\Utils\Config;
use OAuth\PdoOAuthStorage;
use OAuth\ClientRegistration;
use RestService\Utils\Json;
$config = new Config(dirname(__DIR__) . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "oauth.ini");
$storage = new PdoOAuthStorage($config);
$storage->initDatabase();
if ($argc !== 2) {
    echo "ERROR: specify manifest file or URL to parse" . PHP_EOL;
    die;
}
$manifestFile = $argv[1];
$fileContents = file_get_contents($manifestFile);
$data = Json::dec($fileContents);
if (NULL === $data || !is_array($data)) {
    echo "ERROR: manifest seems to be in wrong format" . PHP_EOL;
    die;
}
foreach ($data as $d) {
    // go over all app entries
    if (FALSE === $storage->getClient($d['key'])) {
        echo "Adding '" . $d['name'] . "'..." . PHP_EOL;
        $x = array("id" => $d['key'], "name" => $d['name'], "description" => $d['description'], "secret" => NULL, "type" => "user_agent_based_application", "icon" => $d['icons']['128'], "allowed_scope" => implode(" ", $d['permissions']), "redirect_uri" => $d['app']['launch']['web_url']);
        $y = ClientRegistration::fromArray($x);
        $storage->addClient($y->getClientAsArray());
    }
}