Skip to content

Commit

Permalink
Improve strong types (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Oct 2, 2022
1 parent 7f7e466 commit f475d95
Show file tree
Hide file tree
Showing 31 changed files with 88 additions and 284 deletions.
44 changes: 22 additions & 22 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1']
php: ['7.4', '8.0', '8.1', '8.2']
type: ['Phpunit', 'Phpunit Lowest']
include:
- php: '8.1' # TODO replace with 'latest' once it represents at least PHP 8.1
Expand All @@ -106,7 +106,7 @@ jobs:
ACCEPT_EULA: Y
SA_PASSWORD: atk4_pass
oracle:
image: gvenzl/oracle-xe:18
image: gvenzl/oracle-xe:18-slim-faststart
env:
ORACLE_PASSWORD: atk4_pass
options: --health-cmd healthcheck.sh --health-interval=10s --health-timeout=5s --health-retries=10
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
php -r '(new PDO("mysql:host=mariadb", "root", "atk4_pass_root"))->exec("ALTER USER '"'"'atk4_test_user'"'"'@'"'"'%'"'"' WITH MAX_USER_CONNECTIONS 5");'
php -r '(new PDO("pgsql:host=postgres;dbname=atk4_test", "atk4_test_user", "atk4_pass"))->exec("ALTER ROLE atk4_test_user CONNECTION LIMIT 1");'
/usr/lib/oracle/setup.sh
if [ -n "$LOG_COVERAGE" ]; then mkdir coverage && cp tools/CoverageUtil.php demos; fi
if [ -n "$LOG_COVERAGE" ]; then mkdir coverage; fi
- name: "Run tests: SQLite"
run: |
Expand All @@ -168,8 +168,8 @@ jobs:
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) -v
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-mysql.cov; fi
- name: "Run tests: MariaDB"
if: success() || failure()
- name: "Run tests: MariaDB (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
env:
DB_DSN: "mysql:host=mariadb;dbname=atk4_test"
DB_USER: atk4_test_user
Expand All @@ -180,8 +180,8 @@ jobs:
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) -v
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-mariadb.cov; fi
- name: "Run tests: PostgreSQL"
if: success() || failure()
- name: "Run tests: PostgreSQL (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
env:
DB_DSN: "pgsql:host=postgres;dbname=atk4_test"
DB_USER: atk4_test_user
Expand All @@ -192,8 +192,8 @@ jobs:
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) -v
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-postgres.cov; fi
- name: "Run tests: MSSQL"
if: success() || failure()
- name: "Run tests: MSSQL (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
env:
DB_DSN: "sqlsrv:host=mssql;dbname=master;driverOptions[TrustServerCertificate]=1"
DB_USER: sa
Expand All @@ -204,8 +204,8 @@ jobs:
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) -v
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-mssql.cov; fi
- name: "Run tests: Oracle"
if: success() || failure()
- name: "Run tests: Oracle (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
env:
DB_DSN: "oci:dbname=oracle/xe"
DB_USER: system
Expand Down Expand Up @@ -238,7 +238,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1']
php: ['7.4', '8.0', '8.1', '8.2']
type: ['Chrome', 'Chrome Lowest']
include:
- php: 'latest'
Expand Down Expand Up @@ -267,7 +267,7 @@ jobs:
ACCEPT_EULA: Y
SA_PASSWORD: atk4_pass
oracle:
image: gvenzl/oracle-xe:18
image: gvenzl/oracle-xe:18-slim-faststart
env:
ORACLE_PASSWORD: atk4_pass
options: --health-cmd healthcheck.sh --health-interval=10s --health-timeout=5s --health-retries=10
Expand Down Expand Up @@ -322,7 +322,7 @@ jobs:
php -r '(new PDO("mysql:host=mariadb", "root", "atk4_pass_root"))->exec("ALTER USER '"'"'atk4_test_user'"'"'@'"'"'%'"'"' WITH MAX_USER_CONNECTIONS 5");'
php -r '(new PDO("pgsql:host=postgres;dbname=atk4_test", "atk4_test_user", "atk4_pass"))->exec("ALTER ROLE atk4_test_user CONNECTION LIMIT 1");'
/usr/lib/oracle/setup.sh
if [ -n "$LOG_COVERAGE" ]; then mkdir coverage && cp tools/CoverageUtil.php demos; fi
if [ -n "$LOG_COVERAGE" ]; then mkdir coverage; fi
ci_wait_until () { timeout 30 sh -c "until { $1 2> /dev/null; }; do sleep 0.02; done" || timeout 15 sh -c "$1" || { echo "health timeout: $1"; exit 1; }; }
php -S 127.0.0.1:8888 > /dev/null 2>&1 &
ci_wait_until 'nc -w 1 127.0.0.1 8888'
Expand Down Expand Up @@ -350,8 +350,8 @@ jobs:
php demos/_demo-data/create-db.php
vendor/bin/behat -vv --config behat.yml.dist
- name: "Run tests: MariaDB (only for coverage or cron)"
if: (success() || failure()) && (env.LOG_COVERAGE || github.event_name == 'schedule')
- name: "Run tests: MariaDB (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
env:
DB_DSN: "mysql:host=mariadb;dbname=atk4_test"
DB_USER: atk4_test_user
Expand All @@ -361,8 +361,8 @@ jobs:
php demos/_demo-data/create-db.php
vendor/bin/behat -vv --config behat.yml.dist
- name: "Run tests: PostgreSQL (only for coverage or cron)"
if: (success() || failure()) && (env.LOG_COVERAGE || github.event_name == 'schedule')
- name: "Run tests: PostgreSQL (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
env:
DB_DSN: "pgsql:host=postgres;dbname=atk4_test"
DB_USER: atk4_test_user
Expand All @@ -372,8 +372,8 @@ jobs:
php demos/_demo-data/create-db.php
vendor/bin/behat -vv --config behat.yml.dist
- name: "Run tests: MSSQL (only for coverage or cron)"
if: (success() || failure()) && (env.LOG_COVERAGE || github.event_name == 'schedule')
- name: "Run tests: MSSQL (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
env:
DB_DSN: "sqlsrv:host=mssql;dbname=master;driverOptions[TrustServerCertificate]=1"
DB_USER: sa
Expand All @@ -383,8 +383,8 @@ jobs:
php demos/_demo-data/create-db.php
vendor/bin/behat -vv --config behat.yml.dist
- name: "Run tests: Oracle (only for coverage or cron)"
if: (success() || failure()) && (env.LOG_COVERAGE || github.event_name == 'schedule')
- name: "Run tests: Oracle (only for cron)"
if: (success() || failure()) && github.event_name == 'schedule'
env:
DB_DSN: "oci:dbname=oracle/xe"
DB_USER: system
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Here are all the classes implemented:
- RegisterForm - registration form
- Auth - authentication controller, verify and record logged state
- UserAdmin - UI for user administration
- Layout\Narrow - SemanticUI-based narrow responsive layout login/registration forms
- Layout\Narrow - Fomantic-UI based narrow responsive layout login/registration forms
- Templates for forms an messages
- Demos for all of the above

Expand Down Expand Up @@ -104,9 +104,9 @@ Displays email and 2 password fields (for confirmation). If filled successfully

``` php
\Atk4\Login\LoginForm::addTo($app, [
'auth'=>$app->auth,
//'successLink'=>['dashboard'],
//'forgotLink'=>['forgot'],
'auth' => $app->auth,
// 'successLink' => ['dashboard'],
// 'forgotLink' => ['forgot'],
]);
```

Expand Down Expand Up @@ -147,8 +147,8 @@ Form::addTo($app)->setModel($app->auth->user);
Demos open profile form in a pop-up window, if you wish to do it, you can use this code:

``` php
Button::addTo($app, ['Profile', 'class.primary' => true])->on('click', Modal::addTo($app)->set(function ($p) {
Form::addTo($p)->setModel($p->app->auth->user);
Button::addTo($app, ['Profile', 'class.primary' => true])->on('click', Modal::addTo($app)->set(function (View $p) {
Form::addTo($p)->setModel($p->getApp()->auth->user);
})->show());
```

Expand Down
5 changes: 0 additions & 5 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
ignore:
- src/Behat
- demos
- docs
- tools
comment: false
coverage:
status:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
],
"homepage": "https://github.com/atk4/login",
"require": {
"php": ">=7.4 <8.2",
"php": ">=7.4 <8.3",
"atk4/ui": "dev-develop"
},
"require-release": {
"php": ">=7.4 <8.2",
"php": ">=7.4 <8.3",
"atk4/ui": "~4.0.0"
},
"require-dev": {
Expand Down
5 changes: 1 addition & 4 deletions demos/_includes/MigratorConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ class MigratorConsole extends Console
use DynamicMethodTrait;
use HookTrait;

/** @const string */
public const HOOK_BEFORE_MIGRATION = self::class . '@beforeMigration';

/** @const string */
public const HOOK_AFTER_MIGRATION = self::class . '@afterMigration';

/** @var class-string */
Expand All @@ -35,7 +32,7 @@ class MigratorConsole extends Console
public function migrateModels(array $models): void
{
// run inside callback
$this->set(function ($console) use ($models) {
$this->set(function (self $console) use ($models) {
$this->hook(self::HOOK_BEFORE_MIGRATION);

$console->notice('Preparing to migrate models');
Expand Down
2 changes: 1 addition & 1 deletion demos/_includes/Model/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function init(): void
$this->addField('active', ['type' => 'boolean', 'default' => true]);

// custom action
$this->addUserAction('test', function ($m) {
$this->addUserAction('test', function (self $m) {
return 'Test action run for ' . $m->getTitle() . ' !';
});
}
Expand Down
2 changes: 1 addition & 1 deletion demos/acl-clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Atk4\Ui\Message;

/** @var App $app */
include __DIR__ . '/init-app.php';
require_once __DIR__ . '/init-app.php';

Header::addTo($app, [
'Client list for ACL testing',
Expand Down
2 changes: 1 addition & 1 deletion demos/admin-roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Atk4\Ui\Header;

/** @var App $app */
include __DIR__ . '/init-app.php';
require_once __DIR__ . '/init-app.php';

Header::addTo($app)->set('Roles');

Expand Down
5 changes: 3 additions & 2 deletions demos/admin-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
use Atk4\Login\Model\Role;
use Atk4\Login\Model\User;
use Atk4\Ui\Button;
use Atk4\Ui\Console;
use Atk4\Ui\Header;
use Atk4\Ui\Message;
use Atk4\Ui\View;

/** @var App $app */
require __DIR__ . '/init-app.php';
require_once __DIR__ . '/init-app.php';

Header::addTo($app, ['Setup demo database']);

Expand All @@ -25,7 +26,7 @@
$c1 = MigratorConsole::addTo($v, ['event' => false]);

// after migration import data
$c1->onHook(MigratorConsole::HOOK_AFTER_MIGRATION, function ($c) {
$c1->onHook(MigratorConsole::HOOK_AFTER_MIGRATION, function (Console $c): void {
$c->notice('Populating data...');

$rule = new AccessRule($c->getApp()->db);
Expand Down
2 changes: 1 addition & 1 deletion demos/admin-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Atk4\Ui\Header;

/** @var App $app */
include __DIR__ . '/init-app.php';
require_once __DIR__ . '/init-app.php';

Header::addTo($app)->set('Users');
UserAdmin::addTo($app)->setModel(new User($app->db));
2 changes: 1 addition & 1 deletion demos/form-forgot.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Atk4\Ui\View;

/** @var App $app */
require __DIR__ . '/init-app.php';
require_once __DIR__ . '/init-app.php';

Header::addTo($app, ['Forgot password form']);
View::addTo($app, ['ui' => 'segment'])->set('Not implemented');
Expand Down
2 changes: 1 addition & 1 deletion demos/form-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Atk4\Login\Demos;

/** @var App $app */
require __DIR__ . '/init-app.php';
require_once __DIR__ . '/init-app.php';

$app->auth->logout();
$app->auth->displayLoginForm(['linkSuccess' => ['index']]);
2 changes: 1 addition & 1 deletion demos/form-register.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Atk4\Ui\Header;

/** @var App $app */
require __DIR__ . '/init-app.php';
require_once __DIR__ . '/init-app.php';

$app->html = null;
$app->initLayout([Narrow::class]);
Expand Down
2 changes: 1 addition & 1 deletion demos/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Atk4\Ui\View;

/** @var App $app */
require __DIR__ . '/init-app.php';
require_once __DIR__ . '/init-app.php';

Header::addTo($app, ['Welcome to Auth Add-on demo app']);

Expand Down
20 changes: 12 additions & 8 deletions demos/init-app.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,37 @@
namespace Atk4\Login\Demos;

use Atk4\Data\Persistence;
use Atk4\Ui\Behat\CoverageUtil;
use Atk4\Ui\Exception;

date_default_timezone_set('UTC');

require_once __DIR__ . '/init-autoloader.php';

// collect coverage for HTTP tests 1/2
if (file_exists(__DIR__ . '/CoverageUtil.php') && !class_exists(\PHPUnit\Framework\TestCase::class, false)) {
require_once __DIR__ . '/CoverageUtil.php';
\CoverageUtil::start();
$coverageSaveFx = null;
if (is_dir(__DIR__ . '/../coverage') && !CoverageUtil::isCalledFromPhpunit()) {
CoverageUtil::startFromPhpunitConfig(__DIR__ . '/..');
$coverageSaveFx = function (): void {
CoverageUtil::saveData(__DIR__ . '/../coverage');
};
}

$app = new App();

// collect coverage for HTTP tests 2/2
if (file_exists(__DIR__ . '/CoverageUtil.php') && !class_exists(\PHPUnit\Framework\TestCase::class, false)) {
$app->onHook(\Atk4\Ui\App::HOOK_BEFORE_EXIT, function () {
\CoverageUtil::saveData();
});
if ($coverageSaveFx !== null) {
$app->onHook(App::HOOK_BEFORE_EXIT, $coverageSaveFx);
}
unset($coverageSaveFx);

try {
/** @var Persistence\Sql $db */
require_once __DIR__ . '/init-db.php';
$app->db = $db;
unset($db);
} catch (\Throwable $e) {
throw new \Atk4\Ui\Exception('Database error: ' . $e->getMessage());
throw new Exception('Database error: ' . $e->getMessage());
}

$app->invokeInit();
4 changes: 3 additions & 1 deletion demos/init-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace Atk4\Login\Demos;

use Atk4\Ui\Exception;

try {
require_once file_exists(__DIR__ . '/db.php')
? __DIR__ . '/db.php'
: __DIR__ . '/db.default.php';
} catch (\PDOException $e) {
// do not show $e unless you can secure DSN!
throw (new \Atk4\Ui\Exception('This demo requires access to the database. See "demos/init-db.php"'))
throw (new Exception('This demo requires access to the database. See "demos/init-db.php"'))
->addMoreInfo('PDO error', $e->getMessage());
}
Loading

0 comments on commit f475d95

Please sign in to comment.