diff --git a/.gitignore b/.gitignore index 6f68bc7f65c25ceae8e856eb9ab25fa815acf0cd..63bb990a1793ee5ff8d6a300b46944b26f77b1d0 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .DS_Store -phpcs.xml phpunit.xml Thumbs.db wp-cli.local.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..6c1c666dcdf80d965ae2b65d25b19c328e8f3b4f --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,90 @@ +variables: + # Configure mysql service (https://hub.docker.com/_/mysql/) + MYSQL_DATABASE: wordpress_tests + MYSQL_ROOT_PASSWORD: mysql + +cache: + paths: + - $HOME/.composer + +before_script: + # Install dependencies + + # update the docker + - apt-get clean + - apt-get -yqq update + + # install the required packages for the running CI tests + - | + apt-get -yqqf install lsb-release zip unzip subversion mysql-client libicu-dev libpng-dev libbz2-dev --fix-missing + + if [[ $(lsb_release -a) =~ "stretch" ]]; then + apt-get -yqqf install default-libmysqlclient-dev --fix-missing + else + apt-get -yqqf install libmysqlclient-dev --fix-missing + fi + + # PHP extensions + - docker-php-ext-install mbstring mysqli intl gd zip bz2 + - docker-php-ext-enable mbstring mysqli intl gd zip bz2 + + # Install Composer + - curl -sS https://getcomposer.org/installer | php + - mv composer.phar /usr/local/bin/composer + - export PATH="$HOME/.composer/vendor/bin:$PATH" + + # Set up WordPress tests + - bash bin/install-wp-tests.sh $MYSQL_DATABASE root $MYSQL_ROOT_PASSWORD mysql latest true + + # PHPUnit + - | + if [[ $(php -v) =~ "PHP 7." ]]; then + composer global require "phpunit/phpunit=6.1.*" + else + composer global require "phpunit/phpunit=4.8.*" + fi + + # Install PHPCS and WPCS + - composer global require automattic/vipwpcs + - phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs,$HOME/.composer/vendor/automattic/vipwpcs + +PHPunit:PHP5.3:MySQL: + image: tetraweb/php:5.3 + services: + - mysql:5.6 + script: + - phpcs -n + - phpunit + allow_failure: true + +PHPunit:PHP5.6:MySQL: + image: php:5.6-stretch + services: + - mysql:5.6 + script: + - phpcs -n + - phpunit + +PHPunit:PHP7.0:MySQL: + image: php:7.0-stretch + services: + - mysql:5.6 + script: + - phpcs -n + - phpunit + +PHPunit:PHP7.1:MySQL: + image: php:7.1-stretch + services: + - mysql:5.6 + script: + - phpcs -n + - phpunit + +PHPunit:PHP7.2:MySQL: + image: php:7.2-stretch + services: + - mysql:5.6 + script: + - phpcs -n + - phpunit diff --git a/.travis.yml b/.travis.yml index d2b35d6e3b3d8b0589b3a1a02d9d612cd46d62f4..38e5608e534f0dee4b8520bd1e9a5f0a0d12cb44 100755 --- a/.travis.yml +++ b/.travis.yml @@ -46,8 +46,8 @@ before_script: fi - | if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then - composer global require wp-coding-standards/wpcs - phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs + composer global require automattic/vipwpcs + phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs,$HOME/.composer/vendor/automattic/vipwpcs fi script: diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 878881f0315b397fd3d758752702d4aa45edc8e0..364f83999f95f0cf17ef2696bc74c8f89cbe932a 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -95,7 +95,7 @@ install_wp() { install_test_suite() { # portable in-place argument for both GNU sed and Mac OSX sed if [[ $(uname -s) == 'Darwin' ]]; then - local ioption='-i .bak' + local ioption='-i.bak' else local ioption='-i' fi diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..4e25cc54973efb779494d6e92ec73a86183d7304 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,39 @@ +<?xml version="1.0"?> +<ruleset name="WordPress Coding Standards for Plugins"> + <description>Generally-applicable sniffs for WordPress plugins</description> + + <!-- + Pass some flags to PHPCS: + p flag: Show progress of the run. + s flag: Show sniff codes in all reports. + --> + <arg value="ps" /> + + <!-- Strip the filepaths down to the relevant bit. --> + <arg name="basepath" value="./" /> + + <!-- Check up to 8 files simultaneously. --> + <arg name="parallel" value="8" /> + + <!-- Only check the PHP files. --> + <arg name="extensions" value="php" /> + + <!-- Check all files in this directory and the directories below it. --> + <file>.</file> + + <!-- Exclude a few directories and autogenerated files. --> + <exclude-pattern>*/node_modules/*</exclude-pattern> + <exclude-pattern>*/vendor/</exclude-pattern> + + <rule ref="WordPress" /> + <rule ref="WordPressVIPMinimum" /> + <!--<rule ref="WordPress-VIP-Go" />--> + + <config name="minimum_supported_wp_version" value="4.9" /> + + <rule ref="WordPress.NamingConventions.PrefixAllGlobals"> + <properties> + <property name="prefixes" type="array" value="camo" /> + </properties> + </rule> +</ruleset> diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100644 index 4f1d0e5cf919397d4a3aff507b598e0075b9b047..0000000000000000000000000000000000000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,17 +0,0 @@ -<?xml version="1.0"?> -<ruleset name="WordPress Coding Standards for Plugins"> - <description>Generally-applicable sniffs for WordPress plugins</description> - - <rule ref="WordPress-Core" /> - <rule ref="WordPress-Docs" /> - - <!-- Check all PHP files in directory tree by default. --> - <arg name="extensions" value="php"/> - <file>.</file> - - <!-- Show progress and sniff codes in all reports --> - <arg value="ps"/> - - <exclude-pattern>*/node_modules/*</exclude-pattern> - <exclude-pattern>*/vendor/*</exclude-pattern> -</ruleset> diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4e5b3cc05118e55f846186a2136b7dab1d94a65f..ce4684590410004d383ac4c99a0bfa098387b94d 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,27 +5,27 @@ * @package Camo_Image_Proxy */ -$_tests_dir = getenv( 'WP_TESTS_DIR' ); +$camo_tests_dir = getenv( 'WP_TESTS_DIR' ); -if ( ! $_tests_dir ) { - $_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; +if ( ! $camo_tests_dir ) { + $camo_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; } -if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) { - echo "Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; +if ( ! file_exists( $camo_tests_dir . '/includes/functions.php' ) ) { + echo "Could not find $camo_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped exit( 1 ); } // Give access to tests_add_filter() function. -require_once $_tests_dir . '/includes/functions.php'; +require_once $camo_tests_dir . '/includes/functions.php'; /** * Manually load the plugin being tested. */ -function _manually_load_plugin() { +function camo_manually_load_plugin() { require dirname( dirname( __FILE__ ) ) . '/camo-image-proxy.php'; } -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); +tests_add_filter( 'muplugins_loaded', 'camo_manually_load_plugin' ); // Start up the WP testing environment. -require $_tests_dir . '/includes/bootstrap.php'; +require $camo_tests_dir . '/includes/bootstrap.php'; diff --git a/tests/test-sample.php b/tests/test-sample.php index f4e62d1791e546d84193345b8003ff3186c9fdb3..9d79786fb8cd3b3224f4828bcaca0f6a52ba23bd 100755 --- a/tests/test-sample.php +++ b/tests/test-sample.php @@ -13,7 +13,7 @@ class SampleTest extends WP_UnitTestCase { /** * A single example test. */ - function test_sample() { + public function test_sample() { // Replace this with some actual testing code. $this->assertTrue( true ); }