Skip to content

Commit

Permalink
Phalcon travis ci config (#1)
Browse files Browse the repository at this point in the history
* Added Travis CI installer for Phalcon

* Travis CI config for phalcon

* Refactored to the corresponding directory for the Phalcon classes

* Added phalcon autoload tests

* Test test

* Get client details test

* Init DB for phalcon test

* Refactored di connection

* More tests

* Disabled throwing an exception

* Setup methods

* Fixed table names

* Finalize tests
  • Loading branch information
lucasantarella authored Jul 1, 2016
1 parent 4d77748 commit f18eb47
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 32 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cache:
directories:
- $HOME/.composer/cache
- vendor
- $HOME/cphalcon
php:
- 5.3
- 5.4
Expand All @@ -20,11 +21,16 @@ services:
- mongodb
- redis-server
- cassandra
- mysql
- memcached
before_install:
- phpenv config-rm xdebug.ini || return 0
- composer install --prefer-source --no-interaction
- vendor/bin/install-phalcon.sh
- phpenv config-rm xdebug.ini || return 0
install:
- composer install --no-interaction
before_script:
- php -m
- psql -c 'create database oauth2_server_php;' -U postgres
after_script:
- php test/cleanup.php
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"aws/aws-sdk-php": "~2.8",
"firebase/php-jwt": "~2.2",
"predis/predis": "dev-master",
"thobbs/phpcassa": "dev-master"
"thobbs/phpcassa": "dev-master",
"techpivot/phalcon-ci-installer": "~1.0"
}
}
4 changes: 2 additions & 2 deletions src/OAuth2/Storage/Phalcon/Models/OauthAccessTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function findFirst($parameters = null)
*/
public function initialize()
{
$this->setSource("'oauth__access_tokens'");
$this->setSource("'oauth_access_tokens'");
$this->belongsTo('user_id', 'OAuth2\Storage\Phalcon\Models\OauthUsers', 'username', array("alias" => "User"));
$this->belongsTo('client_id', 'OAuth2\Storage\Phalcon\Models\OauthClients', 'client_id', array("alias" => "Client"));
}
Expand All @@ -73,7 +73,7 @@ public function initialize()
*/
public function getSource()
{
return 'oauth__access_tokens';
return 'oauth_access_tokens';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class OauthAuthorizationCodes extends \Phalcon\Mvc\Model
*/
public function getSource()
{
return 'oauth__authorization_codes';
return 'oauth_authorization_codes';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/OAuth2/Storage/Phalcon/Models/OauthClients.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function findFirst($parameters = null)
*/
public function initialize()
{
$this->setSource("'oauth__clients'");
$this->setSource("'oauth_clients'");
$this->belongsTo('user_id', 'OAuth2\Storage\Phalcon\Models\OauthUsers', 'username', array("alias" => "User"));
}

Expand All @@ -79,7 +79,7 @@ public function initialize()
*/
public function getSource()
{
return 'oauth__clients';
return 'oauth_clients';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OAuth2/Storage/Phalcon/Models/OauthJti.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class OauthJti extends \Phalcon\Mvc\Model
*/
public function getSource()
{
return 'oauth__jti';
return 'oauth_jti';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/OAuth2/Storage/Phalcon/Models/OauthJwt.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function findFirst($parameters = null)
*/
public function initialize()
{
$this->setSource("'oauth__jwt'");
$this->setSource("'oauth_jwt'");
$this->belongsTo('client_id', 'OAuth2\Storage\Phalcon\Models\OauthClients', 'client_id', array("alias" => "Client"));
}

Expand All @@ -61,7 +61,7 @@ public function initialize()
*/
public function getSource()
{
return 'oauth__jwt';
return 'oauth_jwt';
}

public function getClient($parameters = null)
Expand Down
4 changes: 2 additions & 2 deletions src/OAuth2/Storage/Phalcon/Models/OauthPublicKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function findFirst($parameters = null)
*/
public function initialize()
{
$this->setSource("'oauth__public_keys'");
$this->setSource("'oauth_public_keys'");
$this->belongsTo('client_id', 'OAuth2\Storage\Phalcon\Models\OauthClients', 'client_id', array("alias" => "Client"));
}

Expand All @@ -67,7 +67,7 @@ public function initialize()
*/
public function getSource()
{
return 'oauth__public_keys';
return 'oauth_public_keys';
}

public function getClient($parameters = null)
Expand Down
4 changes: 2 additions & 2 deletions src/OAuth2/Storage/Phalcon/Models/OauthRefreshTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function findFirst($parameters = null)
*/
public function initialize()
{
$this->setSource("'oauth__refresh_tokens'");
$this->setSource("'oauth_refresh_tokens'");
$this->belongsTo('user_id', 'OAuth2\Storage\Phalcon\Models\OauthUsers', 'username');
$this->belongsTo('client_id', 'OAuth2\Storage\Phalcon\Models\OauthClients', 'client_id');
}
Expand All @@ -73,7 +73,7 @@ public function initialize()
*/
public function getSource()
{
return 'oauth__refresh_tokens';
return 'oauth_refresh_tokens';
}

}
2 changes: 1 addition & 1 deletion src/OAuth2/Storage/Phalcon/Models/OauthScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OauthScopes extends \Phalcon\Mvc\Model
*/
public function getSource()
{
return 'oauth__scopes';
return 'oauth_scopes';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/OAuth2/Storage/Phalcon/Models/OauthUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static function findFirst($parameters = null)
public function initialize()
{
$this->keepSnapshots(true);
$this->setSource("'oauth__users'");
$this->setSource("'oauth_users'");
$this->hasMany('username', 'OAuth2\Storage\Phalcon\Models\OauthAccessTokens', 'user_id', array("alias" => "AccessTokens"));
$this->hasMany('username', 'OAuth2\Storage\Phalcon\Models\OauthRefreshTokens', 'user_id', array("alias" => "RefreshTokens"));
}
Expand Down Expand Up @@ -112,7 +112,7 @@ public function validation()
*/
public function getSource()
{
return 'oauth__users';
return 'oauth_users';
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/OAuth2/Storage/Phalcon/Phalcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class Phalcon implements
*/
public function __construct($di, $config = array())
{
if(!isset($di['db']))
throw new \InvalidArgumentException('Dependency injector must contain a valid database connection');

$this->di = $di;
$this->config = array_merge(array(
'client_table' => 'oauth_clients',
Expand Down
2 changes: 2 additions & 0 deletions test/OAuth2/AutoloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public function testClassesExist()
$this->assertTrue(class_exists('OAuth2\Response'));
$this->assertTrue(class_exists('OAuth2\GrantType\UserCredentials'));
$this->assertTrue(interface_exists('OAuth2\Storage\AccessTokenInterface'));
$this->assertTrue(class_exists('OAuth2\Storage\Phalcon\Phalcon'));
$this->assertTrue(class_exists('OAuth2\Storage\Phalcon\Models\OauthUsers'));
}
}
101 changes: 101 additions & 0 deletions test/OAuth2/Storage/Phalcon/PhalconTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* Created by PhpStorm.
* User: lucas
* Date: 7/1/2016
* Time: 2:08 PM
*/

namespace OAuth2\Storage\Phalcon;


use OAuth2\Storage\BaseTest;
use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\Di;
use Phalcon\Di\FactoryDefault;
use Phalcon\Escaper;
use Phalcon\Mvc\Micro;
use Phalcon\Mvc\Model\Manager;
use Phalcon\Mvc\Model\MetaData\Memory;
use Phalcon\Mvc\Url;

class PhalconTest extends BaseTest
{
private $di;
/**
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->checkExtension('phalcon');
// Reset the DI container
Di::reset();
// Instantiate a new DI container
$di = new Di();
// Set the URL
$di->set(
'url',
function () {
$url = new Url();
$url->setBaseUri('/');
return $url;
}
);

$di->set(
'escaper',
function () {
return new Escaper();
}
);

$di->set('db', function() {
return new Mysql(array(
"host" => "localhost",
"username" => "root",
"password" => "",
"dbname" => "oauth2_server_php",
));
});

$di->set(
'modelsManager',
function () {
return new Manager();
}
);

$di->set(
'modelsMetadata',
function () {
return new Memory();
}
);

$this->di = $di;
}

public function checkExtension($extension)
{
$message = function ($ext) {
sprintf('Warning: %s extension is not loaded', $ext);
};
if (is_array($extension)) {
foreach ($extension as $ext) {
if (!extension_loaded($ext)) {
$this->markTestSkipped($message($ext));
break;
}
}
} elseif (!extension_loaded($extension)) {
$this->markTestSkipped($message($extension));
}
}

public function testPhalconDataStorage(){
$this->setUp();
$storage = new Phalcon($this->di);
$this->assertNotNull($storage->getClientDetails('oauth_test_client'));
}

}
15 changes: 0 additions & 15 deletions test/OAuth2/Storage/PhalconTest.php

This file was deleted.

0 comments on commit f18eb47

Please sign in to comment.