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

Try: Make code coverage work #1016

Open
wants to merge 11 commits into
base: trunk
Choose a base branch
from
48 changes: 48 additions & 0 deletions .github/workflows/pr-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Run Codecov on PR
on:
pull_request
jobs:
run:
runs-on: ubuntu-latest
timeout-minutes: 15
services:
database:
image: mysql:5.6
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up PHP 8.1
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
tools: composer
extensions: mysql
coverage: xdebug

- name: Get cached composer directories
uses: actions/cache@v2
with:
path: ./vendor
key: ${{ runner.os }}-${{ hashFiles('./composer.lock') }}

- name: Install dependencies
run: composer self-update && composer require --dev --no-update phpunit/phpunit:^9.5 && composer update && composer install && composer dump-autoload

- name: Init database and WordPress
run: ./tests/bin/install.sh woo_test root root 127.0.0.1 latest

- name: Run tests and collect coverage
run: XDEBUG_MODE=coverage ./vendor/bin/phpunit -c ./tests/phpunit.xml.dist --coverage-clover coverage.xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4-beta
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
6 changes: 1 addition & 5 deletions .github/workflows/pr-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -85,7 +85,3 @@ jobs:
run: |
./vendor/bin/phpunit --version
WP_MULTISITE=${{ matrix.multisite }} ./vendor/bin/phpunit -c ./tests/phpunit.xml.dist

- name: Code Coverage
run: |
bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
codecov:
branch: master
branch: trunk

coverage:
ignore:
Expand Down
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"platform": {
"php": "5.6"
}
},
"archive": {
Expand Down
4 changes: 3 additions & 1 deletion tests/ActionScheduler_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ class ActionScheduler_UnitTestCase extends WP_UnitTestCase {

/**
* Perform test set-up work.
* @before
*/
public function set_up() {
ActionScheduler_Callbacks::add_callbacks();
parent::set_up();
ActionScheduler_Callbacks::add_callbacks();
}

/**
* Perform test tear-down work.
* @after
*/
public function tear_down() {
ActionScheduler_Callbacks::remove_callbacks();
Expand Down
4 changes: 3 additions & 1 deletion tests/phpunit/deprecated/ActionScheduler_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ class ActionScheduler_UnitTestCase extends WP_UnitTestCase {

/**
* Perform test set-up work.
* @before
*/
public function set_up() {
ActionScheduler_Callbacks::add_callbacks();
parent::set_up();
ActionScheduler_Callbacks::add_callbacks();
}

/**
* Perform test tear-down work.
* @after
*/
public function tear_down() {
ActionScheduler_Callbacks::remove_callbacks();
Expand Down
9 changes: 5 additions & 4 deletions tests/phpunit/jobstore/ActionScheduler_DBStore_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
* @group tables
*/
class ActionScheduler_DBStore_Test extends AbstractStoreTest {
/**
* @before
*/
public function set_up() {
parent::set_up();

public function setUp() {
global $wpdb;

// Delete all actions before each test.
$wpdb->query( "DELETE FROM {$wpdb->actionscheduler_actions}" );

parent::setUp();
}

/**
Expand Down
16 changes: 11 additions & 5 deletions tests/phpunit/jobstore/ActionScheduler_HybridStore_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
class ActionScheduler_HybridStore_Test extends ActionScheduler_UnitTestCase {
private $demarkation_id = 1000;

public function setUp() {
parent::setUp();
/**
* @before
*/
public function set_up() {
parent::set_up();
if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
$store = new PostStore();
Expand All @@ -26,15 +29,18 @@ public function setUp() {
$hybrid->set_autoincrement( '', ActionScheduler_StoreSchema::ACTIONS_TABLE );
}

public function tearDown() {
parent::tearDown();

/*
* @after
*/
public function tear_down() {
// reset the autoincrement index
/** @var \wpdb $wpdb */
global $wpdb;
$wpdb->query( "TRUNCATE TABLE {$wpdb->actionscheduler_actions}" );
$wpdb->query( "TRUNCATE TABLE {$wpdb->actionscheduler_logs}" );
delete_option( ActionScheduler_HybridStore::DEMARKATION_OPTION );

parent::tear_down();
}

public function test_actions_are_migrated_on_find() {
Expand Down
7 changes: 5 additions & 2 deletions tests/phpunit/migration/ActionMigrator_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
* @group migration
*/
class ActionMigrator_Test extends ActionScheduler_UnitTestCase {
public function setUp() {
parent::setUp();
/**
* @before
*/
public function set_up() {
parent::set_up();
if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
$store = new ActionScheduler_wpPostStore();
Expand Down
7 changes: 5 additions & 2 deletions tests/phpunit/migration/BatchFetcher_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
* @group migration
*/
class BatchFetcher_Test extends ActionScheduler_UnitTestCase {
public function setUp() {
parent::setUp();
/**
* @before
*/
public function set_up() {
parent::set_up();
if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
$store = new PostStore();
Expand Down
7 changes: 5 additions & 2 deletions tests/phpunit/migration/LogMigrator_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
* @group migration
*/
class LogMigrator_Test extends ActionScheduler_UnitTestCase {
function setUp() {
parent::setUp();
/**
* @before
*/
function set_up() {
parent::set_up();
if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
$store = new ActionScheduler_wpPostStore();
Expand Down
7 changes: 5 additions & 2 deletions tests/phpunit/migration/Runner_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
* @group migration
*/
class Runner_Test extends ActionScheduler_UnitTestCase {
public function setUp() {
parent::setUp();
/**
* @before
*/
public function set_up() {
parent::set_up();
if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
$store = new PostStore();
Expand Down
7 changes: 5 additions & 2 deletions tests/phpunit/migration/Scheduler_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
* @group migration
*/
class Scheduler_Test extends ActionScheduler_UnitTestCase {
public function setUp() {
parent::setUp();
/**
* @before
*/
public function set_up() {
parent::set_up();
if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
$store = new PostStore();
Expand Down
18 changes: 13 additions & 5 deletions tests/phpunit/procedural_api/procedural_api_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,19 @@ public function test_as_recover_from_incorrect_schema() {

// ensure that all four errors were logged to error_log.
$logged_errors = stream_get_contents( $error_capture );
$this->assertContains( 'Caught exception while enqueuing action "hook_17": Error saving action', $logged_errors );
$this->assertContains( 'Caught exception while enqueuing action "hook_18": Error saving action', $logged_errors );
$this->assertContains( 'Caught exception while enqueuing action "hook_19": Error saving action', $logged_errors );
$this->assertContains( 'Caught exception while enqueuing action "hook_20": Error saving action', $logged_errors );
$this->assertContains( "Unknown column 'priority' in 'field list'", $logged_errors );
if ( method_exists( $this, 'assertStringContainsString' ) ) {
$this->assertStringContainsString( 'Caught exception while enqueuing action "hook_17": Error saving action', $logged_errors );
$this->assertStringContainsString( 'Caught exception while enqueuing action "hook_18": Error saving action', $logged_errors );
$this->assertStringContainsString( 'Caught exception while enqueuing action "hook_19": Error saving action', $logged_errors );
$this->assertStringContainsString( 'Caught exception while enqueuing action "hook_20": Error saving action', $logged_errors );
$this->assertStringContainsString( "Unknown column 'priority' in 'field list'", $logged_errors );
} else {
$this->assertContains( 'Caught exception while enqueuing action "hook_17": Error saving action', $logged_errors );
$this->assertContains( 'Caught exception while enqueuing action "hook_18": Error saving action', $logged_errors );
$this->assertContains( 'Caught exception while enqueuing action "hook_19": Error saving action', $logged_errors );
$this->assertContains( 'Caught exception while enqueuing action "hook_20": Error saving action', $logged_errors );
$this->assertContains( "Unknown column 'priority' in 'field list'", $logged_errors );
}

// recreate the priority column.
$wpdb->query( "ALTER TABLE {$wpdb->actionscheduler_actions} ADD COLUMN priority tinyint(10) UNSIGNED NOT NULL DEFAULT 10" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ class as_get_scheduled_actions_Test extends ActionScheduler_UnitTestCase {
private $args = array();
private $groups = array();

public function setUp() {
parent::setUp();
/**
* @before
*/
public function set_up() {
parent::set_up();

$store = ActionScheduler::store();

Expand Down
Loading