Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Dec 14, 2023
1 parent a400e52 commit 2296184
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 64 deletions.
48 changes: 43 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,52 @@ env:
DEFAULT_COMPOSER_FLAGS: "--prefer-dist --no-interaction"
CC_TEST_REPORTER_ID: 7e481d4c18137693166bff4fd27569108bd02407c504fb772d3ead151189c856
jobs:

## PHPSTAN
phpstan:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@2.21.0
with:
php-version: '8.0'
extensions: mbstring, intl
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update: true

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: PHPStan tests
run: composer phpstan

# PHPCSFIXER
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install
run: composer install

- name: Run php-cs-fixer
run: composer phpcsfixer

## phpunit
phpunit:
name: PHP ${{ matrix.php }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
php: ['8.0', '8.1', '8.2', '8.3']

steps:
## checkout the repoistory
Expand All @@ -36,18 +74,18 @@ jobs:
## run unit tests
- name: PHP Unit tests for PHP
run: vendor/bin/phpunit --verbose --configuration actions.phpunit.xml
if: matrix.php == '8.0' || matrix.php == '7.4' || matrix.php == '7.3' || matrix.php == '7.2' || matrix.php == '7.0'
if: matrix.php == '8.0' || matrix.php == '8.1' || matrix.php == '8.2' || matrix.php == '8.3'

## unit test with coverage
- name: PHP Unit tests for PHP 7.1
- name: PHP Unit tests for PHP 8.0
run: vendor/bin/phpunit --verbose --coverage-clover=clover.xml --configuration actions.phpunit.xml
if: matrix.php == '7.1'
if: matrix.php == '8.0'

## coverage
- name: Code coverage
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter after-build -t clover
if: matrix.php == '7.1'
if: matrix.php == '8.0'
continue-on-error: true # if is fork
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
/.settings/
/vendor/
/luya
composer.lock
composer.lock
.php-cs-fixer.cache
.tmp
15 changes: 15 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;

$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
])
->setFinder($finder)
;
50 changes: 35 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
{
"name" : "luyadev/luya-module-admin-usertoken",
"description" : "Extend the LUYA Admin by providing app's which then LUYA Admin users can authenticated through the API.",
"type" : "luya-extension",
"keywords" : ["luya", "admin", "accesstoken", "tokens", "login", "api", "authentication"],
"name": "luyadev/luya-module-admin-usertoken",
"description": "Extend the LUYA Admin by providing app's which then LUYA Admin users can authenticated through the API.",
"type": "luya-extension",
"keywords": [
"luya",
"admin",
"accesstoken",
"tokens",
"login",
"api",
"authentication"
],
"license": "MIT",
"require": {
"luyadev/luya-module-admin" : "^3.0|^4.0"
"luyadev/luya-module-admin": "^3.0|^4.0|^4.0"
},
"require-dev" : {
"luyadev/luya-testsuite" : "^3.0"
"require-dev": {
"luyadev/luya-testsuite": "^3.0",
"friendsofphp/php-cs-fixer": "^3.2",
"phpstan/phpstan": "^1.7"
},
"autoload" : {
"psr-4" : {
"luya\\admin\\usertoken\\" : "src/"
"autoload": {
"psr-4": {
"luya\\admin\\usertoken\\": "src/"
}
},
"autoload-dev" : {
"psr-4" : {
"luya\\admin\\usertoken\\tests\\" : "tests/"
}
"autoload-dev": {
"psr-4": {
"luya\\admin\\usertoken\\tests\\": "tests/"
}
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
],
"config": {
"allow-plugins": {
"luyadev/luya-composer": true,
"yiisoft/yii2-composer": true
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan -v",
"phpcsfixer": "vendor/bin/php-cs-fixer fix"
}
}
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 0
paths:
- src
bootstrapFiles:
- vendor/yiisoft/yii2/Yii.php
tmpDir: .tmp
4 changes: 2 additions & 2 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
use luya\admin\models\User;
use luya\admin\Module;
use luya\admin\usertoken\models\Token;
use luya\admin\usertoken\Module as TokenModule;
use yii\base\BootstrapInterface;
use \luya\admin\usertoken\Module as TokenModule;

/**
* Bootstrap login by token.
*
*
* @author Basil Suter <git@nadar.io>
* @since 1.0.0
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* User Token Module
*
*
* @since 1.0.0
* @author Basil Suter <git@nadar.io>
*/
Expand All @@ -28,7 +28,7 @@ class Module extends BaseModule
* @var integer The number of seconds the user will be locked out after {{$loginAttemps}} has exceeded.
* @since 1.1.0
*/
public $loginAttemptLockoutTime = 1800;
public $loginAttemptLockoutTime = 1800;

/**
* {@inheritDoc}
Expand All @@ -50,7 +50,7 @@ class Module extends BaseModule
]
],
];

/**
* {@inheritDoc}
*/
Expand All @@ -63,4 +63,4 @@ public function getMenu()
->itemApi('Login Tokens', 'usertoken/token/index', 'lock', 'api-usertoken-token');
}

}
}
4 changes: 2 additions & 2 deletions src/apis/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* App Controller.
*
*
* @since 1.0.0
* @author Basil Suter <git@nadar.io>
*/
Expand All @@ -14,4 +14,4 @@ class AppController extends \luya\admin\ngrest\base\Api
* @var string The path to the model which is the provider for the rules and fields.
*/
public $modelClass = 'luya\admin\usertoken\models\App';
}
}
10 changes: 5 additions & 5 deletions src/apis/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/**
* Login Controller
*
*
* @since 1.0.0
* @author Basil Suter <git@nadar.io>
*/
Expand All @@ -32,9 +32,9 @@ public function actions()

/**
* User Login
*
*
* Login an user by email and password with a valid application token. The data must be submited by POST and requires `app`, `email` and `password` data.
*
*
* @return Token If successfull the token object is returned.
* @uses string email
* @uses string password
Expand All @@ -53,7 +53,7 @@ public function actionIndex()
$form->allowedAttempts = $this->module->loginAttempts;
$form->email = Yii::$app->request->getBodyParam('email');
$form->password = Yii::$app->request->getBodyParam('password');

if ($form->validate()) {

// Check for an existing token and udpate the token with a new value.
Expand Down Expand Up @@ -92,4 +92,4 @@ public function actionIndex()

return $this->sendModelError($form);
}
}
}
4 changes: 2 additions & 2 deletions src/apis/TokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Token Controller.
*
*
* @since 1.0.0
* @author Basil Suter <git@nadar.io>
*/
Expand All @@ -14,4 +14,4 @@ class TokenController extends \luya\admin\ngrest\base\Api
* @var string The path to the model which is the provider for the rules and fields.
*/
public $modelClass = 'luya\admin\usertoken\models\Token';
}
}
4 changes: 2 additions & 2 deletions src/controllers/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* App Controller.
*
*
* @since 1.0.0
* @author Basil Suter <git@nadar.io>
*/
Expand All @@ -22,4 +22,4 @@ public function getDescription()
{
return 'Register an app that will generate an identifier and can be used to make user login calls.';
}
}
}
4 changes: 2 additions & 2 deletions src/controllers/TokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Token Controller.
*
*
* @since 1.0.0
* @author Basil Suter <git@nadar.io>
*/
Expand All @@ -22,4 +22,4 @@ public function getDescription()
{
return 'List all users that have requested a login token for the given app.';
}
}
}
6 changes: 3 additions & 3 deletions src/models/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace luya\admin\usertoken\models;

use Yii;
use luya\admin\ngrest\base\NgRestModel;
use Yii;
use yii\behaviors\TimestampBehavior;

/**
Expand All @@ -16,7 +16,7 @@
* @property integer $expires_in
* @property integer $created_at
* @property integer $updated_at
*
*
* @since 1.0.0
* @author Basil Suter <git@nadar.io>
*/
Expand Down Expand Up @@ -49,7 +49,7 @@ public function init()
{
parent::init();

$this->on(self::EVENT_BEFORE_VALIDATE, function() {
$this->on(self::EVENT_BEFORE_VALIDATE, function () {
if ($this->isNewRecord) {
$this->token = Yii::$app->security->generateRandomString(64);
}
Expand Down
8 changes: 4 additions & 4 deletions src/models/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace luya\admin\usertoken\models;

use luya\admin\models\User;
use Yii;
use luya\admin\ngrest\base\NgRestModel;
use luya\admin\ngrest\plugins\SelectRelationActiveQuery;
use Yii;
use yii\behaviors\TimestampBehavior;

/**
Expand All @@ -19,7 +19,7 @@
* @property integer $created_at
* @property integer $updated_at
* @property-read integer $originalUserId
*
*
* @since 1.0.0
* @author Basil Suter <git@nadar.io>
*/
Expand Down Expand Up @@ -105,7 +105,7 @@ public function ngRestScopes()
['delete', false],
];
}

/**
* @return string The user id before relation is populated
* @since 1.3.0
Expand All @@ -114,7 +114,7 @@ public function getOriginalUserId()
{
return $this->getOldAttribute('user_id');
}

/**
* App Relation
*
Expand Down
Loading

0 comments on commit 2296184

Please sign in to comment.