Skip to content

Commit 824dec3

Browse files
authored
Merge pull request #20 from wppunk/dev
2 parents c5fedbf + 446eb81 commit 824dec3

20 files changed

+5389
-30514
lines changed

.codeception/_config/params.example.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

.codeception/_config/params.github-actions.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

.codeception/_config/params.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,32 @@
1212
* @author {AUTHOR}
1313
*/
1414

15+
use Codeception\Exception\ConfigurationException;
16+
use Codeception\Lib\ParamsLoader;
17+
1518
global $argv;
1619

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

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

26-
$config = '.codeception/_config/params.local.php';
27-
if ( file_exists( $config ) ) {
28-
return include $config;
29-
}
32+
return [
33+
'WP_URL' => getenv( 'WP_URL' ),
34+
'WP_ADMIN_USERNAME' => getenv( 'WP_ADMIN_USERNAME' ),
35+
'WP_ADMIN_PASSWORD' => getenv( 'WP_ADMIN_PASSWORD' ),
36+
'WP_ADMIN_PATH' => getenv( 'WP_ADMIN_PATH' ),
37+
'DB_HOST' => getenv( 'DB_HOST' ),
38+
'DB_NAME' => getenv( 'DB_NAME' ),
39+
'DB_USER' => getenv( 'DB_USER' ),
40+
'DB_PASSWORD' => getenv( 'DB_PASSWORD' ),
41+
'DB_TABLE_PREFIX' => getenv( 'DB_TABLE_PREFIX' ),
42+
];
3043

31-
die( "No valid config provided.\nPlease use 'params.example.php' as a template to create your own 'params.local.php'.\n" );

.env.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
WP_URL="http://wpplugin.local"
2+
WP_ADMIN_USERNAME="admin"
3+
WP_ADMIN_PASSWORD="pass"
4+
WP_ADMIN_PATH="/wp-admin"
5+
DB_HOST="127.0.0.1"
6+
DB_NAME="local"
7+
DB_USER="root"
8+
DB_PASSWORD="root"
9+
DB_TABLE_PREFIX="wp_"

.github/workflows/plugin-name.conf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,30 @@
88
DirectoryIndex index.php index.html /index.php
99

1010
<Directory /home/runner/work/WPPlugin/WPPlugin/wordpress>
11+
Options FollowSymLinks
1112
DirectoryIndex index.php index.html /index.php
1213
AllowOverride All
1314
Require all granted
1415
</Directory>
1516
</VirtualHost>
17+
18+
<VirtualHost *:443>
19+
DocumentRoot /home/runner/work/WPPlugin/WPPlugin/wordpress
20+
ServerName plugin-name.test
21+
22+
ErrorLog /home/runner/work/WPPlugin/WPPlugin/logs/error.log
23+
CustomLog /home/runner/work/WPPlugin/WPPlugin/logs/access.log combined
24+
25+
DirectoryIndex index.php index.html /index.php
26+
27+
<Directory /home/runner/work/WPPlugin/WPPlugin/wordpress>
28+
Options FollowSymLinks
29+
DirectoryIndex index.php index.html /index.php
30+
AllowOverride All
31+
Require all granted
32+
</Directory>
33+
34+
SSLEngine on
35+
SSLCertificateFile /etc/apache2/ssl/plugin-name.test/plugin-name.test.pem
36+
SSLCertificateKeyFile /etc/apache2/ssl/plugin-name.test/plugin-name.test-key.pem
37+
</VirtualHost>

.github/workflows/plugin-name.yml

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ jobs:
1616
php-extensions: mysql
1717
php-ini-values: post_max_size=256M
1818
wp-directory: wordpress
19-
wp-plugins-directory: wordpress/wp-content/plugins
19+
wp-plugins-directory: wordpress/wp-content/plugins/plugin-name/
2020
DB_HOST: 127.0.0.1
2121
DB_TABLE_PREFIX: wp_
2222
DB_NAME: test_db
2323
DB_USER: user
2424
DB_PASSWORD: passw0rd
25-
WP_URL: http://plugin-name.test
25+
WP_URL: https://plugin-name.test
26+
WP_ADMIN_PATH: /wp-admin
2627
WP_DOMAIN: plugin-name.test
2728
WP_ADMIN_USERNAME: admin
2829
WP_ADMIN_PASSWORD: admin
@@ -46,6 +47,33 @@ jobs:
4647
with:
4748
path: ${{ env.wp-plugins-directory }}
4849

50+
- name: Setup cache environment
51+
id: cache-env
52+
uses: shivammathur/cache-extensions@v1
53+
with:
54+
php-version: ${{ matrix.php-versions }}
55+
extensions: ${{ env.php-extensions }}
56+
key: ${{ env.php-ext-cache-key }}
57+
env:
58+
update: true
59+
60+
- name: Cache extensions
61+
uses: actions/cache@v1
62+
with:
63+
path: ${{ steps.cache-env.outputs.dir }}
64+
key: ${{ steps.cache-env.outputs.key }}
65+
restore-keys: ${{ steps.cache-env.outputs.key }}
66+
67+
- name: Setup PHP
68+
uses: shivammathur/setup-php@v2
69+
with:
70+
tools: pecl
71+
php-version: ${{ matrix.php-versions }}
72+
extensions: ${{ env.php-extensions }}
73+
ini-values: ${{ env.php-ini-values }}
74+
env:
75+
update: true
76+
4977
- name: Validate composer.json and composer.lock
5078
working-directory: ${{ env.wp-plugins-directory }}
5179
run: composer validate
@@ -72,16 +100,6 @@ jobs:
72100
working-directory: ${{ env.wp-plugins-directory }}
73101
run: npm run build:production
74102

75-
- name: Setup PHP
76-
uses: shivammathur/setup-php@v2
77-
with:
78-
tools: pecl
79-
php-version: ${{ matrix.php-versions }}
80-
extensions: ${{ env.php-extensions }}
81-
ini-values: ${{ env.php-ini-values }}
82-
env:
83-
update: true
84-
85103
- name: Install WP CLI
86104
run: |
87105
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
@@ -104,12 +122,22 @@ jobs:
104122
working-directory: ${{ env.wp-plugins-directory }}
105123
run: mysqldump --column-statistics=0 --host="${{ env.DB_HOST }}" --user="${{ env.DB_USER }}" --password="${{ env.DB_PASSWORD }}" ${{ env.DB_NAME }} > .codeception/_data/dump.sql
106124

107-
108125
- name: Setup hosts
109126
run: |
110127
echo ${{ env.DB_HOST }} ${{ env.WP_DOMAIN }} | sudo tee -a /etc/hosts
111128
cat /etc/hosts
112129
130+
- name: Force SSL
131+
run: |
132+
sudo apt install libnss3-tools -y
133+
wget https://github.com/FiloSottile/mkcert/releases/download/v1.4.3/mkcert-v1.4.3-linux-amd64 -O mkcert
134+
chmod +x mkcert
135+
sudo mv mkcert /usr/local/bin/
136+
mkcert -install
137+
localcaroot=$(mkcert -CAROOT)
138+
sudo mkdir -p /etc/apache2/ssl/${{ env.WP_DOMAIN }} && cd $_
139+
sudo CAROOT=$localcaroot mkcert ${{ env.WP_DOMAIN }}
140+
113141
- name: Install & configure Apache
114142
run: |
115143
sudo add-apt-repository ppa:ondrej/php
@@ -119,9 +147,24 @@ jobs:
119147
sudo cp ${{ env.wp-plugins-directory }}/.github/workflows/plugin-name.conf /etc/apache2/sites-available/plugin-name.conf
120148
sudo a2enmod headers
121149
sudo a2enmod rewrite
150+
sudo a2enmod ssl
122151
sudo a2ensite plugin-name
152+
sudo apachectl configtest
123153
sudo service apache2 restart
124154
155+
- name: Set .htaccess
156+
working-directory: ${{ env.wp-directory }}
157+
run: |
158+
echo '# BEGIN WordPress
159+
RewriteEngine On
160+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
161+
RewriteBase /
162+
RewriteRule ^index\.php$ - [L]
163+
RewriteCond %{REQUEST_FILENAME} !-f
164+
RewriteCond %{REQUEST_FILENAME} !-d
165+
RewriteRule . /index.php [L]
166+
# END WordPress' > .htaccess
167+
125168
- name: Setup Chromedriver
126169
uses: nanasess/setup-chromedriver@master
127170

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
.DS_Store
22
/.idea/
33
/.codeception/_cache/
4-
/.codeeception/_output/
4+
/.codeception/_output/
55
/.codeception/_config/params.local.php
66
/.codeception/_support/_generated/
77
/assets/build/
88
/node_modules/
99
/vendor/
1010
/vendor-bin/
1111
/vendor_prefixed/
12-
.phpcs.cache
12+
.env.development
13+
.env.production

.husky/pre-push

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run cs -- --silent --continue-on-error

.phpcs.xml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<arg name="colors"/>
1515
<arg name="extensions" value="php"/>
1616
<arg name="parallel" value="100"/>
17-
<arg name="cache" value=".phpcs.cache"/>
1817

1918
<rule ref="WordPress">
2019
<!-- PSR4 -->
@@ -42,4 +41,35 @@
4241
<severity>0</severity>
4342
</rule>
4443
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found"/>
44+
45+
<!-- Tests -->
46+
<rule ref="Squiz.Commenting.FunctionComment.EmptyThrows">
47+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
48+
<exclude-pattern>\.tests/php/*</exclude-pattern>
49+
</rule>
50+
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
51+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
52+
<exclude-pattern>\.tests/php/*</exclude-pattern>
53+
</rule>
54+
<rule ref="WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid">
55+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
56+
<exclude-pattern>\.tests/php/*</exclude-pattern>
57+
</rule>
58+
<rule ref="WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase">
59+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
60+
<exclude-pattern>\.tests/php/*</exclude-pattern>
61+
</rule>
62+
<rule ref="WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase">
63+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
64+
<exclude-pattern>\.tests/php/*</exclude-pattern>
65+
</rule>
66+
<rule ref="WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase">
67+
<exclude-pattern>\.codeception/_support/*</exclude-pattern>
68+
<exclude-pattern>\.tests/php/*</exclude-pattern>
69+
</rule>
70+
<rule ref="Squiz.NamingConventions">
71+
<exclude name="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore"/>
72+
<include-pattern>\.codeception/_support/*</include-pattern>
73+
<include-pattern>\.tests/php/*</include-pattern>
74+
</rule>
4575
</ruleset>

.tests/php/acceptance.suite.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ modules:
4949
adminPassword: '%WP_ADMIN_PASSWORD%'
5050
adminPath: '%WP_ADMIN_PATH%'
5151
capabilities:
52+
acceptInsecureCerts: true
5253
# Used in more recent releases of Selenium.
5354
"goog:chromeOptions":
5455
# Headless config for production, redefined in env section below.
5556
# args: ["--user-agent=wp-browser", "--headless"]
5657
# Non-headless config for debugging.
57-
args: ["--user-agent=wp-browser"]
58+
args: ["--user-agent=wp-browser", "--ignore-certificate-errors"]
5859

5960
env:
6061
github-actions:

0 commit comments

Comments
 (0)