Skip to content

Commit

Permalink
Merge pull request #77 from arodu/feature/tests
Browse files Browse the repository at this point in the history
gh tests
  • Loading branch information
arodu authored Mar 3, 2024
2 parents b6f0c93 + 46babd3 commit f757c4d
Show file tree
Hide file tree
Showing 21 changed files with 369 additions and 405 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: CI

on:
push:
pull_request:

jobs:
testsuite:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3']
db-type: [sqlite]
prefer-lowest: ['']

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, apcu, memcached, redis, pdo_${{ matrix.db-type }}
ini-values: apc.enable_cli = 1
#coverage: pcov

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: Composer install
run: |
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
else
composer update
fi
- name: Run PHPUnit
run: |
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
vendor/bin/phpunit
cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, intl, apcu, memcached, redis
tools: cs2pr
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: Composer install
run: composer install

- name: Run PHP CodeSniffer
run: composer cs-check

- name: Run phpstan
if: success() || failure()
run: composer stan
continue-on-error: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
/phpunit.xml
/vendor
config/Migrations/schema-dump-default.lock
.phpunit.cache
/webroot/coverage
/.phpunit.cache
1 change: 0 additions & 1 deletion .phpunit.cache/test-results

This file was deleted.

13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CakeLTE: AdminLTE plugin for CakePHP 4.x
# CakeLTE: AdminLTE plugin for CakePHP 5.x

## Getting Started

Expand All @@ -25,15 +25,6 @@ You can load the plugin using the shell command:
bin/cake plugin load CakeLte
```

Or you can manually add the loading statement in the `src/Application.php` file of your application:

```php
public function bootstrap(){
parent::bootstrap();
$this->addPlugin('CakeLte');
}
```

add AdminLTE symlink to webroot
```bash
bin/cake cakelte install
Expand Down Expand Up @@ -101,7 +92,7 @@ bin/cake bake template [command] -t CakeLte register
bin/cake bake template [command] -t CakeLte recovery
```

### To modify the template you can copy one or all the files within your project, copying the following files in the folder `templates/plugin/CakeLte/` and keeping the same structure of `templates/`
To modify the template you can copy one or all the files within your project, copying the following files in the folder `templates/plugin/CakeLte/` and keeping the same structure of `templates/`

Replace the files elements

Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^5.0",
"phpunit/phpunit": "^10.1.0"
"phpunit/phpunit": "^10.1.0",
"phpstan/phpstan": "^1.10",
"cakedc/cakephp-phpstan": "^3.1"
},
"autoload": {
"psr-4": {
Expand All @@ -34,7 +36,8 @@
"cs-check": "phpcs --colors -p",
"cs-fix": "phpcbf --colors -p",
"stan": "phpstan analyse",
"test": "phpunit --colors=always"
"test": "phpunit --colors=always",
"test-coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html webroot/coverage --colors=always"
},
"config": {
"allow-plugins": {
Expand Down
Binary file modified docs/page-debug_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/page-debug_top-nav.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
level: 8
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
checkGenericClassInNonGenericObjectType: false
paths:
- src/
excludePaths:
- src/Console/Installer.php
includes:
- vendor/cakedc/cakephp-phpstan/extension.neon
8 changes: 5 additions & 3 deletions src/Command/CopyFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
{
// @todo if all files
$all = $args->getOption('all');
$forceOverwrite = $args->getOption('force');
$forceOverwrite = (bool)$args->getOption('force');
$type = $args->getArgument('type');

if (!$all && empty($type)) {
$io->err('Error: Need to add a type argument or --all option, excecute `cakelte copy_files -h` for help.');

return 1;
return static::CODE_ERROR;
}

if ($all) {
Expand All @@ -119,9 +119,11 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
$dest = Configure::read('App.paths.templates.0') . 'plugin/CakeLte/';

foreach ($files as $file) {
$content = file_get_contents($src . $file);
$content = (string)file_get_contents($src . $file);
$io->createFile($dest . $file, $content, $forceOverwrite);
}

return static::CODE_SUCCESS;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use Cake\Http\MiddlewareQueue;
use Cake\Routing\RouteBuilder;

define('CAKELTE_VERSION', '2.x');

/**
* Plugin for CakeLte
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Style/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Header implements StyleInterface
/** @deprecated STYLE_BLACK is deprecated, use STYLE_DARK insted*/
public const STYLE_BLACK = self::STYLE_DARK;

private const CSS_CLASSES = [
protected const CSS_CLASSES = [
self::STYLE_PRIMARY => 'navbar-primary navbar-light',
self::STYLE_SECONDARY => 'navbar-secondary navbar-light',
self::STYLE_INFO => 'navbar-info navbar-light',
Expand Down
4 changes: 3 additions & 1 deletion src/Style/Sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Sidebar implements StyleInterface
public const STYLE_LIGHT_WHITE = 'light-white';
public const STYLE_LIGHT_BLACK = 'light-black';

private const CSS_CLASSES = [
protected const CSS_CLASSES = [
// Dark
self::STYLE_DARK_PRIMARY => 'sidebar-dark-primary',
self::STYLE_DARK_SECONDARY => 'sidebar-dark-secondary',
self::STYLE_DARK_INFO => 'sidebar-dark-info',
Expand All @@ -37,6 +38,7 @@ class Sidebar implements StyleInterface
self::STYLE_DARK_WHITE => 'sidebar-dark-white',
self::STYLE_DARK_BLACK => 'sidebar-dark-black',

// Light
self::STYLE_LIGHT_PRIMARY => 'sidebar-light-primary',
self::STYLE_LIGHT_SECONDARY => 'sidebar-light-secondary',
self::STYLE_LIGHT_INFO => 'sidebar-light-info',
Expand Down
8 changes: 5 additions & 3 deletions src/Style/StyleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ trait StyleTrait
{
protected array $custom_css_classes = [];

protected Helper $helper;

/**
* @param \Cake\View\Helper $helper
*/
public function __construct(Helper $helper)
{
$this->_helper = $helper;
$this->helper = $helper;
}

/**
Expand All @@ -31,7 +33,7 @@ public function addStyle(string $key, string $style, bool $autoload = true): voi
$this->custom_css_classes[$key] = $style;

if ($autoload) {
$this->_helper->setConfig($this->_name . '.style', $key);
$this->helper->setConfig($this->_name . '.style', $key);
}
}

Expand All @@ -42,7 +44,7 @@ public function addStyle(string $key, string $style, bool $autoload = true): voi
public function getStyle(?string $key = null): ?string
{
if (empty($key)) {
$key = $this->_helper->getConfig($this->_name . '.style');
$key = $this->helper->getConfig($this->_name . '.style');
}

return $this->getStyles()[$key] ?? null;
Expand Down
26 changes: 24 additions & 2 deletions src/View/Helper/CakeLteHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

namespace CakeLte\View\Helper;

use Cake\Cache\Cache;
use Cake\Core\Configure;
use Cake\Log\Log;
use Cake\View\Helper;
use CakeLte\Style\Header;
use CakeLte\Style\Sidebar;
use Throwable;
use Composer\Json\JsonFile;
use Exception;

/**
* CakeLte helper
Expand All @@ -33,7 +35,7 @@ public function initialize(array $config): void
try {
Configure::load(static::DEFAULT_PLUGIN_CONFIG_FILE);
Configure::load($this->getConfig('configFile') ?? static::DEFAULT_APP_CONFIG_FILE);
} catch (Throwable $th) {
} catch (Exception $e) {
Log::alert('App config file doesn`t exist');
}
$this->setConfig(Configure::read('CakeLte'));
Expand Down Expand Up @@ -108,4 +110,24 @@ public function getMenuClass(): string

return implode(' ', $output);
}

/**
* @return string
*/
public function version(): string
{
return Cache::remember('cakelte_version', function () {
$lockFile = new JsonFile(ROOT . DIRECTORY_SEPARATOR . 'composer.lock');

Check failure on line 120 in src/View/Helper/CakeLteHelper.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Constant ROOT not found.

Check failure on line 120 in src/View/Helper/CakeLteHelper.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Instantiated class Composer\Json\JsonFile not found.

Check failure on line 120 in src/View/Helper/CakeLteHelper.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Constant ROOT not found.

Check failure on line 120 in src/View/Helper/CakeLteHelper.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Instantiated class Composer\Json\JsonFile not found.
if ($lockFile->exists()) {

Check failure on line 121 in src/View/Helper/CakeLteHelper.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Call to method exists() on an unknown class Composer\Json\JsonFile.

Check failure on line 121 in src/View/Helper/CakeLteHelper.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Call to method exists() on an unknown class Composer\Json\JsonFile.
$lockContent = $lockFile->read();

Check failure on line 122 in src/View/Helper/CakeLteHelper.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Call to method read() on an unknown class Composer\Json\JsonFile.

Check failure on line 122 in src/View/Helper/CakeLteHelper.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Call to method read() on an unknown class Composer\Json\JsonFile.
foreach ($lockContent['packages'] as $package) {
if ($package['name'] === 'arodu/cakelte') {
return $package['version'];
}
}
}

return 'unknow version';
});
}
}
20 changes: 13 additions & 7 deletions src/View/Helper/MenuLteHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/**
* MenuLte helper
*
* @property \Cake\View\Helper\HtmlHelper $Html
* @property \Cake\View\Helper\UrlHelper $Url
*/
class MenuLteHelper extends Helper
{
Expand Down Expand Up @@ -59,6 +62,15 @@ class MenuLteHelper extends Helper
*/
protected array $_activeItems = [];

/**
* @inheritDoc
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->checkActiveFromComponent();
}

/**
* Menu Example
*
Expand Down Expand Up @@ -89,13 +101,10 @@ class MenuLteHelper extends Helper
* ];
*
* @param array $menu
* @param bool $cache
* @return string
*/
public function render(array $menu): string
{
$this->checkActiveFromComponent();

$output = '';
foreach ($menu as $tag => $item) {
$output .= $this->renderItem($tag, $item, 1);
Expand Down Expand Up @@ -253,14 +262,11 @@ protected function formatItemHeader(string $tag, array $item): string
*/
protected function checkShowCondition(bool|callable $show): bool
{
if (is_bool($show)) {
return $show;
}
if (is_callable($show)) {
return $show();
}

return $this->getConfig('defaultShowItem');
return $show;
}

/**
Expand Down
13 changes: 0 additions & 13 deletions src/View/Styles/Header.php

This file was deleted.

Loading

0 comments on commit f757c4d

Please sign in to comment.