Skip to content

Commit

Permalink
Merge pull request #20 from wppunk/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wppunk authored Sep 5, 2021
2 parents c5fedbf + 446eb81 commit 824dec3
Show file tree
Hide file tree
Showing 20 changed files with 5,389 additions and 30,514 deletions.
23 changes: 0 additions & 23 deletions .codeception/_config/params.example.php

This file was deleted.

22 changes: 0 additions & 22 deletions .codeception/_config/params.github-actions.php

This file was deleted.

28 changes: 20 additions & 8 deletions .codeception/_config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,32 @@
* @author {AUTHOR}
*/

use Codeception\Exception\ConfigurationException;
use Codeception\Lib\ParamsLoader;

global $argv;

if ( ! in_array( 'acceptance', $argv, true ) ) {
return [];
}

$config = '.codeception/_config/params.github-actions.php';
if ( in_array( 'github-actions', $argv, true ) && file_exists( $config ) ) {
return include $config;
if ( ! in_array( 'github-actions', $argv, true ) ) {
try {
( new ParamsLoader() )->load( '.env.development' );
} catch ( ConfigurationException $e ) {
throw new Exception( 'If you wan\'t to run your tests locally, then create the `.env.development` configuration file.' );
}
}

$config = '.codeception/_config/params.local.php';
if ( file_exists( $config ) ) {
return include $config;
}
return [
'WP_URL' => getenv( 'WP_URL' ),
'WP_ADMIN_USERNAME' => getenv( 'WP_ADMIN_USERNAME' ),
'WP_ADMIN_PASSWORD' => getenv( 'WP_ADMIN_PASSWORD' ),
'WP_ADMIN_PATH' => getenv( 'WP_ADMIN_PATH' ),
'DB_HOST' => getenv( 'DB_HOST' ),
'DB_NAME' => getenv( 'DB_NAME' ),
'DB_USER' => getenv( 'DB_USER' ),
'DB_PASSWORD' => getenv( 'DB_PASSWORD' ),
'DB_TABLE_PREFIX' => getenv( 'DB_TABLE_PREFIX' ),
];

die( "No valid config provided.\nPlease use 'params.example.php' as a template to create your own 'params.local.php'.\n" );
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
WP_URL="http://wpplugin.local"
WP_ADMIN_USERNAME="admin"
WP_ADMIN_PASSWORD="pass"
WP_ADMIN_PATH="/wp-admin"
DB_HOST="127.0.0.1"
DB_NAME="local"
DB_USER="root"
DB_PASSWORD="root"
DB_TABLE_PREFIX="wp_"
22 changes: 22 additions & 0 deletions .github/workflows/plugin-name.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,30 @@
DirectoryIndex index.php index.html /index.php

<Directory /home/runner/work/WPPlugin/WPPlugin/wordpress>
Options FollowSymLinks
DirectoryIndex index.php index.html /index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

<VirtualHost *:443>
DocumentRoot /home/runner/work/WPPlugin/WPPlugin/wordpress
ServerName plugin-name.test

ErrorLog /home/runner/work/WPPlugin/WPPlugin/logs/error.log
CustomLog /home/runner/work/WPPlugin/WPPlugin/logs/access.log combined

DirectoryIndex index.php index.html /index.php

<Directory /home/runner/work/WPPlugin/WPPlugin/wordpress>
Options FollowSymLinks
DirectoryIndex index.php index.html /index.php
AllowOverride All
Require all granted
</Directory>

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/plugin-name.test/plugin-name.test.pem
SSLCertificateKeyFile /etc/apache2/ssl/plugin-name.test/plugin-name.test-key.pem
</VirtualHost>
69 changes: 56 additions & 13 deletions .github/workflows/plugin-name.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ jobs:
php-extensions: mysql
php-ini-values: post_max_size=256M
wp-directory: wordpress
wp-plugins-directory: wordpress/wp-content/plugins
wp-plugins-directory: wordpress/wp-content/plugins/plugin-name/
DB_HOST: 127.0.0.1
DB_TABLE_PREFIX: wp_
DB_NAME: test_db
DB_USER: user
DB_PASSWORD: passw0rd
WP_URL: http://plugin-name.test
WP_URL: https://plugin-name.test
WP_ADMIN_PATH: /wp-admin
WP_DOMAIN: plugin-name.test
WP_ADMIN_USERNAME: admin
WP_ADMIN_PASSWORD: admin
Expand All @@ -46,6 +47,33 @@ jobs:
with:
path: ${{ env.wp-plugins-directory }}

- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.php-extensions }}
key: ${{ env.php-ext-cache-key }}
env:
update: true

- name: Cache extensions
uses: actions/cache@v1
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: pecl
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.php-extensions }}
ini-values: ${{ env.php-ini-values }}
env:
update: true

- name: Validate composer.json and composer.lock
working-directory: ${{ env.wp-plugins-directory }}
run: composer validate
Expand All @@ -72,16 +100,6 @@ jobs:
working-directory: ${{ env.wp-plugins-directory }}
run: npm run build:production

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: pecl
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.php-extensions }}
ini-values: ${{ env.php-ini-values }}
env:
update: true

- name: Install WP CLI
run: |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Expand All @@ -104,12 +122,22 @@ jobs:
working-directory: ${{ env.wp-plugins-directory }}
run: mysqldump --column-statistics=0 --host="${{ env.DB_HOST }}" --user="${{ env.DB_USER }}" --password="${{ env.DB_PASSWORD }}" ${{ env.DB_NAME }} > .codeception/_data/dump.sql


- name: Setup hosts
run: |
echo ${{ env.DB_HOST }} ${{ env.WP_DOMAIN }} | sudo tee -a /etc/hosts
cat /etc/hosts
- name: Force SSL
run: |
sudo apt install libnss3-tools -y
wget https://github.com/FiloSottile/mkcert/releases/download/v1.4.3/mkcert-v1.4.3-linux-amd64 -O mkcert
chmod +x mkcert
sudo mv mkcert /usr/local/bin/
mkcert -install
localcaroot=$(mkcert -CAROOT)
sudo mkdir -p /etc/apache2/ssl/${{ env.WP_DOMAIN }} && cd $_
sudo CAROOT=$localcaroot mkcert ${{ env.WP_DOMAIN }}
- name: Install & configure Apache
run: |
sudo add-apt-repository ppa:ondrej/php
Expand All @@ -119,9 +147,24 @@ jobs:
sudo cp ${{ env.wp-plugins-directory }}/.github/workflows/plugin-name.conf /etc/apache2/sites-available/plugin-name.conf
sudo a2enmod headers
sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2ensite plugin-name
sudo apachectl configtest
sudo service apache2 restart
- name: Set .htaccess
working-directory: ${{ env.wp-directory }}
run: |
echo '# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress' > .htaccess
- name: Setup Chromedriver
uses: nanasess/setup-chromedriver@master

Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
.DS_Store
/.idea/
/.codeception/_cache/
/.codeeception/_output/
/.codeception/_output/
/.codeception/_config/params.local.php
/.codeception/_support/_generated/
/assets/build/
/node_modules/
/vendor/
/vendor-bin/
/vendor_prefixed/
.phpcs.cache
.env.development
.env.production
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run cs -- --silent --continue-on-error
32 changes: 31 additions & 1 deletion .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="100"/>
<arg name="cache" value=".phpcs.cache"/>

<rule ref="WordPress">
<!-- PSR4 -->
Expand Down Expand Up @@ -42,4 +41,35 @@
<severity>0</severity>
</rule>
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found"/>

<!-- Tests -->
<rule ref="Squiz.Commenting.FunctionComment.EmptyThrows">
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
<exclude-pattern>\.tests/php/*</exclude-pattern>
</rule>
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
<exclude-pattern>\.tests/php/*</exclude-pattern>
</rule>
<rule ref="WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid">
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
<exclude-pattern>\.tests/php/*</exclude-pattern>
</rule>
<rule ref="WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase">
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
<exclude-pattern>\.tests/php/*</exclude-pattern>
</rule>
<rule ref="WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase">
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
<exclude-pattern>\.tests/php/*</exclude-pattern>
</rule>
<rule ref="WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase">
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
<exclude-pattern>\.tests/php/*</exclude-pattern>
</rule>
<rule ref="Squiz.NamingConventions">
<exclude name="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore"/>
<include-pattern>\.codeception/_support/*</include-pattern>
<include-pattern>\.tests/php/*</include-pattern>
</rule>
</ruleset>
3 changes: 2 additions & 1 deletion .tests/php/acceptance.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ modules:
adminPassword: '%WP_ADMIN_PASSWORD%'
adminPath: '%WP_ADMIN_PATH%'
capabilities:
acceptInsecureCerts: true
# Used in more recent releases of Selenium.
"goog:chromeOptions":
# Headless config for production, redefined in env section below.
# args: ["--user-agent=wp-browser", "--headless"]
# Non-headless config for debugging.
args: ["--user-agent=wp-browser"]
args: ["--user-agent=wp-browser", "--ignore-certificate-errors"]

env:
github-actions:
Expand Down
18 changes: 6 additions & 12 deletions .tests/php/acceptance/SettingsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,20 @@

/**
* Class SettingsCest.
*
* phpcs:ignoreFile WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
*
* @since {VERSION}
*/
class SettingsCest {

/**
* Check a Settings Page
*
* @since {VERSION}
*
* @param \AcceptanceTester $I Actor.
* @param AcceptanceTester $i Actor.
*
* @throws \Exception Something when wrong.
* @throws Exception Something when wrong.
*/
public function visitSettingsPage( AcceptanceTester $I ) {
$I->loginAsAdmin();
$I->amOnAdminPage( '/admin.php?page=plugin-name' );
$I->see( 'Plugin Name Settings' );
public function visitSettingsPage( AcceptanceTester $i ): void {
$i->loginAsAdmin();
$i->amOnAdminPage( '/admin.php?page=plugin-name' );
$i->see( 'Plugin Name Settings' );
}

}
Loading

0 comments on commit 824dec3

Please sign in to comment.