phpcbf and added .gitea workflows
This commit is contained in:
@@ -12,8 +12,8 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
php-version: ['8.2', '8.4']
|
||||
db-type: ['mysql']
|
||||
# db-type: ['sqlite', 'mysql', 'pgsql']
|
||||
# db-type: ['mysql']
|
||||
db-type: ['sqlite', 'mysql', 'pgsql']
|
||||
prefer-lowest: ['']
|
||||
include:
|
||||
- php-version: '8.2'
|
||||
@@ -33,13 +33,6 @@ jobs:
|
||||
# - 5432:5432
|
||||
# env:
|
||||
# POSTGRES_PASSWORD: postgres
|
||||
# mysql8:
|
||||
# image: mysql:8.0
|
||||
# env:
|
||||
# MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
||||
# MYSQL_DATABASE: test_db
|
||||
# ports:
|
||||
# - 3306:3306
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -47,7 +40,7 @@ jobs:
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-version }}
|
||||
extensions: mbstring, intl, sqlite, pdo_${{ matrix.db-type }}
|
||||
extensions: mbstring, intl, bcmath, sqlite, pdo_${{ matrix.db-type }}
|
||||
coverage: pcov
|
||||
|
||||
- name: Get composer cache directory
|
||||
@@ -108,8 +101,8 @@ jobs:
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
extensions: mbstring, intl, sqlite
|
||||
php-version: '8.2'
|
||||
extensions: mbstring, intl, sqlite, bcmath
|
||||
coverage: none
|
||||
|
||||
- name: Get composer cache directory
|
||||
@@ -133,11 +126,8 @@ jobs:
|
||||
composer install --no-progress --prefer-dist --optimize-autoloader
|
||||
fi
|
||||
|
||||
- name: Composer phpstan setup
|
||||
run: composer stan-setup
|
||||
|
||||
- name: Run phpstan
|
||||
run: vendor/bin/phpstan analyse --error-format=github
|
||||
run: vendor/bin/phpstan analyse src --error-format=github
|
||||
|
||||
- name: Run phpcs
|
||||
run: composer cs-check
|
||||
17
.gitea/workflows/release.yaml
Normal file
17
.gitea/workflows/release.yaml
Normal file
@@ -0,0 +1,17 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
|
||||
|
||||
@@ -8,11 +8,15 @@
|
||||
"php": ">=8.2",
|
||||
"dereuromark/cakephp-tools": "^3.9",
|
||||
"muffin/trash": "^4.2",
|
||||
"cakephp/cakephp": "^5.0.1"
|
||||
"cakephp/cakephp": "^5.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^10.1",
|
||||
"cakephp/migrations": "^4.0.0"
|
||||
"cakephp/migrations": "^4.0.0",
|
||||
"phpstan/phpstan": "^2.1",
|
||||
"dereuromark/composer-prefer-lowest": "^0.1.10",
|
||||
"cakedc/cakephp-phpstan": "^4.1",
|
||||
"fig-r/psr2r-sniffer": "^2.7"
|
||||
},
|
||||
"suggest": {
|
||||
"hi-powered-dev/cake-products": "Manage products and SKUs with a heirarhical category structure, includes attributes and variants"
|
||||
@@ -28,5 +32,17 @@
|
||||
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/",
|
||||
"TestApp\\": "tests/test_app/src/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"cs-check": "vendor/bin/phpcs --colors --parallel=16",
|
||||
"cs-fix": "vendor/bin/phpcbf --colors --parallel=16",
|
||||
"lowest": "validate-prefer-lowest",
|
||||
"lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json",
|
||||
"stan": "phpstan analyze"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
class CreateCarts extends BaseMigration
|
||||
{
|
||||
class CreateCarts extends BaseMigration {
|
||||
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
@@ -12,8 +12,7 @@ class CreateCarts extends BaseMigration
|
||||
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
|
||||
* @return void
|
||||
*/
|
||||
public function change(): void
|
||||
{
|
||||
public function change(): void {
|
||||
$table = $this->table('carts', ['id' => false, 'primary_key' => ['id']]);
|
||||
$table->addColumn('id', 'uuid', [
|
||||
'default' => null,
|
||||
@@ -111,4 +110,5 @@ class CreateCarts extends BaseMigration
|
||||
|
||||
$table->create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
21
phpcs.xml
Normal file
21
phpcs.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="plugin">
|
||||
<arg value="nps"/>
|
||||
|
||||
<file>src/</file>
|
||||
<file>config/</file>
|
||||
<file>tests/</file>
|
||||
|
||||
<exclude-pattern>/tests/test_files/</exclude-pattern>
|
||||
<exclude-pattern>/tests/test_app/</exclude-pattern>
|
||||
|
||||
<rule ref="vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml"/>
|
||||
|
||||
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
|
||||
<exclude-pattern>*/config/Migrations/*</exclude-pattern>
|
||||
</rule>
|
||||
<rule ref="PhpCollective.Classes.ClassFileName.NoMatch">
|
||||
<exclude-pattern>*/config/Migrations/*</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
10
phpstan.neon
Normal file
10
phpstan.neon
Normal file
@@ -0,0 +1,10 @@
|
||||
includes:
|
||||
- vendor/cakedc/cakephp-phpstan/extension.neon
|
||||
|
||||
parameters:
|
||||
level: 4
|
||||
paths:
|
||||
- src
|
||||
bootstrapFiles:
|
||||
- tests/bootstrap.php
|
||||
treatPhpDocTypesAsCertain: false
|
||||
@@ -13,8 +13,8 @@ use Cake\Routing\RouteBuilder;
|
||||
/**
|
||||
* Plugin for CakeCarts
|
||||
*/
|
||||
class CakeCartsPlugin extends BasePlugin
|
||||
{
|
||||
class CakeCartsPlugin extends BasePlugin {
|
||||
|
||||
/**
|
||||
* Load all the plugin configuration and bootstrap logic.
|
||||
*
|
||||
@@ -24,8 +24,7 @@ class CakeCartsPlugin extends BasePlugin
|
||||
* @param \Cake\Core\PluginApplicationInterface $app The host application
|
||||
* @return void
|
||||
*/
|
||||
public function bootstrap(PluginApplicationInterface $app): void
|
||||
{
|
||||
public function bootstrap(PluginApplicationInterface $app): void {
|
||||
// remove this method hook if you don't need it
|
||||
}
|
||||
|
||||
@@ -38,8 +37,7 @@ class CakeCartsPlugin extends BasePlugin
|
||||
* @param \Cake\Routing\RouteBuilder $routes The route builder to update.
|
||||
* @return void
|
||||
*/
|
||||
public function routes(RouteBuilder $routes): void
|
||||
{
|
||||
public function routes(RouteBuilder $routes): void {
|
||||
// remove this method hook if you don't need it
|
||||
$routes->plugin(
|
||||
'CakeCarts',
|
||||
@@ -49,7 +47,7 @@ class CakeCartsPlugin extends BasePlugin
|
||||
$builder->connect('/wishlist', ['controller' => 'CakeCarts', 'action' => 'wishlist']);
|
||||
|
||||
$builder->fallbacks();
|
||||
}
|
||||
},
|
||||
);
|
||||
parent::routes($routes);
|
||||
}
|
||||
@@ -60,8 +58,7 @@ class CakeCartsPlugin extends BasePlugin
|
||||
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
|
||||
* @return \Cake\Http\MiddlewareQueue
|
||||
*/
|
||||
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
|
||||
{
|
||||
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
|
||||
// Add your middlewares here
|
||||
// remove this method hook if you don't need it
|
||||
|
||||
@@ -74,8 +71,7 @@ class CakeCartsPlugin extends BasePlugin
|
||||
* @param \Cake\Console\CommandCollection $commands The command collection to update.
|
||||
* @return \Cake\Console\CommandCollection
|
||||
*/
|
||||
public function console(CommandCollection $commands): CommandCollection
|
||||
{
|
||||
public function console(CommandCollection $commands): CommandCollection {
|
||||
// Add your commands here
|
||||
// remove this method hook if you don't need it
|
||||
|
||||
@@ -87,13 +83,13 @@ class CakeCartsPlugin extends BasePlugin
|
||||
/**
|
||||
* Register application container services.
|
||||
*
|
||||
* @link https://book.cakephp.org/5/en/development/dependency-injection.html#dependency-injection
|
||||
* @param \Cake\Core\ContainerInterface $container The Container to update.
|
||||
* @return void
|
||||
* @link https://book.cakephp.org/5/en/development/dependency-injection.html#dependency-injection
|
||||
*/
|
||||
public function services(ContainerInterface $container): void
|
||||
{
|
||||
public function services(ContainerInterface $container): void {
|
||||
// Add your services here
|
||||
// remove this method hook if you don't need it
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,5 @@ namespace CakeCarts\Controller;
|
||||
|
||||
use App\Controller\AppController as BaseController;
|
||||
|
||||
class AppController extends BaseController
|
||||
{
|
||||
class AppController extends BaseController {
|
||||
}
|
||||
|
||||
@@ -4,10 +4,7 @@ declare(strict_types=1);
|
||||
namespace CakeCarts\Controller;
|
||||
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\Exception\RecordNotFoundException;
|
||||
use Cake\Http\Client;
|
||||
use Cake\Log\Log;
|
||||
use CakeCarts\Controller\AppController;
|
||||
|
||||
/**
|
||||
* CartItems Controller
|
||||
@@ -15,10 +12,12 @@ use CakeCarts\Controller\AppController;
|
||||
* @property \CakeCarts\Model\Table\CartItemsTable $CartItems
|
||||
* @property \Authorization\Controller\Component\AuthorizationComponent $Authorization
|
||||
*/
|
||||
class CartItemsController extends AppController
|
||||
{
|
||||
public function initialize(): void
|
||||
{
|
||||
class CartItemsController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
|
||||
if (!$this->components()->has('ShoppingCart')) {
|
||||
@@ -39,8 +38,7 @@ class CartItemsController extends AppController
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
public function add() {
|
||||
$this->request->allowMethod(['post', 'put', 'patch']);
|
||||
|
||||
Log::debug(print_r('$this->request->getData()', true));
|
||||
@@ -64,7 +62,7 @@ class CartItemsController extends AppController
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index'
|
||||
'action' => 'index',
|
||||
]));
|
||||
}
|
||||
// Log::debug(print_r('$newCartItem->getErrors()', true));
|
||||
@@ -74,7 +72,7 @@ class CartItemsController extends AppController
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index'
|
||||
'action' => 'index',
|
||||
]));
|
||||
}
|
||||
|
||||
@@ -82,11 +80,10 @@ class CartItemsController extends AppController
|
||||
* Edit method
|
||||
*
|
||||
* @param string|null $id Cart Item id.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
public function edit($id = null) {
|
||||
$this->request->allowMethod(['post', 'put', 'patch']);
|
||||
|
||||
$cartItem = $this->CartItems->find()
|
||||
@@ -111,7 +108,7 @@ class CartItemsController extends AppController
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index'
|
||||
'action' => 'index',
|
||||
]));
|
||||
}
|
||||
Log::debug(print_r('$cartItem->getErrors()', true));
|
||||
@@ -122,7 +119,7 @@ class CartItemsController extends AppController
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index'
|
||||
'action' => 'index',
|
||||
]));
|
||||
}
|
||||
|
||||
@@ -130,11 +127,10 @@ class CartItemsController extends AppController
|
||||
* Delete method
|
||||
*
|
||||
* @param string|null $id Cart Item id.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
* @return \Cake\Http\Response|null Redirects to index.
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
public function delete($id = null) {
|
||||
$this->request->allowMethod(['post', 'delete']);
|
||||
$identity = $this->getRequest()->getAttribute('identity');
|
||||
|
||||
@@ -156,7 +152,8 @@ class CartItemsController extends AppController
|
||||
return $this->redirect($this->referer([
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'index'
|
||||
'action' => 'index',
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,19 +4,18 @@ declare(strict_types=1);
|
||||
namespace CakeCarts\Controller;
|
||||
|
||||
use App\Controller\AppController;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Event\EventInterface;
|
||||
use CakeCarts\Model\Enum\CartTypeId;
|
||||
|
||||
/**
|
||||
* Carts Controller
|
||||
*
|
||||
* @property \Authorization\Controller\Component\AuthorizationComponent $Authorization
|
||||
*/
|
||||
class CartsController extends AppController
|
||||
{
|
||||
public function initialize(): void
|
||||
{
|
||||
class CartsController extends AppController {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void {
|
||||
parent::initialize(); // TODO: Change the autogenerated stub
|
||||
|
||||
if (!$this->components()->has('ShoppingCart')) {
|
||||
@@ -33,8 +32,8 @@ class CartsController extends AppController
|
||||
*
|
||||
* @return \Cake\Http\Response|null|void Renders view
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
public function index() {
|
||||
// use cart from beforeFilter
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,28 +10,28 @@ use Cake\Datasource\Exception\RecordNotFoundException;
|
||||
use Cake\Event\EventInterface;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use CakeCarts\Model\Entity\CartItem;
|
||||
use CakeCarts\Model\Enum\CartTypeId;
|
||||
use CakeCarts\Model\Table\CartsTable;
|
||||
|
||||
/**
|
||||
* ShoppingCart component
|
||||
*/
|
||||
class ShoppingCartComponent extends Component
|
||||
{
|
||||
class ShoppingCartComponent extends Component {
|
||||
|
||||
/**
|
||||
* @var string $userIdField
|
||||
*/
|
||||
protected string $userIdField;
|
||||
|
||||
/**
|
||||
* @var CartsTable|Table $Carts
|
||||
* @var \CakeCarts\Model\Table\CartsTable|\Cake\ORM\Table $Carts
|
||||
*/
|
||||
protected CartsTable|Table $Carts;
|
||||
|
||||
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config); // TODO: Change the autogenerated stub
|
||||
|
||||
$this->userIdField = Configure::readOrFail('CakeCarts.Users.user_id') === 'uuid' ? 'user_id_uuid' : 'user_id';
|
||||
@@ -45,8 +45,10 @@ class ShoppingCartComponent extends Component
|
||||
*/
|
||||
protected array $_defaultConfig = [];
|
||||
|
||||
public function beforeFilter(EventInterface $event): void
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function beforeFilter(EventInterface $event): void {
|
||||
if (!$this->_isActionEnabled()) {
|
||||
return;
|
||||
}
|
||||
@@ -62,8 +64,7 @@ class ShoppingCartComponent extends Component
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCartForUserById(string $cartId)
|
||||
{
|
||||
public function getCartForUserById(string $cartId) {
|
||||
$identity = $this->getController()->getRequest()->getAttribute('identity');
|
||||
$sessionId = $this->getSessionId();
|
||||
|
||||
@@ -80,8 +81,7 @@ class ShoppingCartComponent extends Component
|
||||
return $cartsQ->firstOrFail();
|
||||
}
|
||||
|
||||
public function findExistingCartOrCreate(string $sessionId, int $cartTypeId = null)
|
||||
{
|
||||
public function findExistingCartOrCreate(string $sessionId, int|null $cartTypeId = null) {
|
||||
$identity = $this->getController()->getRequest()->getAttribute('identity');
|
||||
|
||||
$cartTypeId = $cartTypeId ?? CartTypeId::Cart->value;
|
||||
@@ -114,16 +114,14 @@ class ShoppingCartComponent extends Component
|
||||
return $cart;
|
||||
}
|
||||
|
||||
public function getUserIdField()
|
||||
{
|
||||
public function getUserIdField() {
|
||||
return $this->userIdField;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSessionId(): string
|
||||
{
|
||||
public function getSessionId(): string {
|
||||
if (!$this->getController()->getRequest()->getSession()->started()) {
|
||||
$this->getController()->getRequest()->getSession()->start();
|
||||
}
|
||||
@@ -136,13 +134,12 @@ class ShoppingCartComponent extends Component
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EntityInterface $cart
|
||||
* @throws RecordNotFoundException
|
||||
* @param \Cake\Datasource\EntityInterface $cart
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function checkIfIsOwnCart(EntityInterface $cart): void
|
||||
{
|
||||
public function checkIfIsOwnCart(EntityInterface $cart): void {
|
||||
$identity = $this->getController()->getRequest()->getAttribute('identity');
|
||||
|
||||
if (!isset($identity) && isset($cart->session_id) && ($cart->session_id != $this->getSessionId())) {
|
||||
@@ -156,8 +153,7 @@ class ShoppingCartComponent extends Component
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isActionEnabled(): bool
|
||||
{
|
||||
protected function _isActionEnabled(): bool {
|
||||
$actions = $this->getConfig('actions');
|
||||
if (is_bool($actions)) {
|
||||
return $actions;
|
||||
@@ -165,4 +161,5 @@ class ShoppingCartComponent extends Component
|
||||
|
||||
return in_array($this->getController()->getRequest()->getParam('action'), (array)$actions, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use Cake\ORM\Entity;
|
||||
* @property string $id
|
||||
* @property int $cart_type_id
|
||||
* @property string|null $session_id
|
||||
* @property integer|null $user_id
|
||||
* @property int|null $user_id
|
||||
* @property string|null $user_id_uuid
|
||||
* @property \Cake\I18n\DateTime $created
|
||||
* @property \Cake\I18n\DateTime|null $modified
|
||||
@@ -22,8 +22,8 @@ use Cake\ORM\Entity;
|
||||
*
|
||||
* @property \CakeCarts\Model\Entity\CartItem[] $cart_items
|
||||
*/
|
||||
class Cart extends Entity
|
||||
{
|
||||
class Cart extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
@@ -47,4 +47,5 @@ class Cart extends Entity
|
||||
'user' => true,
|
||||
'cart_items' => true,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ use Cake\ORM\Entity;
|
||||
*
|
||||
* @property \CakeCarts\Model\Entity\Cart $cart
|
||||
*/
|
||||
class CartItem extends Entity
|
||||
{
|
||||
class CartItem extends Entity {
|
||||
|
||||
/**
|
||||
* Fields that can be mass assigned using newEntity() or patchEntity().
|
||||
*
|
||||
@@ -42,4 +42,5 @@ class CartItem extends Entity
|
||||
'subtotal' => true,
|
||||
'cart' => true,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace CakeCarts\Model\Enum;
|
||||
|
||||
use Cake\Database\Type\EnumLabelInterface;
|
||||
@@ -12,12 +13,11 @@ enum CartTypeId: int implements EnumLabelInterface
|
||||
case Wishlist = 2;
|
||||
case CustomList = 3;
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
public function label(): string {
|
||||
return match ($this) {
|
||||
self::Cart => 'Cart',
|
||||
self::Wishlist => 'Wishlist',
|
||||
self::CustomList => 'List'
|
||||
static::Cart => 'Cart',
|
||||
static::Wishlist => 'Wishlist',
|
||||
static::CustomList => 'List'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace CakeCarts\Model\Table;
|
||||
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
@@ -27,16 +26,15 @@ use Cake\Validation\Validator;
|
||||
* @method iterable<\CakeCarts\Model\Entity\CartItem>|\Cake\Datasource\ResultSetInterface<\CakeCarts\Model\Entity\CartItem>|false deleteMany(iterable $entities, array $options = [])
|
||||
* @method iterable<\CakeCarts\Model\Entity\CartItem>|\Cake\Datasource\ResultSetInterface<\CakeCarts\Model\Entity\CartItem> deleteManyOrFail(iterable $entities, array $options = [])
|
||||
*/
|
||||
class CartItemsTable extends Table
|
||||
{
|
||||
class CartItemsTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('cart_items');
|
||||
@@ -56,8 +54,7 @@ class CartItemsTable extends Table
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->scalar('foreign_key')
|
||||
->allowEmptyString('foreign_key');
|
||||
@@ -87,8 +84,7 @@ class CartItemsTable extends Table
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public function validationRequiresPricing(Validator $validator): Validator
|
||||
{
|
||||
public function validationRequiresPricing(Validator $validator): Validator {
|
||||
$validator = $this->validationDefault($validator);
|
||||
|
||||
$validator
|
||||
@@ -111,10 +107,10 @@ class CartItemsTable extends Table
|
||||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
|
||||
* @return \Cake\ORM\RulesChecker
|
||||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
public function buildRules(RulesChecker $rules): RulesChecker {
|
||||
$rules->add($rules->existsIn(['cart_id'], 'Carts'), ['errorField' => 'cart_id']);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ declare(strict_types=1);
|
||||
namespace CakeCarts\Model\Table;
|
||||
|
||||
use Cake\Database\Type\EnumType;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use CakeCarts\Model\Enum\CartTypeId;
|
||||
@@ -32,16 +30,15 @@ use CakeCarts\Model\Enum\CartTypeId;
|
||||
*
|
||||
* @mixin \Cake\ORM\Behavior\TimestampBehavior
|
||||
*/
|
||||
class CartsTable extends Table
|
||||
{
|
||||
class CartsTable extends Table {
|
||||
|
||||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param array<string, mixed> $config The configuration for the Table.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
public function initialize(array $config): void {
|
||||
parent::initialize($config);
|
||||
|
||||
$this->setTable('carts');
|
||||
@@ -64,8 +61,7 @@ class CartsTable extends Table
|
||||
* @param \Cake\Validation\Validator $validator Validator instance.
|
||||
* @return \Cake\Validation\Validator
|
||||
*/
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
public function validationDefault(Validator $validator): Validator {
|
||||
$validator
|
||||
->integer('cart_type_id')
|
||||
->requirePresence('cart_type_id', 'create')
|
||||
@@ -102,4 +98,5 @@ class CartsTable extends Table
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,15 +8,14 @@ use Cake\TestSuite\Fixture\TestFixture;
|
||||
/**
|
||||
* CartItemsFixture
|
||||
*/
|
||||
class CartItemsFixture extends TestFixture
|
||||
{
|
||||
class CartItemsFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '79f66e8d-8d8d-4095-adc4-fd15234a4397',
|
||||
@@ -65,4 +64,5 @@ class CartItemsFixture extends TestFixture
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,15 +9,14 @@ use CakeCarts\Model\Enum\CartTypeId;
|
||||
/**
|
||||
* CartsFixture
|
||||
*/
|
||||
class CartsFixture extends TestFixture
|
||||
{
|
||||
class CartsFixture extends TestFixture {
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
public function init(): void {
|
||||
$this->records = [
|
||||
// normal cart - open
|
||||
[
|
||||
@@ -78,4 +77,5 @@ class CartsFixture extends TestFixture
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,17 +5,15 @@ namespace CakeCarts\Test\TestCase\Controller;
|
||||
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeCarts\Controller\CartItemsController;
|
||||
use CakeCarts\Model\Table\CartItemsTable;
|
||||
use CakeCarts\Model\Table\CartsTable;
|
||||
|
||||
/**
|
||||
* CakeCarts\Controller\CartItemsController Test Case
|
||||
*
|
||||
* @link \CakeCarts\Controller\CartItemsController
|
||||
*/
|
||||
class CartItemsControllerTest extends TestCase
|
||||
{
|
||||
class CartItemsControllerTest extends TestCase {
|
||||
|
||||
use IntegrationTestTrait;
|
||||
|
||||
/**
|
||||
@@ -35,23 +33,23 @@ class CartItemsControllerTest extends TestCase
|
||||
'plugin.CakeCarts.Carts',
|
||||
];
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void {
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
||||
$config = $this->getTableLocator()->exists('CartItems') ? [] : ['className' => CartItemsTable::class];
|
||||
$this->CartItems = $this->getTableLocator()->get('CartItems', $config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* @return void
|
||||
* @link \CakeCarts\Controller\CartItemsController::add()
|
||||
* @return void
|
||||
*/
|
||||
public function testAdd(): void
|
||||
{
|
||||
public function testAdd(): void {
|
||||
$url = [
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
@@ -80,17 +78,16 @@ class CartItemsControllerTest extends TestCase
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* @return void
|
||||
* @link \CakeCarts\Controller\CartItemsController::edit()
|
||||
* @return void
|
||||
*/
|
||||
public function testEdit(): void
|
||||
{
|
||||
public function testEdit(): void {
|
||||
$id = '79f66e8d-8d8d-4095-adc4-fd15234a4397';
|
||||
$url = [
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'CartItems',
|
||||
'action' => 'edit',
|
||||
$id
|
||||
$id,
|
||||
];
|
||||
$this->session(['Auth.User.id' => 1]);
|
||||
$this->session(['Auth.id' => 1]);
|
||||
@@ -112,11 +109,11 @@ class CartItemsControllerTest extends TestCase
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* @return void
|
||||
* @link \CakeCarts\Controller\CartItemsController::delete()
|
||||
* @return void
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
public function testDelete(): void {
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,15 +5,14 @@ namespace CakeCarts\Test\TestCase\Controller;
|
||||
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeCarts\Controller\CartsController;
|
||||
|
||||
/**
|
||||
* CakeCarts\Controller\CartsController Test Case
|
||||
*
|
||||
* @uses \CakeCarts\Controller\CartsController
|
||||
*/
|
||||
class CartsControllerTest extends TestCase
|
||||
{
|
||||
class CartsControllerTest extends TestCase {
|
||||
|
||||
use IntegrationTestTrait;
|
||||
|
||||
/**
|
||||
@@ -23,16 +22,20 @@ class CartsControllerTest extends TestCase
|
||||
*/
|
||||
protected $Carts;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void {
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
|
||||
$config = $this->getTableLocator()->exists('Carts') ? [] : ['className' => CartsTable::class];
|
||||
$this->Carts = $this->getTableLocator()->get('Carts', $config);
|
||||
}
|
||||
|
||||
public function testIndex(): void
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testIndex(): void {
|
||||
$url = [
|
||||
'plugin' => 'CakeCarts',
|
||||
'controller' => 'Carts',
|
||||
@@ -42,4 +45,5 @@ class CartsControllerTest extends TestCase
|
||||
|
||||
$this->assertResponseCode(200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ use CakeCarts\Controller\Component\ShoppingCartComponent;
|
||||
/**
|
||||
* CakeCarts\Controller\Component\ShoppingCartComponent Test Case
|
||||
*/
|
||||
class ShoppingCartComponentTest extends TestCase
|
||||
{
|
||||
class ShoppingCartComponentTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
@@ -24,8 +24,7 @@ class ShoppingCartComponentTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$registry = new ComponentRegistry();
|
||||
$this->ShoppingCart = new ShoppingCartComponent($registry);
|
||||
@@ -36,10 +35,10 @@ class ShoppingCartComponentTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
protected function tearDown(): void {
|
||||
unset($this->ShoppingCart);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ use CakeCarts\Model\Table\CartItemsTable;
|
||||
/**
|
||||
* CakeCarts\Model\Table\CartItemsTable Test Case
|
||||
*/
|
||||
class CartItemsTableTest extends TestCase
|
||||
{
|
||||
class CartItemsTableTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
@@ -33,8 +33,7 @@ class CartItemsTableTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$config = $this->getTableLocator()->exists('CartItems') ? [] : ['className' => CartItemsTable::class];
|
||||
$this->CartItems = $this->getTableLocator()->get('CartItems', $config);
|
||||
@@ -45,8 +44,7 @@ class CartItemsTableTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
protected function tearDown(): void {
|
||||
unset($this->CartItems);
|
||||
|
||||
parent::tearDown();
|
||||
@@ -55,22 +53,21 @@ class CartItemsTableTest extends TestCase
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeCarts\Model\Table\CartItemsTable::validationDefault()
|
||||
* @return void
|
||||
*/
|
||||
public function testValidationDefault(): void
|
||||
{
|
||||
public function testValidationDefault(): void {
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildRules method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeCarts\Model\Table\CartItemsTable::buildRules()
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildRules(): void
|
||||
{
|
||||
public function testBuildRules(): void {
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ use CakeCarts\Model\Table\CartsTable;
|
||||
/**
|
||||
* CakeCarts\Model\Table\CartsTable Test Case
|
||||
*/
|
||||
class CartsTableTest extends TestCase
|
||||
{
|
||||
class CartsTableTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
@@ -34,8 +34,7 @@ class CartsTableTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$config = $this->getTableLocator()->exists('Carts') ? [] : ['className' => CartsTable::class];
|
||||
$this->Carts = $this->getTableLocator()->get('Carts', $config);
|
||||
@@ -46,8 +45,7 @@ class CartsTableTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
protected function tearDown(): void {
|
||||
unset($this->Carts);
|
||||
|
||||
parent::tearDown();
|
||||
@@ -56,22 +54,21 @@ class CartsTableTest extends TestCase
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeCarts\Model\Table\CartsTable::validationDefault()
|
||||
* @return void
|
||||
*/
|
||||
public function testValidationDefault(): void
|
||||
{
|
||||
public function testValidationDefault(): void {
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildRules method
|
||||
*
|
||||
* @return void
|
||||
* @uses \CakeCarts\Model\Table\CartsTable::buildRules()
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildRules(): void
|
||||
{
|
||||
public function testBuildRules(): void {
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ use Cake\Core\Configure;
|
||||
use Cake\Core\Plugin;
|
||||
use Cake\Database\Connection;
|
||||
use Cake\Datasource\ConnectionManager;
|
||||
use Cake\TestSuite\Fixture\SchemaLoader;
|
||||
use CakeProducts\CakeProductsPlugin;
|
||||
use CakeCarts\CakeCartsPlugin;
|
||||
use Migrations\TestSuite\Migrator;
|
||||
use TestApp\Controller\AppController;
|
||||
|
||||
@@ -94,7 +93,7 @@ Cache::setConfig($cache);
|
||||
|
||||
class_alias(AppController::class, 'App\Controller\AppController');
|
||||
|
||||
Plugin::getCollection()->add(new \CakeCarts\CakeCartsPlugin());
|
||||
Plugin::getCollection()->add(new CakeCartsPlugin());
|
||||
|
||||
Chronos::setTestNow(Chronos::now());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user