Skip to content

Commit

Permalink
update phpunit config to convert deprecations to errors; remove brain…
Browse files Browse the repository at this point in the history
…/monkey dependency
  • Loading branch information
dannyvankooten committed Jan 14, 2025
1 parent 2f65de1 commit a6522c2
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 56 deletions.
8 changes: 2 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@
"php": ">=7.4"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"brain/monkey": "^2.2",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.11"
},
"scripts": {
"make-pot": "wp i18n make-pot . languages/mailchimp-for-wp.pot --exclude=assets/js",
"test": "phpunit tests/",
"codestyle": "phpcs -n -s",
"check-syntax": "./bin/check-php-syntax"
},
"config": {
},
"minimum-stability": "dev"
}
}
9 changes: 5 additions & 4 deletions mailchimp-for-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
// Prevent direct file access
defined('ABSPATH') or exit;

// don't run if PHP version is lower than 7.4.0
if (PHP_VERSION_ID < 70400) {
return;
}

/** @ignore */
function _mc4wp_load_plugin()
Expand All @@ -47,6 +43,11 @@ function _mc4wp_load_plugin()
return;
}

// don't run if PHP version is lower than 7.4.0
if (PHP_VERSION_ID < 70400) {
return;
}

// bootstrap the core plugin
define('MC4WP_VERSION', '4.9.21');
define('MC4WP_PLUGIN_DIR', __DIR__);
Expand Down
33 changes: 19 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" colors="true" failOnWarning="true" stopOnError="false" stopOnFailure="false" verbose="true" bootstrap="./tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="mailchimp-for-wordpress">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<ini name="display_errors" value="true"/>
</php>

<!-- https://docs.phpunit.de/en/9.6/ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
bootstrap="tests/bootstrap.php"
convertDeprecationsToExceptions="true"
>
<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<server name="SHELL_VERBOSITY" value="-1" />
</php>

<testsuites>
<testsuite name="tests">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion tests/DebugLogReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DebugLogReaderTest extends TestCase
/**
* @var string
*/
protected $sample_log_lines = array(
protected array $sample_log_lines = array(
'eCommerce360 > Successfully added order 101',
'eCommerce360 > Order 101 deleted',
);
Expand Down
2 changes: 1 addition & 1 deletion tests/IntegrationManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function test_get()


$instance->register_integration('slug', 'MC4WP_Sample_Integration', true);
self::expectException(null);
self::expectException('');
self::assertInstanceOf('MC4WP_Sample_Integration', $instance->get('slug'));
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function test_constructor()
public function test_checkbox_was_checked()
{
$slug = 'my-integration';

/** @var MC4WP_Integration $instance */
$instance = $this->getMockForAbstractClass('MC4WP_Integration', array(
$slug,
array()
Expand Down
15 changes: 0 additions & 15 deletions tests/QueueTest.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
<?php

use PHPUnit\Framework\TestCase;
use Brain\Monkey;
use Brain\Monkey\Functions;

class QueueTest extends TestCase
{
protected function setUp() : void
{
parent::setUp();

Monkey\setUp();
}

protected function tearDown() : void
{
Monkey\tearDown();
parent::tearDown();
}

/**
* @covers MC4WP_Queue::all
Expand Down Expand Up @@ -100,7 +86,6 @@ public function test_save()

// add something, then save
$queue->put(array( 'key' => 'value' ));
Functions\when('update_option')->justReturn(true);
self::assertTrue($queue->save());
}
}
5 changes: 2 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

echo 'Welcome to the Mailchimp for WordPress Test Suite' . PHP_EOL;

require __DIR__ . '/../autoload.php';
require __DIR__ . '/../vendor/antecedent/patchwork/Patchwork.php';
require __DIR__ . '/mock.php';
require __DIR__ . '/../vendor/autoload.php';

require dirname(__DIR__) . '/autoload.php';
33 changes: 21 additions & 12 deletions tests/mock.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?php

if (! defined('ABSPATH')) {
define('ABSPATH', '/');
}

define('ABSPATH', '/');
define('HOUR_IN_SECONDS', 3600);
define('MC4WP_PLUGIN_DIR', __DIR__ . '/..');
define('MC4WP_PLUGIN_DIR', dirname(__DIR__));

class WP_Post {}
class WP_Post
{
public $ID;
public $post_type;
public $post_title;
public $post_content;
public $post_status;
}


/** @ignore */
Expand All @@ -32,15 +36,19 @@ function get_option($option, $default = null)
}

/** @ignore */
function absint($v) { return $v; }
function absint($v)
{
return $v;
}

/** @ignore */
function update_option($a, $b, $c)
{
return true;
}

/** @ignore */
function apply_filters($hook, $value, $parameter_1 = null)
function apply_filters($hook, $value, $a = null, $b = null, $c = null)
{
return $value;
}
Expand Down Expand Up @@ -88,8 +96,9 @@ function __($string, $text_domain = '')
return $string;
}

function esc_html__($string, $text_domain) {
return $string;
function esc_html__($string, $text_domain)
{
return $string;
}

/** @ignore */
Expand All @@ -108,7 +117,7 @@ function get_post($id)
/** @ignore */
function mock_post(array $props) : WP_Post
{
$post = new WP_Post;
$post = new WP_Post();
$props = array_merge(
array(
'ID' => 1,
Expand All @@ -119,7 +128,7 @@ function mock_post(array $props) : WP_Post
),
$props
);
foreach($props as $key => $value) {
foreach ($props as $key => $value) {
$post->$key = $value;
}

Expand Down

0 comments on commit a6522c2

Please sign in to comment.