-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from hokoo/local-wp-tests
Dev local tests
- Loading branch information
Showing
15 changed files
with
250 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/.idea | ||
|
||
/vendor | ||
/wordpress-develop | ||
.phpunit.result.cache | ||
.phpcs.cache | ||
.phpcs.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
tests.init: | ||
cd ./tests/dev/ && bash ./init.sh | ||
|
||
tests.docker.up: | ||
cd ./tests/dev/ && docker-compose -p wpc-tests up -d | ||
|
||
tests.docker.down: | ||
cd ./tests/dev/ && docker-compose -p wpc-tests down | ||
|
||
tests.docker.build: | ||
cd ./tests/dev/ && docker-compose -p wpc-tests up -d --build php | ||
|
||
tests.docker.connect: | ||
cd ./tests/dev/ && docker-compose -p wpc-tests exec php bash | ||
|
||
tests.run: | ||
cd ./tests/dev/ && \ | ||
docker-compose -p wpc-tests exec php sh -c 'vendor/bin/phpunit -c phpunit.xml && vendor/bin/phpunit -c php-wp-unit.xml' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
PROJECT_NAME=WPC_TESTS | ||
DB_NAME=wpc-tests | ||
DB_USER=wordpress | ||
DB_PASSWORD=wordpress | ||
DB_ROOT_PASSWORD=wordpress | ||
DB_HOST=mysql | ||
|
||
PHP_VERSION=8.2 | ||
XDEBUG_PORT=9020 | ||
XDEBUG_MODE=debug | ||
XDEBUG_IDE_KEY=PHPSTORM | ||
EXTENSIONS_DISABLE="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
PROJECT_NAME=WPC_TESTS | ||
DB_NAME=wpc-tests | ||
DB_USER=wordpress | ||
DB_PASSWORD=wordpress | ||
DB_ROOT_PASSWORD=wordpress | ||
DB_HOST=mysql | ||
|
||
PHP_VERSION=8.2 | ||
XDEBUG_PORT=9020 | ||
XDEBUG_MODE=debug | ||
XDEBUG_IDE_KEY=PHPSTORM | ||
EXTENSIONS_DISABLE="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
version: "3" | ||
|
||
services: | ||
mysql: | ||
container_name: "${PROJECT_NAME}_mysql" | ||
image: mysql:5.7 | ||
stop_grace_period: 30s | ||
volumes: | ||
- ~/mysql-data/iTRON/wpConnections:/var/lib/mysql | ||
environment: | ||
MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD | ||
MYSQL_DATABASE: $DB_NAME | ||
MYSQL_USER: $DB_USER | ||
MYSQL_PASSWORD: $DB_PASSWORD | ||
ports: | ||
- "3066:3306" | ||
networks: | ||
- itron-network | ||
|
||
php: | ||
build: | ||
context: ./php | ||
args: | ||
PHP_VER: $PHP_VERSION | ||
container_name: "${PROJECT_NAME}_php" | ||
working_dir: /srv/web/ | ||
environment: | ||
PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025 | ||
DB_HOST: $DB_HOST | ||
DB_USER: $DB_USER | ||
DB_PASSWORD: $DB_PASSWORD | ||
DB_ROOT_PASSWORD: $DB_ROOT_PASSWORD | ||
DB_NAME: $DB_NAME | ||
PHP_FPM_USER: wodby | ||
PHP_FPM_GROUP: wodby | ||
PHP_XDEBUG: 1 | ||
PHP_XDEBUG_DEFAULT_ENABLE: 1 | ||
PHP_XDEBUG_CLIENT_PORT: $XDEBUG_PORT | ||
PHP_XDEBUG_MODE: $XDEBUG_MODE | ||
PHP_XDEBUG_IDEKEY: $XDEBUG_IDE_KEY | ||
PHP_EXTENSIONS_DISABLE: $EXTENSIONS_DISABLE | ||
volumes: | ||
- ../../:/srv/web/ | ||
- ./php.ini:/usr/local/etc/php/conf.d/php-sp-overrides.ini | ||
networks: | ||
- itron-network | ||
|
||
networks: | ||
itron-network: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
# if .env file does not exist, copy the template | ||
[ -f ./.env ] || cp ./dev/.env.template ./.env | ||
|
||
# Read the .env file | ||
source ./.env | ||
|
||
WP_DEV_DIR_NAME=wordpress-develop | ||
WP_DEV_DIR=../../${WP_DEV_DIR_NAME} | ||
|
||
# if wordpress-develop directory does not exist, clone the repository | ||
[ -d $WP_DEV_DIR ] || git clone https://github.com/WordPress/wordpress-develop $WP_DEV_DIR | ||
|
||
if [ ! -f $WP_DEV_DIR/wp-tests-config.php ]; then | ||
# copy the sample file | ||
cp "$WP_DEV_DIR"/wp-tests-config-sample.php $WP_DEV_DIR/wp-tests-config.php | ||
|
||
# remove all forward slashes in the end | ||
sed -i "s/youremptytestdbnamehere/$DB_NAME/" $WP_DEV_DIR/wp-tests-config.php | ||
sed -i "s/yourusernamehere/$DB_USER/" $WP_DEV_DIR/wp-tests-config.php | ||
sed -i "s/yourpasswordhere/$DB_PASSWORD/" $WP_DEV_DIR/wp-tests-config.php | ||
sed -i "s|localhost|${DB_HOST}|" $WP_DEV_DIR/wp-tests-config.php | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error_log = /var/log/php/error.log | ||
display_errors = On | ||
display_startup_errors = On | ||
log_errors = On | ||
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT | ||
html_errors = On | ||
|
||
xdebug.log = /var/log/php/xdebug.log | ||
xdebug.client_host = host.docker.internal | ||
xdebug.start_with_request = yes | ||
|
||
opcache.jit=0 | ||
opcache.jit_buffer_size=0 | ||
opcache.jit_debug=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ARG PHP_VER | ||
|
||
FROM wodby/wordpress-php:$PHP_VER | ||
|
||
LABEL maintainer="Igor Tron <[email protected]>" | ||
|
||
USER root | ||
|
||
RUN mkdir -p /var/log/php && chown -R wodby:wodby /var/log/php | ||
|
||
RUN echo 'alias ll="ls -la"' >> /etc/bash.bashrc | ||
RUN echo 'alias ll="ls -la"' >> /home/wodby/.bashrc | ||
|
||
USER wodby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
// Drop the database tables. | ||
// Remove tables created by WPC Client. | ||
global $wpdb; | ||
|
||
use iTRON\wpConnections\Helpers\Database; | ||
use iTRON\wpConnections\WPStorage; | ||
|
||
$client_name = $argv[1]; | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
require_once __DIR__ . '/../wordpress-develop/wp-tests-config.php'; | ||
require_once ABSPATH . 'wp-settings.php'; | ||
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | ||
require_once ABSPATH . 'wp-includes/class-wpdb.php'; | ||
|
||
|
||
|
||
$wpdb->select( DB_NAME, $wpdb->dbh ); | ||
|
||
$q = "DROP TABLE IF EXISTS " . $wpdb->prefix . | ||
WPStorage::CONNECTIONS_TABLE_PREFIX . | ||
Database::normalize_table_name( $client_name ); | ||
|
||
$result = $wpdb->query( $q ); | ||
|
||
echo PHP_EOL . "QUERY: " . $q . PHP_EOL; | ||
echo "Dropped tables: "; | ||
var_dump( $result ); | ||
echo PHP_EOL; | ||
|
||
// Close transaction. | ||
$wpdb->query( 'COMMIT;' ); | ||
|
||
// exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,37 @@ | ||
<?php | ||
|
||
// Define constants for the IDE. Never fired. | ||
if ( defined( 'PHPSTORM_META' ) ) { | ||
define( 'DOING_TESTS', 1 ); | ||
define( 'CLIENT_NAME', 'client-test' ); | ||
define( 'RELATION_NAME', 'relation-test' ); | ||
} | ||
|
||
use iTRON\wpConnections\Helpers\Database; | ||
use iTRON\wpConnections\WPStorage; | ||
|
||
$test_root = getenv( 'WP_TESTS_DIR' ) ? : dirname( __FILE__ ) . '/../wordpress-develop/tests/phpunit'; | ||
require_once $test_root . '/includes/functions.php'; | ||
|
||
tests_add_filter( 'muplugins_loaded', function() { | ||
// Remove tables created by WPC Client. | ||
global $wpdb; | ||
|
||
$q = "DROP TABLE IF EXISTS " . $wpdb->prefix . | ||
WPStorage::CONNECTIONS_TABLE_PREFIX . | ||
Database::normalize_table_name( CLIENT_NAME ); | ||
|
||
$wpdb->query( $q ); | ||
|
||
$q = "DROP TABLE IF EXISTS " . $wpdb->prefix . | ||
WPStorage::META_TABLE_PREFIX . | ||
Database::normalize_table_name( CLIENT_NAME ); | ||
|
||
$wpdb->query( $q ); | ||
} ); | ||
|
||
tests_add_filter( 'wpConnections/storage/installOnInit', function ( $installOnInit ) { | ||
return true; | ||
}, 10, 1 ); | ||
|
||
require $test_root . '/includes/bootstrap.php'; | ||
require_once $test_root . '/includes/bootstrap.php'; |