diff --git a/.php-version.dist b/.php-version.dist index 9904c66..cc40bca 100644 --- a/.php-version.dist +++ b/.php-version.dist @@ -1 +1 @@ -7.4 \ No newline at end of file +8.0 diff --git a/.php_cs.dist b/.php_cs.dist index df7f6a0..e534831 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -3,19 +3,17 @@ declare(strict_types=1); $header = <<<'HEADER' -This file is part of Monsieur Biz' menu plugin for Sylius. +This file is part of Monsieur Biz' Menu plugin for Sylius. + (c) Monsieur Biz -For the full copyright and license information, please view the LICENSE + +For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code. HEADER; $finder = PhpCsFixer\Finder::create() ->in(__DIR__) - ->exclude([ - 'tests/Application/var', - 'tests/Application/bin', - 'tests/Application/config', - ]); + ->exclude('tests/Application'); return PhpCsFixer\Config::create() ->setRiskyAllowed(true) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..9971d62 --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,15 @@ +## Node + +Be sure you have node 14 on your machine. You can use NVM to easily switch versions. + +# Docker + +Be sure you have docker on your machine. + +# Symfony + +Be sure you have the Symfony binary on your machine. + +``` + curl -sS https://get.symfony.com/cli/installer | bash + ``` diff --git a/Makefile b/Makefile index c158717..cdff239 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,20 @@ .DEFAULT_GOAL := help SHELL=/bin/bash APP_DIR=tests/Application +SYLIUS_VERSION=1.10 SYMFONY=cd ${APP_DIR} && symfony COMPOSER=symfony composer CONSOLE=${SYMFONY} console export COMPOSE_PROJECT_NAME=menu -DOCTRINE_NAMESPACE=MonsieurBiz\SyliusMenuPlugin\Migrations +PLUGIN_NAME=sylius-${COMPOSE_PROJECT_NAME}-plugin COMPOSE=docker-compose YARN=yarn -PHPUNIT=symfony php vendor/bin/phpunit -PHPSPEC=symfony php vendor/bin/phpspec ### ### DEVELOPMENT ### ¯¯¯¯¯¯¯¯¯¯¯ -install: platform sylius ## Install the plugin +install: application platform sylius ## Install the plugin .PHONY: install up: docker.up server.start ## Up the project (start docker, start symfony server) @@ -24,6 +23,7 @@ down: server.stop docker.down ## Down the project (removes docker containers, st reset: docker.down ## Stop docker and remove dependencies rm -rf ${APP_DIR}/node_modules ${APP_DIR}/yarn.lock + rm -rf ${APP_DIR} rm -rf vendor composer.lock .PHONY: reset @@ -32,7 +32,9 @@ dependencies: vendor node_modules ## Setup the dependencies .php-version: .php-version.dist cp .php-version.dist .php-version - (cd ${APP_DIR} && ln -sf ../../.php-version) + +php.ini: php.ini.dist + cp php.ini.dist php.ini vendor: composer.lock ## Install the PHP dependencies using composer ifdef GITHUB_ACTIONS @@ -53,11 +55,48 @@ yarn.install: ${APP_DIR}/yarn.lock ${APP_DIR}/yarn.lock: ln -sf ${APP_DIR}/node_modules node_modules cd ${APP_DIR} && ${YARN} install && ${YARN} build +# No CSS and JS on this plugin yet +# ${YARN} install +# ${YARN} encore prod node_modules: ${APP_DIR}/node_modules ## Install the Node dependencies using yarn ${APP_DIR}/node_modules: yarn.install +### +### TEST APPLICATION +### ¯¯¯¯¯ + +application: .php-version php.ini ${APP_DIR} setup_application ${APP_DIR}/docker-compose.yaml + +${APP_DIR}: + (${COMPOSER} create-project --prefer-dist --no-scripts --no-progress --no-install sylius/sylius-standard="${SYLIUS_VERSION}" ${APP_DIR}) + +setup_application: + rm -f ${APP_DIR}/yarn.lock + (cd ${APP_DIR} && ${COMPOSER} config repositories.plugin '{"type": "path", "url": "../../"}') + (cd ${APP_DIR} && ${COMPOSER} config extra.symfony.allow-contrib true) + (cd ${APP_DIR} && ${COMPOSER} require --no-scripts --no-progress --no-install --no-update monsieurbiz/${PLUGIN_NAME}="*@dev") + $(MAKE) apply_dist + $(MAKE) ${APP_DIR}/.php-version + $(MAKE) ${APP_DIR}/php.ini + (cd ${APP_DIR} && ${COMPOSER} install) + +${APP_DIR}/docker-compose.yaml: + rm -f ${APP_DIR}/docker-compose.yml + rm -f ${APP_DIR}/docker-compose.yaml + cp docker-compose.yaml.dist ${APP_DIR}/docker-compose.yaml +.PHONY: ${APP_DIR}/docker-compose.yaml + +${APP_DIR}/.php-version: .php-version + (cd ${APP_DIR} && ln -sf ../../.php-version) + +${APP_DIR}/php.ini: php.ini + (cd ${APP_DIR} && ln -sf ../../php.ini) + +apply_dist: + cp -Rv dist/* ${APP_DIR} + ### ### TESTS ### ¯¯¯¯¯ @@ -65,8 +104,7 @@ ${APP_DIR}/node_modules: yarn.install test.all: test.composer test.phpstan test.phpmd test.phpunit test.phpspec test.phpcs test.yaml test.schema test.twig ## Run all tests in once test.composer: ## Validate composer.json - ${COMPOSER} validate -# ${COMPOSER} validate --strict + ${COMPOSER} validate --strict test.phpstan: ## Run PHPStan ${COMPOSER} phpstan @@ -75,10 +113,10 @@ test.phpmd: ## Run PHPMD ${COMPOSER} phpmd test.phpunit: ## Run PHPUnit - ${PHPUNIT} + ${COMPOSER} phpunit test.phpspec: ## Run PHPSpec - ${PHPSPEC} run + ${COMPOSER} phpspec test.phpcs: ## Run PHP CS Fixer in dry-run ${COMPOSER} run -- phpcs --dry-run -v @@ -96,7 +134,7 @@ test.schema: ## Validate MySQL Schema ${CONSOLE} doctrine:schema:validate test.twig: ## Validate Twig templates - ${CONSOLE} lint:twig -e prod --no-debug ../../src/Resources/views/ + ${CONSOLE} lint:twig --no-debug templates/ ../../src/Resources/views/ ### ### SYLIUS @@ -118,12 +156,6 @@ sylius.assets: ## Install all assets with symlinks ${CONSOLE} sylius:install:assets ${CONSOLE} sylius:theme:assets:install --symlink -doctrine.diff: ## Make doctrine diff - ${CONSOLE} doctrine:migration:diff --namespace="${DOCTRINE_NAMESPACE}" - -doctrine.migrate: ## Make doctrine migrate - ${CONSOLE} doctrine:migration:migrate - ### ### PLATFORM ### ¯¯¯¯¯¯¯¯ @@ -146,6 +178,10 @@ docker.down: ## Stop and remove the docker containers cd ${APP_DIR} && ${COMPOSE} down .PHONY: docker.down +docker.logs: ## Logs the docker containers + cd ${APP_DIR} && ${COMPOSE} logs +.PHONY: docker.logs + server.start: ## Run the local webserver using Symfony ${SYMFONY} local:server:start -d diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000..dd1a5fc --- /dev/null +++ b/TESTING.md @@ -0,0 +1,58 @@ +# Testing + +## Requirements + +You'll need: + +- PHP 7.4 minimum. +- docker, for the database. +- symfony CLI, to run the local server. +- composer, to install PHP dependencies. +- npm and yarn, to install ui dependencies and build the JS/CSS files. + +## Installation + +```bash +make install +``` + +This will run a Sylius app (the one in `tests/Application/`) with the plugin +installed and all Sylius' sample data. It uses the symfony binary. + +## Usage + +### List all available commands + +```bash +make help +``` + +### Running minimum plugin tests + +- PHPUnit + + ```bash + make test.phpunit + ``` + +- PHP CS fixer + + ```bash + make test.phpcs + ``` + + > Tip: You can fix your code with `make test.phpcs.fix`! + +- PHPSpec + + ```bash + make test.phpspec + ``` + +- PHPStan + + ```bash + make test.phpstan + ``` + +> Tip: You can run all tests with `make test.all`! diff --git a/docker-compose.yaml.dist b/docker-compose.yaml.dist new file mode 100644 index 0000000..3135e79 --- /dev/null +++ b/docker-compose.yaml.dist @@ -0,0 +1,20 @@ +version: '3.8' +services: + database: + image: mysql:8.0 + ports: + - 3306 + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: 1 + MYSQL_DATABASE: sylius + volumes: + - database:/var/lib/mysql + + mailer: + image: monsieurbiz/mailcatcher + ports: + - 1025 + - 1080 + +volumes: + database: {} diff --git a/php.ini.dist b/php.ini.dist new file mode 100644 index 0000000..b0fe7fe --- /dev/null +++ b/php.ini.dist @@ -0,0 +1 @@ +memory_limit=-1 diff --git a/phpmd.xml b/phpmd.xml index d0c3423..0000ac5 100644 --- a/phpmd.xml +++ b/phpmd.xml @@ -44,7 +44,7 @@ - + diff --git a/phpstan.neon b/phpstan.neon index 4b220da..b551d67 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,10 +1,13 @@ +includes: + - vendor/phpstan/phpstan-doctrine/extension.neon + - vendor/phpstan/phpstan-webmozart-assert/extension.neon + parameters: level: max paths: - %rootDir%/src/ checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false excludes_analyse: # Makes PHPStan crash diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4af4d34..6d47b3f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,7 +6,7 @@ bootstrap="tests/Application/config/bootstrap.php"> - tests + tests/Unit