Skip to content

Commit

Permalink
PSR-14 implementation
Browse files Browse the repository at this point in the history
Polish repo and try PSR-14
  • Loading branch information
overclokk authored Oct 7, 2023
2 parents 3055c7a + 2c3d610 commit 6ce118e
Show file tree
Hide file tree
Showing 126 changed files with 5,284 additions and 3,495 deletions.
14 changes: 14 additions & 0 deletions .docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Docker only
PROJECT_NAME="event"
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"
6 changes: 6 additions & 0 deletions .docker/codecept
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# 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/plugins/"${PROJECT_NAME}" "${PROJECT_NAME}"_test sh -c "vendor/bin/codecept ${*}"
6 changes: 6 additions & 0 deletions .docker/composer
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# 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/plugins/"${PROJECT_NAME}" --rm wordpress sh -c "composer ${*}"
62 changes: 62 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: '3.7'
services:
wordpress:
build:
context: ./wordpress
args:
PHP_VERSION: ${PHP_VERSION}
WP_VERSION: ${WP_VERSION}
container_name: ${PROJECT_NAME:-wordpress}_test
restart: always
ports:
- ${WP_PORT}:80
environment:
WORDPRESS_DB_HOST: ${DB_HOST:-mysql}
WORDPRESS_DB_NAME: ${DB_NAME:-test}
WORDPRESS_DB_USER: ${DB_USER:-root}
WORDPRESS_DB_PASSWORD: ${DB_PASSWORD:-root}
WORDPRESS_TABLE_PREFIX: ${TABLE_PREFIX:-wp_}
WORDPRESS_DEBUG: 1
volumes:
- ../:/var/www/html/wp-content/plugins/${PROJECT_NAME:-wordpress}
- ../tests/_output/:/var/www/html/wp-content/plugins/${PROJECT_NAME:-wordpress}/tests/_output/
- ./mu-plugins/:/var/www/html/wp-content/mu-plugins/
depends_on:
- mysql
networks:
integration_test_networks:

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

phpmyadmin:
depends_on:
- mysql
image: phpmyadmin/phpmyadmin:${PMA_VERSION:-latest}
container_name: ${PROJECT_NAME}_phpmyadmin_test
restart: always
ports:
- ${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:
- integration_test_networks

networks:
integration_test_networks:
driver: bridge
39 changes: 39 additions & 0 deletions .docker/wordpress/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ARG PHP_VERSION
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 \
pdo_mysql

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \
chmod +x wp-cli.phar && \
mv wp-cli.phar /usr/local/bin/wp
9 changes: 0 additions & 9 deletions .editorconfig

This file was deleted.

29 changes: 12 additions & 17 deletions .env
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
WP_ROOT_FOLDER="/tmp/wordpress"
TEST_SITE_WP_ADMIN_PATH="/wp-admin"
TEST_SITE_DB_NAME="test"
TEST_SITE_DB_HOST="localhost"
TEST_SITE_DB_USER="root"
TEST_SITE_DB_PASSWORD=""
TEST_SITE_TABLE_PREFIX="wp_"
TEST_DB_NAME="wploader"
TEST_DB_HOST="localhost"
TEST_DB_USER="root"
TEST_DB_PASSWORD=""
TEST_TABLE_PREFIX="wp_"
TEST_SITE_WP_URL="http://wp.localhost"
TEST_SITE_WP_DOMAIN="wp.localhost"
TEST_SITE_ADMIN_EMAIL="[email protected]"
TEST_SITE_ADMIN_USERNAME="admin"
TEST_SITE_ADMIN_PASSWORD="password"
# Codeception configuration file
ROOT_FOLDER="../../../"

DB_HOST="localhost"
DB_NAME="test"
DB_USER="root"
DB_PASSWORD="root"

TABLE_PREFIX="wp_"

DOMAIN="localhost"
ADMIN_EMAIL="[email protected]"
37 changes: 37 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CS - File lint and file validation

on:
push:
pull_request:
paths:
- '**workflows/lint.yml'
- '**.php'
- '**phpcs.xml.dist'
- '**composer.json'

jobs:
lint:
name: ✔ CS check al files

runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '--skip ci') && !github.event.pull_request.draft"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Validate php files
run: find ./src/ ./tests/ -type f -name '*.php' -print0 | xargs -0 -L 1 -P 4 -- php -l

- uses: ramsey/composer-install@v2

- name: Coding standard
run: composer run cs
31 changes: 31 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Static Analysis

on:
pull_request:
push:
paths:
- '**workflows/static-analysis.yml'
- '**.php'
- '**psalm.xml'
- '**composer.json'

jobs:
tests:
name: Static Analysis for PHP

runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '--skip ci') && !github.event.pull_request.draft"

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4

- uses: ramsey/composer-install@v2

- name: Psalm
run: vendor/bin/psalm
94 changes: 94 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: CI

env:
PROJECT_KIND: plugins
DB_HOST: localhost
DB_NAME: test
DB_USER: root
DB_PASSWORD: root
TABLE_PREFIX: wp_
APP_FOLDER_PATH: /tmp/app
APP_PORT: 8888
APP_HOST: localhost
APP_USER: root
APP_PASSWORD: root

on:
workflow_dispatch:
pull_request:
push:
branches:
- master


jobs:

tests:
name: 🐘 Tests on PHP ${{matrix.php_versions}} & APP version ${{matrix.app_versions}}

strategy:
matrix:
php_versions: ['7.4']
app_versions: ['6.0']

runs-on: ubuntu-latest
continue-on-error: ${{ matrix.php_versions == '8.2' }}
if: "!contains(github.event.head_commit.message, '--skip ci') && !github.event.pull_request.draft"

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{matrix.php_versions}}

- name: Start MySQL
run: |
sudo systemctl start mysql.service
mysql -e "CREATE DATABASE IF NOT EXISTS ${{env.DB_NAME}};" -u${{env.DB_USER}} -p${{env.DB_PASSWORD}}
- name: Install CLI
run: |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp cli info
- name: Create folder for running the App
run: mkdir -p ${{env.APP_FOLDER_PATH}}

- name: Install App
working-directory: ${{env.APP_FOLDER_PATH}}
run: |
wp core download --version="${{matrix.app_versions}}"
wp config create --dbname="${{env.DB_NAME}}" --dbuser="${{env.DB_USER}}" --dbpass="${{env.DB_PASSWORD}}" --dbhost="${{env.DB_HOST}}" --dbprefix="${{env.TABLE_PREFIX}}"
wp core install --url="${{env.APP_HOST}}:${{env.APP_PORT}}" --title="Test" --admin_user="${{env.APP_USER}}" --admin_password="${{env.APP_PASSWORD}}" --admin_email="${{env.APP_USER}}@${{env.APP_HOST}}.test" --skip-email
wp core update-db
cp -r $GITHUB_WORKSPACE ${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{ github.event.repository.name }}
- uses: "ramsey/composer-install@v2"
with:
working-directory: "${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{ github.event.repository.name }}"

- name: Activate ${{ github.event.repository.name }}
working-directory: ${{env.APP_FOLDER_PATH}}
run: |
wp plugin deactivate --all
wp site empty --yes
wp plugin activate ${{ github.event.repository.name }}
wp plugin list --status=active
chmod -R 777 wp-content/${{env.PROJECT_KIND}}/${{ github.event.repository.name }}
ls -la wp-content/${{env.PROJECT_KIND}}/${{ github.event.repository.name }}
wp db export wp-content/${{env.PROJECT_KIND}}/${{ github.event.repository.name }}/tests/_data/dump.sql
- name: Build codeception
working-directory: ${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{ github.event.repository.name }}
run: ./vendor/bin/codecept build

- name: Run Unit & Integration test
working-directory: ${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{ github.event.repository.name }}
run: |
./vendor/bin/codecept run unit --coverage-text
./vendor/bin/codecept run integration
composer bench
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Composer
/vendor/

/_others/
# Codeception
codeception.yml

# Rector
rector.php

# Common File
*.local
codeception.yml
*.lock

c3.php
infection.log
infection-log.txt
infection.json
*.phar
Loading

0 comments on commit 6ce118e

Please sign in to comment.