From 50e381c03ae98c09e2ab34b803f8e697d2739047 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 26 Jun 2022 23:02:44 +0530 Subject: [PATCH 1/8] Update for Cake 5. --- .github/workflows/ci.yml | 20 +++--- composer.json | 12 ++-- phpunit.xml.dist | 24 +++---- src/{Plugin.php => BootstrapUIPlugin.php} | 10 +-- src/Command/BootstrapCommand.php | 4 +- src/Command/CopyLayoutsCommand.php | 4 +- src/Command/InstallCommand.php | 8 +-- src/Command/ModifyViewCommand.php | 6 +- src/View/Helper/BreadcrumbsHelper.php | 4 +- src/View/Helper/FlashHelper.php | 5 +- src/View/Helper/FormHelper.php | 32 ++++----- src/View/Helper/HtmlHelper.php | 3 +- src/View/Helper/OptionsAwareTrait.php | 14 ++-- src/View/Helper/PaginatorHelper.php | 15 ++-- src/View/Widget/BasicWidget.php | 3 +- src/View/Widget/ButtonWidget.php | 3 +- src/View/Widget/DateTimeWidget.php | 3 +- src/View/Widget/FileWidget.php | 5 +- src/View/Widget/InputGroupTrait.php | 6 +- src/View/Widget/SelectBoxWidget.php | 3 +- src/View/Widget/TextareaWidget.php | 3 +- tests/Fixture/ArticlesFixture.php | 10 --- tests/Fixture/AuthorsFixture.php | 8 --- tests/TestCase/Bake/BakeTest.php | 7 +- .../TestCase/Command/BootstrapCommandTest.php | 14 +--- .../Command/CopyLayoutsCommandTest.php | 29 +++----- tests/TestCase/Command/InstallCommandTest.php | 51 ++++++-------- .../Command/ModifyViewCommandTest.php | 23 +++--- .../TestCase/View/Helper/FlashHelperTest.php | 3 +- .../DefaultAlign/DateTimeControlTest.php | 21 +++--- .../HorizontalAlign/DateTimeControlTest.php | 21 +++--- .../InlineAlign/DateTimeControlTest.php | 25 +++---- .../View/Helper/PaginatorHelperTest.php | 70 +++++++++---------- tests/bootstrap.php | 31 ++++---- tests/schema.php | 23 ++++++ tests/test_app/TestApp/Application.php | 3 +- 36 files changed, 255 insertions(+), 271 deletions(-) rename src/{Plugin.php => BootstrapUIPlugin.php} (81%) create mode 100644 tests/schema.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c23a652..fb3d0333 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,14 +10,14 @@ on: jobs: testsuite: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: - php-version: ['7.4', '8.0', '8.1'] + php-version: ['8.1', '8.2'] prefer-lowest: [''] include: - - php-version: '7.2' + - php-version: '8.1' prefer-lowest: 'prefer-lowest' services: @@ -42,17 +42,19 @@ jobs: run: | if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then composer update --prefer-lowest --prefer-stable + elif ${{ matrix.php-version == '8.2' }}; then + composer update --ignore-platform-req=php else - composer install + composer update fi - name: Setup problem matchers for PHPUnit - if: matrix.php-version == '7.4' + if: matrix.php-version == '8.1' run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run PHPUnit run: | - if [[ ${{ matrix.php-version }} == '7.4' ]]; then + if [[ ${{ matrix.php-version }} == '8.1' ]]; then vendor/bin/phpunit --coverage-clover=coverage.xml else vendor/bin/phpunit @@ -60,12 +62,12 @@ jobs: continue-on-error: ${{ matrix.prefer-lowest == 'prefer-lowest' }} - name: Code Coverage Report - if: matrix.php-version == '7.4' + if: matrix.php-version == '8.1' uses: codecov/codecov-action@v3 cs-stan: name: Coding Standard & Static Analysis - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 @@ -73,7 +75,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '8.1' extensions: mbstring, intl coverage: none tools: cs2pr, vimeo/psalm:4.23, phpstan:1.7 diff --git a/composer.json b/composer.json index 47f1a9d3..6285fa05 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ } ], "require": { - "cakephp/cakephp": "^4.0" + "cakephp/cakephp": "5.x-dev" }, "require-dev": { - "phpunit/phpunit": "^8.5 || ^9.3", - "cakephp/bake": "^2.1", - "cakephp/cakephp-codesniffer": "^4.1" + "phpunit/phpunit": "^9.5.19", + "cakephp/bake": "dev-cake5", + "cakephp/cakephp-codesniffer": "5.x-dev" }, "support": { "issues": "http://github.com/friendsofcake/bootstrap-ui/issues", @@ -52,5 +52,7 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } - } + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b2b2a9f5..b3e1dd7e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,17 +11,17 @@ - - - - - - - + + + - - - ./src/ - - + + + src/ + + + + + + diff --git a/src/Plugin.php b/src/BootstrapUIPlugin.php similarity index 81% rename from src/Plugin.php rename to src/BootstrapUIPlugin.php index 491d3a73..c8b3972e 100644 --- a/src/Plugin.php +++ b/src/BootstrapUIPlugin.php @@ -10,28 +10,28 @@ use Cake\Console\CommandCollection; use Cake\Core\BasePlugin; -class Plugin extends BasePlugin +class BootstrapUIPlugin extends BasePlugin { /** * Plugin name. * - * @var string + * @var string|null */ - protected $name = 'BootstrapUI'; + protected ?string $name = 'BootstrapUI'; /** * Do bootstrapping or not * * @var bool */ - protected $bootstrapEnabled = false; + protected bool $bootstrapEnabled = false; /** * Load routes or not * * @var bool */ - protected $routesEnabled = false; + protected bool $routesEnabled = false; /** * @inheritDoc diff --git a/src/Command/BootstrapCommand.php b/src/Command/BootstrapCommand.php index 4b786aae..031bfb74 100644 --- a/src/Command/BootstrapCommand.php +++ b/src/Command/BootstrapCommand.php @@ -21,7 +21,7 @@ class BootstrapCommand extends Command implements CommandCollectionAwareInterfac * * @var \Cake\Console\CommandCollection */ - protected $commands; + protected CommandCollection $commands; /** * @inheritDoc @@ -34,7 +34,7 @@ public function setCommandCollection(CommandCollection $commands): void /** * @inheritDoc */ - public function execute(Arguments $args, ConsoleIo $io) + public function execute(Arguments $args, ConsoleIo $io): ?int { $io->warning('No command provided. Run `bootstrap --help` to get a list of commands.'); diff --git a/src/Command/CopyLayoutsCommand.php b/src/Command/CopyLayoutsCommand.php index 53f77ea6..7e07fcfe 100644 --- a/src/Command/CopyLayoutsCommand.php +++ b/src/Command/CopyLayoutsCommand.php @@ -8,7 +8,7 @@ use Cake\Console\ConsoleIo; use Cake\Console\ConsoleOptionParser; use Cake\Core\Plugin; -use Cake\Filesystem\Filesystem; +use Cake\Utility\Filesystem; /** * Copies the sample layouts into the application's layout templates folder. @@ -18,7 +18,7 @@ class CopyLayoutsCommand extends Command /** * @inheritDoc */ - public function execute(Arguments $args, ConsoleIo $io) + public function execute(Arguments $args, ConsoleIo $io): ?int { $io->info('Copying sample layouts...'); diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index 628c36ce..c07f2471 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -10,7 +10,7 @@ use Cake\Console\ConsoleIo; use Cake\Console\ConsoleOptionParser; use Cake\Core\Plugin; -use Cake\Filesystem\Filesystem; +use Cake\Utility\Filesystem; /** * Installs Bootstrap dependencies and links the assets to the application's webroot. @@ -20,7 +20,7 @@ class InstallCommand extends Command /** * @inheritDoc */ - public function execute(Arguments $args, ConsoleIo $io) + public function execute(Arguments $args, ConsoleIo $io): ?int { $this->installPackages($args, $io); $this->refreshAssetBuffer($io); @@ -250,7 +250,7 @@ protected function _deleteBufferedPackageAssets(ConsoleIo $io): bool /** * Finds the buffered package assets. * - * @return \SplFileInfo[] + * @return array<\SplFileInfo> */ protected function _findBufferedPackageAssets(): array { @@ -344,7 +344,7 @@ protected function _bufferPackageAssets(ConsoleIo $io): bool /** * Finds the package assets to buffer. * - * @return \SplFileInfo[] + * @return array<\SplFileInfo> */ protected function _findPackageAssets(): array { diff --git a/src/Command/ModifyViewCommand.php b/src/Command/ModifyViewCommand.php index f1f3469e..3fb07dba 100644 --- a/src/Command/ModifyViewCommand.php +++ b/src/Command/ModifyViewCommand.php @@ -16,7 +16,7 @@ class ModifyViewCommand extends Command /** * @inheritDoc */ - public function execute(Arguments $args, ConsoleIo $io) + public function execute(Arguments $args, ConsoleIo $io): ?int { $io->info('Modifying view...'); @@ -86,9 +86,9 @@ protected function _isFile(string $filePath): bool * Reads a files contents. * * @param string $filePath The file path. - * @return false|string + * @return string|false */ - protected function _readFile(string $filePath) + protected function _readFile(string $filePath): false|string { return file_get_contents($filePath); } diff --git a/src/View/Helper/BreadcrumbsHelper.php b/src/View/Helper/BreadcrumbsHelper.php index c18657f6..c3bd89c6 100644 --- a/src/View/Helper/BreadcrumbsHelper.php +++ b/src/View/Helper/BreadcrumbsHelper.php @@ -12,7 +12,7 @@ class BreadcrumbsHelper extends CoreBreadcrumbsHelper /** * @inheritDoc */ - protected $_defaultConfig = [ + protected array $_defaultConfig = [ 'ariaCurrent' => 'last', 'templates' => [ 'wrapper' => '', @@ -27,7 +27,7 @@ class BreadcrumbsHelper extends CoreBreadcrumbsHelper * * @var array */ - protected $_defaultAttributes = [ + protected array $_defaultAttributes = [ 'class' => [ 'wrapper' => 'breadcrumb', 'item' => 'breadcrumb-item', diff --git a/src/View/Helper/FlashHelper.php b/src/View/Helper/FlashHelper.php index 95ec0155..4fc393fe 100644 --- a/src/View/Helper/FlashHelper.php +++ b/src/View/Helper/FlashHelper.php @@ -4,6 +4,7 @@ namespace BootstrapUI\View\Helper; use Cake\View\Helper; +use UnexpectedValueException; /** * FlashHelper class to render flash messages. @@ -20,7 +21,7 @@ class FlashHelper extends Helper * * @var array */ - protected $_defaultConfig = [ + protected array $_defaultConfig = [ 'class' => ['alert', 'alert-dismissible', 'fade', 'show', 'd-flex', 'align-items-center'], 'attributes' => ['role' => 'alert'], 'icon' => true, @@ -55,7 +56,7 @@ public function render(string $key = 'flash', array $options = []): ?string } if (!is_array($stack)) { - throw new \UnexpectedValueException(sprintf( + throw new UnexpectedValueException(sprintf( 'Value for flash setting key "%s" must be an array.', $key )); diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index c1d43f96..b26aa75d 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -6,11 +6,11 @@ use Cake\Core\Configure\Engine\PhpConfig; use Cake\Utility\Hash; use Cake\Utility\Inflector; -use Cake\View\Helper\FormHelper as Helper; +use Cake\View\Helper\FormHelper as CoreFormHelper; use Cake\View\View; use InvalidArgumentException; -class FormHelper extends Helper +class FormHelper extends CoreFormHelper { use OptionsAwareTrait; @@ -110,28 +110,28 @@ class FormHelper extends Helper * * @var string|null */ - protected $_align; + protected ?string $_align = null; /** * Set on `Form::create()` to tell grid type. * * @var array|null */ - protected $_grid; + protected ?array $_grid = null; /** * Set on `Form::create()` to tell the spacing type. * * @var string|false|null */ - protected $_spacing; + protected string|false|null $_spacing = null; /** * Default Bootstrap string templates. * * @var array */ - protected $_templates = [ + protected array $_templates = [ 'error' => '
{{content}}
', 'errorTooltip' => @@ -227,7 +227,7 @@ class FormHelper extends Helper * * @var array */ - protected $_templateSet = [ + protected array $_templateSet = [ 'default' => [ ], 'inline' => [ @@ -339,7 +339,7 @@ class FormHelper extends Helper * * @var array */ - protected $_widgets = [ + protected array $_widgets = [ 'button' => 'BootstrapUI\View\Widget\ButtonWidget', 'datetime' => 'BootstrapUI\View\Widget\DateTimeWidget', 'file' => ['BootstrapUI\View\Widget\FileWidget', 'label'], @@ -353,7 +353,7 @@ class FormHelper extends Helper * * @var string|null */ - private $_errorFieldName = null; + private ?string $_errorFieldName = null; /** * {@inheritDoc} @@ -400,7 +400,7 @@ public function __construct(View $View, array $config = []) * - `spacing` - The spacing to use for the form. Can be either a string to define a class, or boolean `false` to * disable automatic spacing class usage. */ - public function create($context = null, array $options = []): string + public function create(mixed $context = null, array $options = []): string { $options += [ 'class' => null, @@ -416,7 +416,7 @@ public function create($context = null, array $options = []): string /** * @inheritDoc */ - public function error(string $field, $text = null, array $options = []): string + public function error(string $field, array|string|null $text = null, array $options = []): string { $this->_errorFieldName = $field; $error = parent::error($field, $text, $options); @@ -1174,7 +1174,7 @@ protected function _postProcessElement(string $html, ?string $fieldName, array $ /** * @inheritDoc */ - public function checkbox(string $fieldName, array $options = []) + public function checkbox(string $fieldName, array $options = []): array|string { $options = $this->injectClasses('form-check-input', $options); @@ -1305,7 +1305,7 @@ public function staticControl(string $fieldName, array $options = []): string /** * @inheritDoc */ - protected function _getInput(string $fieldName, array $options) + protected function _getInput(string $fieldName, array $options): array|string { unset($options['help']); @@ -1527,9 +1527,9 @@ protected function _detectFormAlignment(array $options): string * May return `false` to indicate that no spacing should be used. * * @param string $align The alignment type for which to retrieve the spacing class. - * @return string|bool + * @return string|false */ - protected function _getSpacingForAlignment(string $align) + protected function _getSpacingForAlignment(string $align): string|false { $spacing = $this->getConfig('spacing'); @@ -1561,7 +1561,7 @@ protected function _getSpacingForAlignment(string $align) * * @return void */ - protected function _clearFormState() + protected function _clearFormState(): void { $this->_align = $this->_grid = diff --git a/src/View/Helper/HtmlHelper.php b/src/View/Helper/HtmlHelper.php index 8e80cf94..ce747d53 100644 --- a/src/View/Helper/HtmlHelper.php +++ b/src/View/Helper/HtmlHelper.php @@ -3,9 +3,10 @@ namespace BootstrapUI\View\Helper; +use Cake\View\Helper\HtmlHelper as CoreHtmlHelper; use Cake\View\View; -class HtmlHelper extends \Cake\View\Helper\HtmlHelper +class HtmlHelper extends CoreHtmlHelper { use OptionsAwareTrait; diff --git a/src/View/Helper/OptionsAwareTrait.php b/src/View/Helper/OptionsAwareTrait.php index 677c12b9..8aa771e2 100644 --- a/src/View/Helper/OptionsAwareTrait.php +++ b/src/View/Helper/OptionsAwareTrait.php @@ -57,7 +57,7 @@ public function renameClasses(string $element, array $options): array * @param array $options An array of HTML attributes and options. * @return bool True if any one of the class names was found. */ - public function hasAnyClass($classes, array $options): bool + public function hasAnyClass(array|string $classes, array $options): bool { $options += ['class' => []]; @@ -82,7 +82,7 @@ public function hasAnyClass($classes, array $options): bool * @param array $options An array of HTML attributes and options. * @return array An array of HTML attributes and options. */ - public function injectClasses($classes, array $options): array + public function injectClasses(array|string $classes, array $options): array { $options += ['class' => [], 'skip' => []]; @@ -109,7 +109,7 @@ public function injectClasses($classes, array $options): array * @param array $options An array of HTML attributes and options. * @return array An array of HTML attributes and options. */ - public function removeClasses($classes, array $options): array + public function removeClasses(array|string $classes, array $options): array { $options += ['class' => []]; @@ -137,7 +137,7 @@ public function removeClasses($classes, array $options): array * @param array $options An array of HTML attributes and options. * @return bool False if one or more class(es) do not exist. */ - public function checkClasses($classes, array $options): bool + public function checkClasses(array|string $classes, array $options): bool { if (empty($options['class'])) { return false; @@ -161,7 +161,7 @@ public function checkClasses($classes, array $options): bool * @param mixed $mixed One or more classes. * @return array Classes as array. */ - protected function _toClassArray($mixed): array + protected function _toClassArray(mixed $mixed): array { if ($mixed === null) { return []; @@ -178,9 +178,9 @@ protected function _toClassArray($mixed): array * * @param string $element UI element to which the class can be applied (e.g. btn). * @param string $class CSS class, which can be applied to the element. - * @return bool|string String of generated class, false if element/class not in list. + * @return string|bool String of generated class, false if element/class not in list. */ - public function genClassName(string $element, string $class) + public function genClassName(string $element, string $class): bool|string { if (!in_array($element, Element::values())) { return false; diff --git a/src/View/Helper/PaginatorHelper.php b/src/View/Helper/PaginatorHelper.php index 0672b3dc..a8f78d18 100644 --- a/src/View/Helper/PaginatorHelper.php +++ b/src/View/Helper/PaginatorHelper.php @@ -3,23 +3,24 @@ namespace BootstrapUI\View\Helper; +use Cake\View\Helper\PaginatorHelper as CorePaginatorHelper; use Cake\View\View; -class PaginatorHelper extends \Cake\View\Helper\PaginatorHelper +class PaginatorHelper extends CorePaginatorHelper { /** * Allowed sizes. * - * @var string[] + * @var array */ - protected $_allowedSizes = ['sm', 'lg']; + protected array $_allowedSizes = ['sm', 'lg']; /** * Label defaults. * * @var array */ - protected $_labels = [ + protected array $_labels = [ 'first' => [ 'label' => 'First', 'text' => '«', @@ -90,7 +91,7 @@ public function __construct(View $View, array $config = []) * - `templates` An array of templates, or template file name containing the templates you'd like to use when * generating the link for first page. This method uses the `first` template. */ - public function first($first = '«', array $options = []): string + public function first(string|int $first = '«', array $options = []): string { $options = $this->_templateOptions('first', $options); @@ -115,7 +116,7 @@ public function first($first = '«', array $options = []): string * - `templates` An array of templates, or template file name containing the templates you'd like to use when * generating the link for last page. This method uses the `last` template. */ - public function last($last = '»', array $options = []): string + public function last(string|int $last = '»', array $options = []): string { $options = $this->_templateOptions('last', $options); @@ -180,7 +181,7 @@ public function next(string $title = '›', array $options = []): string * @return string|false Pagination controls markup, or `false` in case of an invalid `size` option. * @link http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-page-number-links */ - public function links(array $options = []) + public function links(array $options = []): string|false { $class = 'pagination'; diff --git a/src/View/Widget/BasicWidget.php b/src/View/Widget/BasicWidget.php index d07b1f00..44ae395a 100644 --- a/src/View/Widget/BasicWidget.php +++ b/src/View/Widget/BasicWidget.php @@ -4,8 +4,9 @@ namespace BootstrapUI\View\Widget; use Cake\View\Form\ContextInterface; +use Cake\View\Widget\BasicWidget as CoreBasicWidget; -class BasicWidget extends \Cake\View\Widget\BasicWidget +class BasicWidget extends CoreBasicWidget { use InputGroupTrait; diff --git a/src/View/Widget/ButtonWidget.php b/src/View/Widget/ButtonWidget.php index 4fe7d6d8..979d86d7 100644 --- a/src/View/Widget/ButtonWidget.php +++ b/src/View/Widget/ButtonWidget.php @@ -5,8 +5,9 @@ use BootstrapUI\View\Helper\OptionsAwareTrait; use Cake\View\Form\ContextInterface; +use Cake\View\Widget\ButtonWidget as CoreButtonWidget; -class ButtonWidget extends \Cake\View\Widget\ButtonWidget +class ButtonWidget extends CoreButtonWidget { use OptionsAwareTrait; diff --git a/src/View/Widget/DateTimeWidget.php b/src/View/Widget/DateTimeWidget.php index ba95cb78..10cf30d0 100644 --- a/src/View/Widget/DateTimeWidget.php +++ b/src/View/Widget/DateTimeWidget.php @@ -4,8 +4,9 @@ namespace BootstrapUI\View\Widget; use Cake\View\Form\ContextInterface; +use Cake\View\Widget\DateTimeWidget as CoreDateTimeWidget; -class DateTimeWidget extends \Cake\View\Widget\DateTimeWidget +class DateTimeWidget extends CoreDateTimeWidget { use InputGroupTrait; diff --git a/src/View/Widget/FileWidget.php b/src/View/Widget/FileWidget.php index 9e73a26f..eb4af1ad 100644 --- a/src/View/Widget/FileWidget.php +++ b/src/View/Widget/FileWidget.php @@ -5,12 +5,13 @@ use Cake\View\Form\ContextInterface; use Cake\View\StringTemplate; +use Cake\View\Widget\FileWidget as CoreFileWidget; use Cake\View\Widget\LabelWidget; /** * Input widget class for generating a file upload control. */ -class FileWidget extends \Cake\View\Widget\FileWidget +class FileWidget extends CoreFileWidget { use InputGroupTrait; @@ -19,7 +20,7 @@ class FileWidget extends \Cake\View\Widget\FileWidget * * @var \Cake\View\Widget\LabelWidget */ - protected $_label; + protected LabelWidget $_label; /** * Constructor diff --git a/src/View/Widget/InputGroupTrait.php b/src/View/Widget/InputGroupTrait.php index a38179e5..40535c28 100644 --- a/src/View/Widget/InputGroupTrait.php +++ b/src/View/Widget/InputGroupTrait.php @@ -35,7 +35,7 @@ protected function _withInputGroup(array $data, ContextInterface $context): stri 'injectFormControl' => true, 'injectErrorClass' => null, 'input' => null, - 'templateVars' => null, + 'templateVars' => [], ]; if ($data['injectFormControl'] && $data['type'] !== 'hidden') { @@ -91,7 +91,7 @@ protected function _withInputGroup(array $data, ContextInterface $context): stri /** * Get addon HTML. * - * @param string[] $addons Addon content. + * @param array $addons Addon content. * @param array $data Widget data. * @return string */ @@ -129,7 +129,7 @@ protected function _isButton(string $html): bool * @param array|string $attachment prepend or append element. Can be a string or array, if contains options * @return array */ - protected function _checkForOptions($attachment): array + protected function _checkForOptions(array|string $attachment): array { $ret = []; diff --git a/src/View/Widget/SelectBoxWidget.php b/src/View/Widget/SelectBoxWidget.php index ee9329b4..5f00c6eb 100644 --- a/src/View/Widget/SelectBoxWidget.php +++ b/src/View/Widget/SelectBoxWidget.php @@ -4,8 +4,9 @@ namespace BootstrapUI\View\Widget; use Cake\View\Form\ContextInterface; +use Cake\View\Widget\SelectBoxWidget as CoreSelectBoxWidget; -class SelectBoxWidget extends \Cake\View\Widget\SelectBoxWidget +class SelectBoxWidget extends CoreSelectBoxWidget { use InputGroupTrait; diff --git a/src/View/Widget/TextareaWidget.php b/src/View/Widget/TextareaWidget.php index e9b83b63..7b6fbf56 100644 --- a/src/View/Widget/TextareaWidget.php +++ b/src/View/Widget/TextareaWidget.php @@ -4,6 +4,7 @@ namespace BootstrapUI\View\Widget; use Cake\View\Form\ContextInterface; +use Cake\View\Widget\TextareaWidget as CoreTextareaWidget; /** * Input widget class for generating a textarea control. @@ -11,7 +12,7 @@ * This class is intended as an internal implementation detail * of Cake\View\Helper\FormHelper and is not intended for direct use. */ -class TextareaWidget extends \Cake\View\Widget\TextareaWidget +class TextareaWidget extends CoreTextareaWidget { use InputGroupTrait; diff --git a/tests/Fixture/ArticlesFixture.php b/tests/Fixture/ArticlesFixture.php index 796987ca..c222e253 100644 --- a/tests/Fixture/ArticlesFixture.php +++ b/tests/Fixture/ArticlesFixture.php @@ -5,14 +5,4 @@ class ArticlesFixture extends TestFixture { - public $fields = [ - 'id' => ['type' => 'integer'], - 'author_id' => ['type' => 'integer', 'null' => true], - 'title' => ['type' => 'string', 'null' => true], - 'body' => 'text', - '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], - ]; - - public $records = [ - ]; } diff --git a/tests/Fixture/AuthorsFixture.php b/tests/Fixture/AuthorsFixture.php index 9fafc0d1..0500a65e 100644 --- a/tests/Fixture/AuthorsFixture.php +++ b/tests/Fixture/AuthorsFixture.php @@ -5,12 +5,4 @@ class AuthorsFixture extends TestFixture { - public $fields = [ - 'id' => ['type' => 'integer'], - 'name' => ['type' => 'string', 'default' => null], - '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], - ]; - - public $records = [ - ]; } diff --git a/tests/TestCase/Bake/BakeTest.php b/tests/TestCase/Bake/BakeTest.php index 4a7424e1..27d8803e 100644 --- a/tests/TestCase/Bake/BakeTest.php +++ b/tests/TestCase/Bake/BakeTest.php @@ -4,8 +4,8 @@ namespace BootstrapUI\Test\TestCase\Bake; use Cake\Command\Command; +use Cake\Console\TestSuite\ConsoleIntegrationTestTrait; use Cake\Core\Plugin; -use Cake\TestSuite\ConsoleIntegrationTestTrait; use Cake\TestSuite\StringCompareTrait; use Cake\TestSuite\TestCase; @@ -14,9 +14,9 @@ class BakeTest extends TestCase use ConsoleIntegrationTestTrait; use StringCompareTrait; - protected $generatedFile = ''; + protected string $generatedFile = ''; - protected $fixtures = [ + protected array $fixtures = [ 'plugin.BootstrapUI.Articles', 'plugin.BootstrapUI.Authors', ]; @@ -33,7 +33,6 @@ public function setUp(): void 'bootstrap' => true, ], ]); - $this->useCommandRunner(); } public function tearDown(): void diff --git a/tests/TestCase/Command/BootstrapCommandTest.php b/tests/TestCase/Command/BootstrapCommandTest.php index fd856e45..a7b81d12 100644 --- a/tests/TestCase/Command/BootstrapCommandTest.php +++ b/tests/TestCase/Command/BootstrapCommandTest.php @@ -3,25 +3,13 @@ namespace BootstrapUI\Test\TestCase\Command; -use Cake\TestSuite\ConsoleIntegrationTestTrait; +use Cake\Console\TestSuite\ConsoleIntegrationTestTrait; use Cake\TestSuite\TestCase; class BootstrapCommandTest extends TestCase { use ConsoleIntegrationTestTrait; - public function setUp(): void - { - parent::setUp(); - - $this->useCommandRunner(); - } - - public function tearDown(): void - { - parent::tearDown(); - } - public function testEntry() { $this->exec('bootstrap'); diff --git a/tests/TestCase/Command/CopyLayoutsCommandTest.php b/tests/TestCase/Command/CopyLayoutsCommandTest.php index be514904..a40e4231 100644 --- a/tests/TestCase/Command/CopyLayoutsCommandTest.php +++ b/tests/TestCase/Command/CopyLayoutsCommandTest.php @@ -8,23 +8,16 @@ use Cake\Console\Arguments; use Cake\Console\ConsoleIo; use Cake\Console\Exception\StopException; +use Cake\Console\TestSuite\ConsoleIntegrationTestTrait; +use Cake\Console\TestSuite\StubConsoleOutput; use Cake\Core\Plugin; -use Cake\Filesystem\Filesystem; -use Cake\TestSuite\ConsoleIntegrationTestTrait; -use Cake\TestSuite\Stub\ConsoleOutput; use Cake\TestSuite\TestCase; +use Cake\Utility\Filesystem; class CopyLayoutsCommandTest extends TestCase { use ConsoleIntegrationTestTrait; - public function setUp(): void - { - parent::setUp(); - - $this->useCommandRunner(); - } - public function tearDown(): void { parent::tearDown(); @@ -53,9 +46,9 @@ public function testCopyLayouts() Plugin::path('BootstrapUI') . 'tests' . DS . 'test_app' . DS . 'templates' . DS . 'layout' . DS . 'TwitterBootstrap' . DS; - $this->assertFileNotExists($targetPath . 'cover.php'); - $this->assertFileNotExists($targetPath . 'dashboard.php'); - $this->assertFileNotExists($targetPath . 'signin.php'); + $this->assertFileDoesNotExist($targetPath . 'cover.php'); + $this->assertFileDoesNotExist($targetPath . 'dashboard.php'); + $this->assertFileDoesNotExist($targetPath . 'signin.php'); $this->exec('bootstrap copy_layouts'); @@ -88,9 +81,9 @@ public function testCustomTargetPath() $compatTargetPath = substr($targetPath, 0, -1); - $this->assertFileNotExists($targetPath . 'cover.php'); - $this->assertFileNotExists($targetPath . 'dashboard.php'); - $this->assertFileNotExists($targetPath . 'signin.php'); + $this->assertFileDoesNotExist($targetPath . 'cover.php'); + $this->assertFileDoesNotExist($targetPath . 'dashboard.php'); + $this->assertFileDoesNotExist($targetPath . 'signin.php'); $this->exec('bootstrap copy_layouts ' . escapeshellarg($compatTargetPath)); @@ -127,8 +120,8 @@ public function testFilesCannotBeCopied() $args = new Arguments([], [], []); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $io = new ConsoleIo($out, $err); try { diff --git a/tests/TestCase/Command/InstallCommandTest.php b/tests/TestCase/Command/InstallCommandTest.php index 8886ee15..d88bd324 100644 --- a/tests/TestCase/Command/InstallCommandTest.php +++ b/tests/TestCase/Command/InstallCommandTest.php @@ -8,24 +8,17 @@ use Cake\Console\Arguments; use Cake\Console\ConsoleIo; use Cake\Console\Exception\StopException; +use Cake\Console\TestSuite\ConsoleIntegrationTestTrait; +use Cake\Console\TestSuite\StubConsoleOutput; use Cake\Core\Plugin; -use Cake\Filesystem\Filesystem; -use Cake\TestSuite\ConsoleIntegrationTestTrait; -use Cake\TestSuite\Stub\ConsoleOutput; use Cake\TestSuite\TestCase; +use Cake\Utility\Filesystem; use SplFileInfo; class InstallCommandTest extends TestCase { use ConsoleIntegrationTestTrait; - public function setUp(): void - { - parent::setUp(); - - $this->useCommandRunner(); - } - public function testInstall() { $pluginWebrootPath = Plugin::path('BootstrapUI') . 'webroot' . DS; @@ -35,7 +28,7 @@ public function testInstall() $filesystem = new Filesystem(); $filesystem->deleteDir($appWebrootPath); - $this->assertDirectoryNotExists($appWebrootPath); + $this->assertDirectoryDoesNotExist($appWebrootPath); $this->exec('bootstrap install'); @@ -467,8 +460,8 @@ public function testNPMNotAvailable() ->method('_isNPMAvailable') ->willReturn(false); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $args = new Arguments([], [], []); $io = new ConsoleIo($out, $err); @@ -499,8 +492,8 @@ public function testDeleteNodeModulesFailure() ->method('_deleteNodeModules') ->willReturn(false); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $args = new Arguments([], [], []); $io = new ConsoleIo($out, $err); @@ -538,8 +531,8 @@ public function testChangeWorkingDirectoryFailure() ->method('_changeWorkingDirectory') ->willReturn(false); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $args = new Arguments([], [], []); $io = new ConsoleIo($out, $err); @@ -588,8 +581,8 @@ public function testNPMInstallFailure() $return = 1234; })); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $args = new Arguments([], [], []); $io = new ConsoleIo($out, $err); @@ -635,8 +628,8 @@ public function testDeleteBufferedPackageAssetsFailure() new SplFileInfo(TMP . 'script.js'), ]); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $io = new ConsoleIo($out, $err); try { @@ -686,8 +679,8 @@ public function testBufferPackageAssetsSkipUnsupportedFileTypes() new SplFileInfo(TMP . 'script.js'), ]); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $io = new ConsoleIo($out, $err); $io->level(ConsoleIo::VERBOSE); @@ -731,8 +724,8 @@ public function testBufferPackageAssetsFailure() new SplFileInfo(TMP . 'non-existent.css'), ]); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $io = new ConsoleIo($out, $err); try { @@ -771,8 +764,8 @@ public function testRemovePluginAssetsFailure() ->method('executeCommand') ->willReturn(1234); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $io = new ConsoleIo($out, $err); try { @@ -805,8 +798,8 @@ public function testLinkPluginAssetsFailure() ->method('executeCommand') ->willReturn(1234); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $io = new ConsoleIo($out, $err); try { diff --git a/tests/TestCase/Command/ModifyViewCommandTest.php b/tests/TestCase/Command/ModifyViewCommandTest.php index d1b570cb..ad76f9b6 100644 --- a/tests/TestCase/Command/ModifyViewCommandTest.php +++ b/tests/TestCase/Command/ModifyViewCommandTest.php @@ -8,22 +8,15 @@ use Cake\Console\Arguments; use Cake\Console\ConsoleIo; use Cake\Console\Exception\StopException; +use Cake\Console\TestSuite\ConsoleIntegrationTestTrait; +use Cake\Console\TestSuite\StubConsoleOutput; use Cake\Core\Plugin; -use Cake\TestSuite\ConsoleIntegrationTestTrait; -use Cake\TestSuite\Stub\ConsoleOutput; use Cake\TestSuite\TestCase; class ModifyViewCommandTest extends TestCase { use ConsoleIntegrationTestTrait; - public function setUp(): void - { - parent::setUp(); - - $this->useCommandRunner(); - } - public function tearDown(): void { parent::tearDown(); @@ -127,8 +120,8 @@ public function testPathIsNotAFile() $args = new Arguments([], [], []); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $io = new ConsoleIo($out, $err); try { @@ -165,8 +158,8 @@ public function testFileCannotBeRead() $args = new Arguments([], [], []); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $io = new ConsoleIo($out, $err); try { @@ -203,8 +196,8 @@ public function testFileCannotBeWritten() $args = new Arguments([], [], []); - $out = new ConsoleOutput(); - $err = new ConsoleOutput(); + $out = new StubConsoleOutput(); + $err = new StubConsoleOutput(); $io = new ConsoleIo($out, $err); try { diff --git a/tests/TestCase/View/Helper/FlashHelperTest.php b/tests/TestCase/View/Helper/FlashHelperTest.php index d4b44e0a..f03f062a 100644 --- a/tests/TestCase/View/Helper/FlashHelperTest.php +++ b/tests/TestCase/View/Helper/FlashHelperTest.php @@ -8,6 +8,7 @@ use Cake\Http\Session; use Cake\TestSuite\TestCase; use Cake\View\View; +use UnexpectedValueException; /** * FlashHelperTest class @@ -166,7 +167,7 @@ public function testRenderNonExistentKey() public function testRenderInvalidKey() { - $this->expectException(\UnexpectedValueException::class); + $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('Value for flash setting key "invalidKey" must be an array.'); $this->View->getRequest()->getSession()->write('Flash', [ diff --git a/tests/TestCase/View/Helper/FormHelper/DefaultAlign/DateTimeControlTest.php b/tests/TestCase/View/Helper/FormHelper/DefaultAlign/DateTimeControlTest.php index c916c7a1..fd2099b8 100644 --- a/tests/TestCase/View/Helper/FormHelper/DefaultAlign/DateTimeControlTest.php +++ b/tests/TestCase/View/Helper/FormHelper/DefaultAlign/DateTimeControlTest.php @@ -4,6 +4,7 @@ namespace BootstrapUI\Test\TestCase\View\Helper\FormHelper\DefaultAlign; use BootstrapUI\Test\TestCase\View\Helper\FormHelper\AbstractFormHelperTest; +use DateTime; class DateTimeControlTest extends AbstractFormHelperTest { @@ -11,7 +12,7 @@ public function testDefaultAlignDateTimeControl() { $this->Form->create($this->article); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -39,7 +40,7 @@ public function testDefaultAlignDateTimeControlWithDisabledLabel() { $this->Form->create($this->article); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -67,7 +68,7 @@ public function testDefaultAlignDateTimeControlWithCustomLabel() { $this->Form->create($this->article); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -98,7 +99,7 @@ public function testDefaultAlignDateTimeControlWithCustomLabelOptions() { $this->Form->create($this->article); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -247,7 +248,7 @@ public function testDefaultAlignDateTimeControlWithCustomSpacing() { $this->Form->create($this->article); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -279,7 +280,7 @@ public function testDefaultAlignDateTimeControlWithError() ]; $this->Form->create($this->article); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -318,7 +319,7 @@ public function testDefaultAlignDateTimeControlWithErrorAndHelp() ]; $this->Form->create($this->article); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -360,7 +361,7 @@ public function testDefaultAlignDateTimeControlWithErrorAndHelpOptions() ]; $this->Form->create($this->article); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -408,7 +409,7 @@ public function testDefaultAlignDateTimeControlContainerOptions() { $this->Form->create($this->article); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -446,7 +447,7 @@ public function testDefaultAlignDateTimeControlContainerOptionsWithError() ]; $this->Form->create($this->article); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', diff --git a/tests/TestCase/View/Helper/FormHelper/HorizontalAlign/DateTimeControlTest.php b/tests/TestCase/View/Helper/FormHelper/HorizontalAlign/DateTimeControlTest.php index 0b7ff8a2..291f6304 100644 --- a/tests/TestCase/View/Helper/FormHelper/HorizontalAlign/DateTimeControlTest.php +++ b/tests/TestCase/View/Helper/FormHelper/HorizontalAlign/DateTimeControlTest.php @@ -5,6 +5,7 @@ use BootstrapUI\Test\TestCase\View\Helper\FormHelper\AbstractFormHelperTest; use BootstrapUI\View\Helper\FormHelper; +use DateTime; class DateTimeControlTest extends AbstractFormHelperTest { @@ -19,7 +20,7 @@ public function testHorizontalAlignDateTimeControl() ], ]); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -55,7 +56,7 @@ public function testHorizontalAlignDateTimeControlWithDisabledLabel() ], ]); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -89,7 +90,7 @@ public function testHorizontalAlignDateTimeControlWithCustomLabel() ], ]); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -126,7 +127,7 @@ public function testHorizontalAlignDateTimeControlWithCustomLabelOptions() ], ]); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -304,7 +305,7 @@ public function testHorizontalAlignDateTimeControlWithCustomSpacing() ], ]); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -344,7 +345,7 @@ public function testHorizontalAlignDateTimeControlWithError() ], ]); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -391,7 +392,7 @@ public function testHorizontalAlignDateTimeControlWithErrorAndHelp() ], ]); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -441,7 +442,7 @@ public function testHorizontalAlignDateTimeControlWithErrorAndHelpOptions() ], ]); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -497,7 +498,7 @@ public function testHorizontalAlignDateTimeControlContainerOptions() ], ]); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -543,7 +544,7 @@ public function testHorizontalAlignDateTimeControlContainerOptionsWithError() ], ]); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', diff --git a/tests/TestCase/View/Helper/FormHelper/InlineAlign/DateTimeControlTest.php b/tests/TestCase/View/Helper/FormHelper/InlineAlign/DateTimeControlTest.php index 420e1429..8673f25f 100644 --- a/tests/TestCase/View/Helper/FormHelper/InlineAlign/DateTimeControlTest.php +++ b/tests/TestCase/View/Helper/FormHelper/InlineAlign/DateTimeControlTest.php @@ -4,6 +4,7 @@ namespace BootstrapUI\Test\TestCase\View\Helper\FormHelper\InlineAlign; use BootstrapUI\Test\TestCase\View\Helper\FormHelper\AbstractFormHelperTest; +use DateTime; class DateTimeControlTest extends AbstractFormHelperTest { @@ -15,7 +16,7 @@ public function testInlineAlignDateTimeControl() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -48,7 +49,7 @@ public function testInlineAlignDateTimeControlWithDisabledLabel() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -79,7 +80,7 @@ public function testInlineAlignDateTimeControlWithCustomLabel() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -113,7 +114,7 @@ public function testInlineAlignDateTimeControlWithCustomLabelOptions() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -155,7 +156,7 @@ public function testInlineAlignDateTimeControlWithHelp() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -193,7 +194,7 @@ public function testInlineAlignDateTimeControlWithHelpOptions() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -240,7 +241,7 @@ public function testInlineAlignDateTimeControlWithTooltip() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -283,7 +284,7 @@ public function testInlineAlignDateTimeControlWithError() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -323,7 +324,7 @@ public function testInlineAlignDateTimeControlContainerOptions() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -366,7 +367,7 @@ public function testInlineAlignDateTimeControlWithErrorAndHelp() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -413,7 +414,7 @@ public function testInlineAlignDateTimeControlWithErrorAndHelpOptions() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', @@ -472,7 +473,7 @@ public function testInlineAlignDateTimeControlContainerOptionsWithError() ]); }); - $now = new \DateTime('now'); + $now = new DateTime('now'); $result = $this->Form->control('created', [ 'type' => 'datetime-local', diff --git a/tests/TestCase/View/Helper/PaginatorHelperTest.php b/tests/TestCase/View/Helper/PaginatorHelperTest.php index b739587c..524cafe9 100644 --- a/tests/TestCase/View/Helper/PaginatorHelperTest.php +++ b/tests/TestCase/View/Helper/PaginatorHelperTest.php @@ -4,7 +4,9 @@ namespace BootstrapUI\Test\TestCase\View\Helper; use BootstrapUI\View\Helper\PaginatorHelper; +use Cake\Datasource\Paging\PaginatedResultSet; use Cake\Http\ServerRequest; +use Cake\ORM\ResultSet; use Cake\Routing\Router; use Cake\TestSuite\TestCase; use Cake\View\View; @@ -14,15 +16,11 @@ */ class PaginatorHelperTest extends TestCase { - /** - * @var View - */ - public $View; + protected View $View; - /** - * @var PaginatorHelper - */ - public $Paginator; + protected PaginatorHelper $Paginator; + + protected PaginatedResultSet $paginatedResult; /** * setUp method @@ -42,19 +40,10 @@ public function setUp(): void 'pass' => [], ], ]); - $request = $request->withAttribute('paging', [ - 'Client' => [ - 'page' => 2, - 'current' => 1, - 'count' => 3, - 'prevPage' => 1, - 'nextPage' => 3, - 'pageCount' => 3, - ], - ]); $this->View = new View($request); $this->Paginator = new PaginatorHelper($this->View); + $this->setPaginatedResult([]); $routeBuilder = Router::createRouteBuilder('/'); $routeBuilder->connect('/{controller}/{action}/*'); @@ -72,6 +61,25 @@ public function tearDown(): void unset($this->View, $this->Paginator); } + protected function setPaginatedResult(array $params, bool $merge = true): void + { + if ($merge) { + $params += [ + 'alias' => 'Clients', + 'currentPage' => 2, + 'count' => 1, + 'totalCount' => 3, + 'hasPrevPage' => true, + 'hasNextPage' => true, + 'pageCount' => 3, + ]; + } + + $this->paginatedResult = new PaginatedResultSet(new ResultSet([]), $params); + + $this->Paginator->setPaginated($this->paginatedResult); + } + public function testLinksDefaults(): void { $result = $this->Paginator->links(); @@ -212,14 +220,10 @@ public function testLinksCustomTextAndLabels(): void public function testLinksNoPreviousNext(): void { - $request = $this->Paginator->getView()->getRequest(); - $request = $request->withAttribute('paging', [ - 'Client' => [ - 'prevPage' => false, - 'nextPage' => false, - ] + $request->getAttribute('paging')['Client'], + $this->setPaginatedResult([ + 'hasPrevPage' => false, + 'hasNextPage' => false, ]); - $this->Paginator->getView()->setRequest($request); $result = $this->Paginator->links(['prev' => true, 'next' => true, 'first' => true, 'last' => true]); $expected = [ @@ -562,13 +566,9 @@ public function testPrevCustomTemplate() public function testPrevDisabledCustomTemplate() { - $request = $this->Paginator->getView()->getRequest(); - $request = $request->withAttribute('paging', [ - 'Client' => [ - 'prevPage' => false, - ] + $request->getAttribute('paging')['Client'], + $this->setPaginatedResult([ + 'hasPrevPage' => false, ]); - $this->Paginator->getView()->setRequest($request); $result = $this->Paginator->prev('‹', [ 'templates' => [ @@ -630,13 +630,9 @@ public function testNextCustomTemplate() public function testNextDisabledCustomTemplate() { - $request = $this->Paginator->getView()->getRequest(); - $request = $request->withAttribute('paging', [ - 'Client' => [ - 'nextPage' => false, - ] + $request->getAttribute('paging')['Client'], + $this->setPaginatedResult([ + 'hasNextPage' => false, ]); - $this->Paginator->getView()->setRequest($request); $result = $this->Paginator->next('›', [ 'templates' => [ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f5e20bef..1958d59e 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,10 +1,13 @@ 'css/', 'paths' => [ 'plugins' => [dirname(APP) . DS . 'plugins' . DS], - 'templates' => [TEST_APP . 'templates' . DS] - ] -]); -Configure::write('Error', [ - 'ignoredDeprecationPaths' => [ - 'vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php', + 'templates' => [TEST_APP . 'templates' . DS], ], ]); @@ -77,13 +75,13 @@ '_cake_core_' => [ 'engine' => 'File', 'prefix' => 'cake_core_', - 'serialize' => true + 'serialize' => true, ], '_cake_model_' => [ 'engine' => 'File', 'prefix' => 'cake_model_', - 'serialize' => true - ] + 'serialize' => true, + ], ]); if (!getenv('db_dsn')) { @@ -91,10 +89,11 @@ } ConnectionManager::setConfig('test', ['url' => getenv('db_dsn')]); -Plugin::getCollection()->add(new \BootstrapUI\Plugin(['path' => ROOT . DS])); -Plugin::getCollection()->add(new \Bake\Plugin()); +Plugin::getCollection()->add(new BootstrapUIPlugin(['path' => ROOT . DS])); +Plugin::getCollection()->add(new BakePlugin()); -Configure::write( - 'Error.ignoredDeprecationPaths', - ['vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php'] -); +// Create test database schema +if (env('FIXTURE_SCHEMA_METADATA')) { + $loader = new SchemaLoader(); + $loader->loadInternalFile(env('FIXTURE_SCHEMA_METADATA')); +} diff --git a/tests/schema.php b/tests/schema.php new file mode 100644 index 00000000..9dd8b8ac --- /dev/null +++ b/tests/schema.php @@ -0,0 +1,23 @@ + 'articles', + 'columns' => [ + 'id' => ['type' => 'integer'], + 'author_id' => ['type' => 'integer', 'null' => true], + 'title' => ['type' => 'string', 'null' => true], + 'body' => 'text', + ], + 'constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], + ], + [ + 'table' => 'authors', + 'columns' => [ + 'id' => ['type' => 'integer'], + 'name' => ['type' => 'string', 'default' => null], + ], + 'constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]], + ], +]; diff --git a/tests/test_app/TestApp/Application.php b/tests/test_app/TestApp/Application.php index b0f45b57..0997af65 100644 --- a/tests/test_app/TestApp/Application.php +++ b/tests/test_app/TestApp/Application.php @@ -18,6 +18,7 @@ use Cake\Error\Middleware\ErrorHandlerMiddleware; use Cake\Http\BaseApplication; +use Cake\Http\MiddlewareQueue; use Cake\Routing\Middleware\AssetMiddleware; use Cake\Routing\Middleware\RoutingMiddleware; @@ -50,7 +51,7 @@ public function bootstrap(): void * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to setup. * @return \Cake\Http\MiddlewareQueue The updated middleware queue. */ - public function middleware(\Cake\Http\MiddlewareQueue $middlewareQueue): \Cake\Http\MiddlewareQueue + public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue { $middlewareQueue // Catch any exceptions in the lower layers, From 259307f8cf3d9a183d5ab942b8b7e06f74c160ac Mon Sep 17 00:00:00 2001 From: cewi Date: Sun, 16 Jul 2023 14:13:25 +0200 Subject: [PATCH 2/8] Update README.md fix that this branch is for Cake 5 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f90e8bfd..08800b0d 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ [package]: https://packagist.org/packages/friendsofcake/bootstrap-ui [license]: LICENSE.txt -Transparently use [Bootstrap 5][bs] with [CakePHP 4][cakephp]. +Transparently use [Bootstrap 5][bs] with [CakePHP 5][cakephp]. For version info see [version map](https://github.com/FriendsOfCake/bootstrap-ui/wiki#version-map). ## Requirements -* CakePHP 4.x +* CakePHP 5.x * Bootstrap 5.x * npm 6.x * Popper.js 2.x From f8d541e472e164d037533ba5867e9404c806ecfb Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 17 Jul 2023 18:58:05 +0530 Subject: [PATCH 3/8] Update for phpunit 10 and namespaced functions --- .github/workflows/ci.yml | 63 +++---------------- .gitignore | 1 + composer.json | 6 +- phpunit.xml.dist | 22 +++---- src/View/Helper/FormHelper.php | 2 + src/View/Helper/PaginatorHelper.php | 1 + templates/element/flash/default.php | 1 + .../TestCase/View/Helper/FlashHelperTest.php | 4 +- tests/bootstrap.php | 10 +-- 9 files changed, 29 insertions(+), 81 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb3d0333..9ae4a913 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,66 +8,17 @@ on: branches: - '*' +permissions: + contents: read + jobs: testsuite: - runs-on: ubuntu-20.04 - strategy: - fail-fast: false - matrix: - php-version: ['8.1', '8.2'] - prefer-lowest: [''] - include: - - php-version: '8.1' - prefer-lowest: 'prefer-lowest' - - services: - postgres: - image: postgres - ports: - - 5432:5432 - env: - POSTGRES_PASSWORD: postgres - - steps: - - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, intl - coverage: pcov - - - name: Composer install - run: | - if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then - composer update --prefer-lowest --prefer-stable - elif ${{ matrix.php-version == '8.2' }}; then - composer update --ignore-platform-req=php - else - composer update - fi - - - name: Setup problem matchers for PHPUnit - if: matrix.php-version == '8.1' - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Run PHPUnit - run: | - if [[ ${{ matrix.php-version }} == '8.1' ]]; then - vendor/bin/phpunit --coverage-clover=coverage.xml - else - vendor/bin/phpunit - fi - continue-on-error: ${{ matrix.prefer-lowest == 'prefer-lowest' }} - - - name: Code Coverage Report - if: matrix.php-version == '8.1' - uses: codecov/codecov-action@v3 + uses: cakephp/.github/.github/workflows/testsuite-with-db.yml@5.x + secrets: inherit cs-stan: name: Coding Standard & Static Analysis - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 @@ -78,7 +29,7 @@ jobs: php-version: '8.1' extensions: mbstring, intl coverage: none - tools: cs2pr, vimeo/psalm:4.23, phpstan:1.7 + tools: cs2pr, vimeo/psalm:5, phpstan:1.10 - name: Composer Install run: composer install diff --git a/.gitignore b/.gitignore index 6fb0d54c..0c225561 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ vendor/ composer.lock node_modules .phpunit.result.cache +.phpunit.cache # Generated test files tests/test_app/webroot/bootstrap_u_i diff --git a/composer.json b/composer.json index 6285fa05..8b43ca23 100644 --- a/composer.json +++ b/composer.json @@ -20,9 +20,9 @@ "cakephp/cakephp": "5.x-dev" }, "require-dev": { - "phpunit/phpunit": "^9.5.19", - "cakephp/bake": "dev-cake5", - "cakephp/cakephp-codesniffer": "5.x-dev" + "phpunit/phpunit": "^10.1", + "cakephp/bake": "3.x-dev", + "cakephp/cakephp-codesniffer": "^5.0" }, "support": { "issues": "http://github.com/friendsofcake/bootstrap-ui/issues", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b3e1dd7e..fb379f75 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,27 +1,19 @@ - - + tests/TestCase/ - - + - - - - src/ - - - + + + src/ + + diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index b26aa75d..20f5d10c 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -9,6 +9,8 @@ use Cake\View\Helper\FormHelper as CoreFormHelper; use Cake\View\View; use InvalidArgumentException; +use function Cake\Core\h; +use function Cake\I18n\__; class FormHelper extends CoreFormHelper { diff --git a/src/View/Helper/PaginatorHelper.php b/src/View/Helper/PaginatorHelper.php index a8f78d18..a6e7c6d7 100644 --- a/src/View/Helper/PaginatorHelper.php +++ b/src/View/Helper/PaginatorHelper.php @@ -5,6 +5,7 @@ use Cake\View\Helper\PaginatorHelper as CorePaginatorHelper; use Cake\View\View; +use function Cake\Core\h; class PaginatorHelper extends CorePaginatorHelper { diff --git a/templates/element/flash/default.php b/templates/element/flash/default.php index 76fe7c90..9f615a27 100644 --- a/templates/element/flash/default.php +++ b/templates/element/flash/default.php @@ -4,6 +4,7 @@ * @var array $params * @var string $message */ +use function Cake\Core\h; $icon = $params['icon']; $class = array_unique((array)$params['class']); diff --git a/tests/TestCase/View/Helper/FlashHelperTest.php b/tests/TestCase/View/Helper/FlashHelperTest.php index f03f062a..30f899dc 100644 --- a/tests/TestCase/View/Helper/FlashHelperTest.php +++ b/tests/TestCase/View/Helper/FlashHelperTest.php @@ -51,7 +51,7 @@ public function tearDown(): void unset($this->View, $this->Flash); } - public function flashTypeDefaultsDataProvider(): array + public static function flashTypeDefaultsDataProvider(): array { return [ ['default', 'info', 'info-circle-fill'], @@ -433,7 +433,7 @@ public function testCustomHtmlIcon() $this->assertHtml($expected, $result, true); } - public function flashTypeDataProvider(): array + public static function flashTypeDataProvider(): array { return [ ['default'], diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1958d59e..3d5b9b25 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -84,16 +84,16 @@ ], ]); -if (!getenv('db_dsn')) { - putenv('db_dsn=sqlite:///:memory:'); +if (!getenv('DB_URL')) { + putenv('DB_URL=sqlite:///:memory:'); } -ConnectionManager::setConfig('test', ['url' => getenv('db_dsn')]); +ConnectionManager::setConfig('test', ['url' => getenv('DB_URL')]); Plugin::getCollection()->add(new BootstrapUIPlugin(['path' => ROOT . DS])); Plugin::getCollection()->add(new BakePlugin()); // Create test database schema -if (env('FIXTURE_SCHEMA_METADATA')) { +if (getenv('FIXTURE_SCHEMA_METADATA')) { $loader = new SchemaLoader(); - $loader->loadInternalFile(env('FIXTURE_SCHEMA_METADATA')); + $loader->loadInternalFile(getenv('FIXTURE_SCHEMA_METADATA')); } From 434ea3101303fe9e8858e0f10f6a5f8b75624eb3 Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 17 Jul 2023 18:59:07 +0530 Subject: [PATCH 4/8] update psalm config --- psalm.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/psalm.xml b/psalm.xml index 12c5ed33..bb4ae33a 100644 --- a/psalm.xml +++ b/psalm.xml @@ -6,6 +6,8 @@ xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" autoloader="tests/bootstrap.php" + findUnusedBaselineEntry="false" + findUnusedCode="false" > From d6223ef626f87d0af06dd03b35e15d4252d49522 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 13 Sep 2023 21:34:50 +0530 Subject: [PATCH 5/8] Exclude abstract class from testsuite. --- phpunit.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fb379f75..0c8957f8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,6 +3,7 @@ tests/TestCase/ + tests/TestCase/View/Helper/FormHelper/AbstractFormHelperTest.php From c3296af1e78e6472dd8c3d9f82d73b340e5ed328 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 13 Sep 2023 21:36:24 +0530 Subject: [PATCH 6/8] Update deps to stable releases. --- composer.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 8b43ca23..d2536c7e 100644 --- a/composer.json +++ b/composer.json @@ -17,11 +17,11 @@ } ], "require": { - "cakephp/cakephp": "5.x-dev" + "cakephp/cakephp": "^5.0" }, "require-dev": { "phpunit/phpunit": "^10.1", - "cakephp/bake": "3.x-dev", + "cakephp/bake": "^3.0", "cakephp/cakephp-codesniffer": "^5.0" }, "support": { @@ -52,7 +52,5 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } - }, - "minimum-stability": "dev", - "prefer-stable": true + } } From 896b39a8f1fda9e8e4d5fafa450f4dffbf113538 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 13 Sep 2023 21:39:42 +0530 Subject: [PATCH 7/8] Update to actions/checkout v4 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ae4a913..40117ba5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 From 02f60d4b36e48829e07ed7a110065d58ac28bd61 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 13 Sep 2023 21:46:47 +0530 Subject: [PATCH 8/8] Fix badge URL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 08800b0d..6852a8eb 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Total Downloads][ico-downloads]][package] [![License][ico-license]][license] -[ico-ga]: https://img.shields.io/github/workflow/status/FriendsOfCake/bootstrap-ui/CI/master?style=flat-square +[ico-ga]: https://img.shields.io/github/actions/workflow/status/friendsofcake/bootstrap-ui/ci.yml?style=flat-square [ico-coverage]: https://img.shields.io/codecov/c/github/FriendsOfCake/bootstrap-ui.svg?style=flat-square [ico-downloads]: https://img.shields.io/packagist/dt/friendsofcake/bootstrap-ui.svg?style=flat-square [ico-license]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square