Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #880 Update tests base #925

Merged
merged 18 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 50 additions & 50 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
name: Unit/Integration tests

on:
pull_request:
branches:
- trunk
- develop
- branch-*
pull_request:
branches:
- trunk
- develop
- branch-*

jobs:
run:
runs-on: ${{ matrix.operating-system }}
run:
runs-on: ${{ matrix.operating-system }}

strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4']
wp-versions: ['latest']
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.0', '8.1', '8.2']
wp-versions: ['latest']

name: WP ${{ matrix.wp-versions }} with PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}.
name: WP ${{ matrix.wp-versions }} with PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}.

env:
WP_TESTS_DIR: "/tmp/tests/phpunit"
WP_CORE_DIR: "/tmp/wordpress-develop"
IMAGIFY_TESTS_API_KEY: ${{ secrets.IMAGIFY_TESTS_API_KEY }}
env:
WP_TESTS_DIR: "/tmp/tests/phpunit"
WP_CORE_DIR: "/tmp/wordpress-develop"
IMAGIFY_TESTS_API_KEY: ${{ secrets.IMAGIFY_TESTS_API_KEY }}

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none # XDebug can be enabled here 'coverage: xdebug'
tools: composer:v2, phpunit
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none # XDebug can be enabled here 'coverage: xdebug'
tools: composer:v2, phpunit

- name: Start mysql service
run: sudo /etc/init.d/mysql start
- name: Start mysql service
run: sudo /etc/init.d/mysql start

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-scripts
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-scripts --ignore-platform-reqs

- name: Install tests
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:3306 ${{ matrix.wp-versions }}
- name: Install tests
run: bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:3306 ${{ matrix.wp-versions }}

- name: Mysql8 auth plugin workaround
run: sudo mysql -u root -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';"
- name: Mysql8 auth plugin workaround
run: sudo mysql -u root -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';"

- name: Test
run: composer run-tests
- name: Test
run: composer run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.3']
php-versions: ['7.3', '7.4']
wp-versions: ['5.3']

name: WP ${{ matrix.wp-versions }} with PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}.
Expand All @@ -27,19 +27,36 @@ jobs:

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mysqli
coverage: none # XDebug can be enabled here 'coverage: xdebug'
tools: composer:v2
tools: composer:v2, phpunit

- name: Start mysql service
run: sudo /etc/init.d/mysql start

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Mysql8 auth plugin workaround
run: sudo mysql -u root -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';"

Expand All @@ -49,8 +66,8 @@ jobs:
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Remove unmet dependencies by legacy versions
run: composer remove --dev --no-scripts coenjacobs/mozart
- name: Require PHPUnit 7.5 for WP compatibility
run: composer require --dev --no-scripts phpunit/phpunit "^7.5" -W

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-scripts
Expand Down
69 changes: 0 additions & 69 deletions .github/workflows/test_php8.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
composer.lock
package-lock.json
/_dev/node_modules
.phpunit.result.cache
92 changes: 82 additions & 10 deletions Tests/Integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@

namespace Imagify\Tests\Integration;

use Brain\Monkey;
use Imagify;
use Imagify\Tests\TestCaseTrait;
use ReflectionObject;
use WPMedia\PHPUnit\Integration\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase {
use TestCaseTrait;

protected $useApi = true;
protected $api_credentials_config_file = 'imagify-api.php';
protected $invalidApiKey = '1234567890abcdefghijklmnopqrstuvwxyz';
protected $originalImagifyInstance;
protected $originalApiKeyOption;
protected $config;

/**
* Prepares the test environment before each test.
*/
public function setUp() {
parent::setUp();
Monkey\setUp();
public function set_up() {
parent::set_up();

if ( empty( $this->config ) ) {
$this->loadTestDataConfig();
}

if ( ! $this->useApi ) {
return;
Expand All @@ -35,9 +36,8 @@ public function setUp() {
/**
* Cleans up the test environment after each test.
*/
public function tearDown() {
Monkey\tearDown();
parent::tearDown();
public function tear_down() {
parent::tear_down();

if ( ! $this->useApi ) {
return;
Expand All @@ -48,6 +48,23 @@ public function tearDown() {
update_imagify_option( 'api_key', $this->originalApiKeyOption );
}

public function configTestData() {
if ( empty( $this->config ) ) {
$this->loadTestDataConfig();
}

return isset( $this->config['test_data'] )
? $this->config['test_data']
: $this->config;
}

protected function loadTestDataConfig() {
$obj = new ReflectionObject( $this );
$filename = $obj->getFileName();

$this->config = $this->getTestData( dirname( $filename ), basename( $filename, '.php' ) );
}

/**
* Gets the credential's value from either an environment variable (stored locally on the machine or CI) or from a
* local constant defined in `tests/env/local/imagify-api.php`.
Expand Down Expand Up @@ -86,4 +103,59 @@ protected function getApiCredential( $name ) {

return constant( $name );
}

/**
* Set the singleton's `$instance` property to the given instance.
*
* @param string $class Name of the target class.
* @param mixed $instance Instance of the target object.
*
* @return mixed Previous value.
* @throws ReflectionException Throws an exception if property does not exist.
*
*/
protected function setSingletonInstance( $class, $instance ) {
return $this->setPropertyValue( 'instance', $class, $instance );
}

/**
* Set the value of a private/protected property.
*
* @param string $property Property name for which to gain access.
* @param string|object $class Class name for a static property, or instance for an instance property.
* @param mixed $value The value to set to the property.
*
* @return mixed The previous value of the property.
* @throws ReflectionException Throws an exception if property does not exist.
*
*/
protected function setPropertyValue( $property, $class, $value ) {
$ref = $this->get_reflective_property( $property, $class );

if ( is_object( $class ) ) {
$previous = $ref->getValue( $class );
// Instance property.
$ref->setValue( $class, $value );
} else {
$previous = $ref->getValue();
// Static property.
$ref->setValue( $value );
}

return $previous;
}

/**
* Reset the value of a private/protected property.
*
* @param string $property Property name for which to gain access.
* @param string|object $class Class name for a static property, or instance for an instance property.
*
* @return mixed The previous value of the property.
* @throws ReflectionException Throws an exception if property does not exist.
*
*/
protected function resetPropertyValue( $property, $class ) {
return $this->setPropertyValue( $property, $class, null );
}
}
Loading
Loading