Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try new version of Empress #37

Merged
merged 10 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 19 additions & 0 deletions .docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Docker only
PROJECT_NAME="italystrap"
PHP_VERSION="7.4"
WP_VERSION="6.0"

WP_PORT=8888
DB_PORT=8889
PMA_PORT=8890

# Docker and Codeception
DB_NAME="test"
DB_HOST="mysql"
DB_USER="root"
DB_PASSWORD="root"

# Functional tests
APP_URL=http://localhost
ADMIN_USERNAME=root
ADMIN_PASSWORD=root
5 changes: 4 additions & 1 deletion .docker/codecept
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env bash

docker exec -w //var/www/html/wp-content/themes/italystrap italystrap80 sh -c "vendor/bin/codecept ${*}"
# Get project name from .env file
PROJECT_NAME=$(grep PROJECT_NAME .env | cut -d '=' -f2 | tr -d '"')

docker exec -w /var/www/html/wp-content/themes/"${PROJECT_NAME}" "${PROJECT_NAME}"_test sh -c "vendor/bin/codecept ${*}"
5 changes: 4 additions & 1 deletion .docker/composer
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env bash

docker-compose run -w //var/www/html/wp-content/themes/italystrap --rm wordpress sh -c "composer ${*}"
# Get project name from .env file
PROJECT_NAME=$(grep PROJECT_NAME .env | cut -d '=' -f2 | tr -d '"')

docker-compose run -w /var/www/html/wp-content/themes/"${PROJECT_NAME}" --rm wordpress sh -c "composer ${*}"
30 changes: 15 additions & 15 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ services:
args:
PHP_VERSION: ${PHP_VERSION}
WP_VERSION: ${WP_VERSION}
container_name: ${PROJECT_NAME:-wordpress}${MATRIX_PHP_VERSION}
container_name: ${PROJECT_NAME:-wordpress}_test
restart: always
ports:
- ${WP_PORT_TEST}:80
- ${WP_PORT}:80
environment:
WORDPRESS_DB_HOST: ${DB_HOST:-mysql}
WORDPRESS_DB_NAME: ${DB_NAME:-test}
Expand All @@ -19,45 +19,45 @@ services:
WORDPRESS_TABLE_PREFIX: ${TABLE_PREFIX:-wp_}
WORDPRESS_DEBUG: 1
volumes:
- ../:/var/www/html/wp-content/themes/${FOLDER_NAME:-wordpress}
- ../:/var/www/html/wp-content/themes/${PROJECT_NAME:-wordpress}
- ../tests/_output/:/var/www/html/wp-content/themes/${PROJECT_NAME:-wordpress}/tests/_output/
- ./codeception.yml:/var/www/html/wp-content/themes/${PROJECT_NAME:-wordpress}/codeception.yml
#- ./mu-plugins/:/var/www/html/wp-content/mu-plugins/
depends_on:
- mysql
networks:
wpbrowser:
# aliases:
# - wp
integration_test_networks:

mysql:
image: mysql:${DB_VERSION:-5.7}
container_name: ${PROJECT_NAME:-wordpress}_mysql
container_name: ${PROJECT_NAME:-wordpress}_mysql_test
restart: always
ports:
- ${DB_PORT_TEST}:3306
- ${DB_PORT}:3306
environment:
MYSQL_DATABASE: ${DB_NAME:-test}
#MYSQL_USER: ${TEST_SITE_DB_USER:-root}
#MYSQL_USER: ${DB_USER:-root}
MYSQL_PASSWORD: ${DB_PASSWORD:-root}
#MYSQL_RANDOM_ROOT_PASSWORD: '1'
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root}
networks:
- wpbrowser
- integration_test_networks

phpmyadmin:
depends_on:
- mysql
image: phpmyadmin/phpmyadmin:${PMA_VERSION:-latest}
container_name: ${PROJECT_NAME}_phpmyadmin
container_name: ${PROJECT_NAME}_phpmyadmin_test
restart: always
ports:
- ${PMA_PORT_TEST}:80
- ${PMA_PORT}:80
environment:
# For max upload from PHPMYADMIN https://github.com/10up/wp-local-docker-v2/issues/40#issuecomment-719915040
UPLOAD_LIMIT: 1G
PMA_HOST: ${DB_HOST:-mysql}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root}
networks:
- wpbrowser
- integration_test_networks

chromedriver:
image: selenium/standalone-chrome:4.6.0-20221104
Expand All @@ -67,8 +67,8 @@ services:
- "4444:4444"
- "7900:7900"
networks:
- wpbrowser
- integration_test_networks

networks:
wpbrowser:
integration_test_networks:
driver: bridge
5 changes: 4 additions & 1 deletion .docker/ssh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env bash

docker exec -it -w //var/www/html/wp-content/themes/italystrap italystrap8.0 sh
# Get project name from .env file
PROJECT_NAME=$(grep PROJECT_NAME .env | cut -d '=' -f2 | tr -d '"')

docker exec -it -w //var/www/html/wp-content/themes/"${PROJECT_NAME}" "${PROJECT_NAME}"_test sh
17 changes: 17 additions & 0 deletions .docker/wordpress/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,30 @@ ARG WP_VERSION

FROM wordpress:${WP_VERSION}-php${PHP_VERSION}

# Install pcov for code coverage
RUN set -eux; \
pecl install pcov; \
docker-php-ext-enable pcov

# If you want to use xdebug, uncomment the following lines
# Install xdebug for code coverage
#RUN set -eux; \
# pecl install xdebug-3.1.4; \
# docker-php-ext-enable xdebug

# Set XDEBUG_MODE=coverage or xdebug.mode=coverage
#ENV XDEBUG_MODE=coverage

RUN set -eux; \
apt-get update && apt-get install -y \
git \
nano \
less # Needed for the WP-CLI \
rm -rf /var/lib/apt/lists/*

# Git add safe directory for the working directory


# Needed for Db driver
# https://github.com/Codeception/Codeception/issues/3605
RUN docker-php-ext-install \
Expand Down
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEST=test
COMPOSE_PROJECT_NAME=italystrap
PROJECT_NAME=italystrap
FOLDER_NAME=italystrap
PHP_VERSION=8.0
PHP_VERSION=7.4
MATRIX_PHP_VERSION=80
WP_VERSION=6.0
WP_PORT_TEST=8888
Expand Down
197 changes: 173 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,185 @@
DOCKER_FOLDER = .docker
DOCKER_DIR = cd $(DOCKER_FOLDER) &&
HOST_OWNER = $(shell id -u):$(shell id -g)
FILES_OWNERSHIP = sudo chown -R $(HOST_OWNER) .

.PHONY: up down codeceptbuild unit integration functional acceptance qa
composebuild:
cd .docker && docker-compose --env-file ../.env up -d --build
default: help

up:
cd .docker && docker-compose --env-file ../.env up -d --remove-orphans
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
# https://gist.github.com/prwhite/8168133?permalink_comment_id=4266839#gistcomment-4266839
.PHONY: help
help: ## Display this help screen
@grep -hP '^\w.*?:.*##.*$$' $(MAKEFILE_LIST) | sort -u | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

down:
cd .docker && docker-compose --env-file ../.env down --remove-orphans --volumes
.PHONY: files/mod
files/permission: ### Set the executable files in Docker folder permissions to 777
@echo "Checking files permissions"
@find $(DOCKER_FOLDER) -maxdepth 1 -type f -exec grep -lE '^#!' {} \; | xargs chmod 777
@find $(DOCKER_FOLDER) -maxdepth 1 -type f -exec grep -lqE '^#!' {} \; -exec ls -la {} \;
@echo "Files permissions ok"

codeceptbuild: up
.docker/codecept build
.PHONY: files/own
files/own: ### Set again the ownership off all the file to the current user
@echo "Setting the ownership of all the files to the current user"
@$(FILES_OWNERSHIP)
@echo "Ownership set"

clean: up
.docker/codecept clean
# Docker commands

unit: up
.docker/codecept run unit
.PHONY: build
build: files/permission ### Build the containers inside the ./docker folder
@echo "Building the containers"
$(DOCKER_DIR) docker-compose up -d --build --remove-orphans
@echo "Containers built"

integration: up
.docker/codecept run integration
.PHONY: up
up: files/permission ### Start the containers inside the ./docker folder
@echo "Starting the containers..."
@$(DOCKER_DIR) docker-compose up -d --remove-orphans
@echo "Containers started"

functional: up
.docker/codecept run functional --debug
.PHONY: down
down: ### Stop the containers inside the ./docker folder
@echo "Stopping the containers"
@$(DOCKER_DIR) docker-compose down --remove-orphans --volumes
@echo "Containers stopped"

acceptance: up
.docker/codecept run acceptance
# Composer commands

qa: unit integration functional acceptance
.PHONY: composer/install
composer/install: up ### Install the composer dependencies
@echo "Installing the composer dependencies"
@$(DOCKER_DIR) ./composer install

cs:
composer cs
.PHONY: composer/update
composer/update: up ### Update the composer dependencies
@echo "Updating the composer dependencies"
@$(DOCKER_DIR) ./composer update

fix:
composer cs:fix
.PHONY: composer/dump
composer/dump: up ### Dump the composer autoload
@echo "Dumping the composer autoload"
@$(DOCKER_DIR) ./composer dump-autoload

# Codestyle commands

.PHONY: cs
cs: up ### Run the code sniffer
@echo "Running the code sniffer"
@$(DOCKER_DIR) ./composer cs

.PHONY: cs/fix
cs/fix: up ### Run the code sniffer and fix the errors
@echo "Running the code sniffer and fix the errors"
@$(DOCKER_DIR) ./composer cs:fix
@$(FILES_OWNERSHIP)

# Psalm commands

.PHONY: psalm
psalm: up ### Run the psalm
@echo "Running the psalm"
@$(DOCKER_DIR) ./composer psalm

# Codeception commands

.PHONY: codecept/build
codecept/build: up ### Build the codeception suites
@echo "Building the codeception suites"
@$(DOCKER_DIR) ./codecept build
@$(FILES_OWNERSHIP)

.PHONY: clean
clean: up ### Clean the codeception suites
@echo "Cleaning the codeception suites"
@$(DOCKER_DIR) ./codecept clean

.PHONY: unit
unit: up ### Run the unit tests
@echo "Running the unit tests"
@$(DOCKER_DIR) ./codecept run unit --debug

.PHONY: integration
integration: up ### Run the integration tests
@echo "Running the integration tests"
@$(DOCKER_DIR) ./codecept run integration --debug

.PHONY: functional
functional: up ### Run the functional tests
@echo "Running the functional tests"
@$(DOCKER_DIR) ./codecept run functional --debug

.PHONY: acceptance
acceptance: up ### Run the acceptance tests
@echo "Running the acceptance tests"
@$(DOCKER_DIR) ./codecept run acceptance

.PHONY: tests
tests: unit integration ### Run unit and integration tests

.PHONY: qa
qa: cs psalm unit integration functional ### Run all the tests

# Infection commands

.PHONY: infection
infection: up ### Run the infection
@echo "Running the infection"
@$(DOCKER_DIR) ./composer infection

# Rector commands

.PHONY: rector
rector: up ### Run the rector with dry-run
@echo "Running the rector in dry-run mode, if you want to apply the refactorings run make rector/fix"
@$(DOCKER_DIR) ./composer rector

.PHONY: rector/fix
rector/fix: up ### Apply the rector refactorings
@echo "Running the rector"
@$(DOCKER_DIR) ./composer rector:fix
@$(FILES_OWNERSHIP)

# Benchmark commands

.PHONY: bench
bench: ### Run the benchmark in the local machine not in the docker container
@echo "Running the benchmark"
@composer bench

# PhpMetrics commands

.PHONY: docker/metrics
docker/metrics: ### Run the phpmetrics
@echo "Running the phpmetrics"
@docker run --rm \
--user $(id -u):$(id -g) \
--volume `pwd`:/project \
herloct/phpmetrics --report-html=./tests/_output/report src

# PhpMetrics commands from composer

.PHONY: metrics
metrics: up ### Run the composer/metrics
@echo "Running the psalm"
@$(DOCKER_DIR) ./composer metrics

# Generate commands

.PHONY: generate
generate: up ### Run the codeception generate test files in unit and integration suite, use FILE=filename to generate a specific file
@echo "Start generating the test files"
@if [ ! -z "$(FILE)" -a ! -f "tests/unit/$(FILE)Test.php" ]; then \
echo "File does not exists, generating now."; \
./vendor/bin/codecept generate:test unit $(FILE); \
else \
echo "FILE variable empty or file already generated"; \
fi
@if [ ! -z "$(FILE)" -a ! -f "tests/integration/$(FILE)Test.php" ]; then \
echo "File does not exists, generating now."; \
./vendor/bin/codecept generate:wpunit integration $(FILE); \
else \
echo "FILE variable empty or file already generated"; \
fi
@$(FILES_OWNERSHIP)
@echo "Files generated"
Loading