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; $config = new Config(dirname(__DIR__) . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "oauth.ini"); $storage = new PdoOAuthStorage($config); $sql = file_get_contents('schema/db.sql'); $storage->dbQuery($sql);