Skip to content

Commit

Permalink
Update Makfile and some other files
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Oct 30, 2021
1 parent fdddf16 commit 9bb7ed9
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .php-version.dist
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.4
8.0
12 changes: 5 additions & 7 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
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)
Expand Down
15 changes: 15 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -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
```
68 changes: 52 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand All @@ -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
Expand All @@ -53,20 +55,56 @@ 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
### ¯¯¯¯¯

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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
### ¯¯¯¯¯¯¯¯
Expand All @@ -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

Expand Down
58 changes: 58 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -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`!
20 changes: 20 additions & 0 deletions docker-compose.yaml.dist
Original file line number Diff line number Diff line change
@@ -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: {}
1 change: 1 addition & 0 deletions php.ini.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
memory_limit=-1
2 changes: 1 addition & 1 deletion phpmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<rule ref="rulesets/naming.xml/ShortClassName"/>
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="exceptions" value="id,em,qb"/>
<property name="exceptions" value="id,em"/>
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName"/>
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
bootstrap="tests/Application/config/bootstrap.php">
<testsuites>
<testsuite name="MonsieurBizSyliusMenuPlugin Test Suite">
<directory>tests</directory>
<directory>tests/Unit</directory>
</testsuite>
</testsuites>

Expand Down

0 comments on commit 9bb7ed9

Please sign in to comment.