Skip to content

Commit a6522c2

Browse files
update phpunit config to convert deprecations to errors; remove brain/monkey dependency
1 parent 2f65de1 commit a6522c2

9 files changed

+53
-56
lines changed

composer.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@
2121
"php": ">=7.4"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^9.0",
25-
"brain/monkey": "^2.2",
24+
"phpunit/phpunit": "^9.6",
2625
"squizlabs/php_codesniffer": "^3.11"
2726
},
2827
"scripts": {
2928
"make-pot": "wp i18n make-pot . languages/mailchimp-for-wp.pot --exclude=assets/js",
3029
"test": "phpunit tests/",
3130
"codestyle": "phpcs -n -s",
3231
"check-syntax": "./bin/check-php-syntax"
33-
},
34-
"config": {
35-
},
36-
"minimum-stability": "dev"
32+
}
3733
}

mailchimp-for-wp.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
// Prevent direct file access
3333
defined('ABSPATH') or exit;
3434

35-
// don't run if PHP version is lower than 7.4.0
36-
if (PHP_VERSION_ID < 70400) {
37-
return;
38-
}
3935

4036
/** @ignore */
4137
function _mc4wp_load_plugin()
@@ -47,6 +43,11 @@ function _mc4wp_load_plugin()
4743
return;
4844
}
4945

46+
// don't run if PHP version is lower than 7.4.0
47+
if (PHP_VERSION_ID < 70400) {
48+
return;
49+
}
50+
5051
// bootstrap the core plugin
5152
define('MC4WP_VERSION', '4.9.21');
5253
define('MC4WP_PLUGIN_DIR', __DIR__);

phpunit.xml.dist

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
3-
<coverage processUncoveredFiles="true">
4-
<include>
5-
<directory suffix=".php">./src</directory>
6-
</include>
7-
</coverage>
8-
<testsuites>
9-
<testsuite name="mailchimp-for-wordpress">
10-
<directory suffix="Test.php">./tests/</directory>
11-
</testsuite>
12-
</testsuites>
13-
<php>
14-
<ini name="display_errors" value="true"/>
15-
</php>
2+
3+
<!-- https://docs.phpunit.de/en/9.6/ -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
6+
colors="true"
7+
bootstrap="tests/bootstrap.php"
8+
convertDeprecationsToExceptions="true"
9+
>
10+
<php>
11+
<ini name="display_errors" value="1" />
12+
<ini name="error_reporting" value="-1" />
13+
<server name="SHELL_VERBOSITY" value="-1" />
14+
</php>
15+
16+
<testsuites>
17+
<testsuite name="tests">
18+
<directory>tests</directory>
19+
</testsuite>
20+
</testsuites>
1621
</phpunit>

tests/DebugLogReaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class DebugLogReaderTest extends TestCase
1313
/**
1414
* @var string
1515
*/
16-
protected $sample_log_lines = array(
16+
protected array $sample_log_lines = array(
1717
'eCommerce360 > Successfully added order 101',
1818
'eCommerce360 > Order 101 deleted',
1919
);

tests/IntegrationManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function test_get()
6262

6363

6464
$instance->register_integration('slug', 'MC4WP_Sample_Integration', true);
65-
self::expectException(null);
65+
self::expectException('');
6666
self::assertInstanceOf('MC4WP_Sample_Integration', $instance->get('slug'));
6767
}
6868
}

tests/IntegrationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function test_constructor()
3030
public function test_checkbox_was_checked()
3131
{
3232
$slug = 'my-integration';
33+
34+
/** @var MC4WP_Integration $instance */
3335
$instance = $this->getMockForAbstractClass('MC4WP_Integration', array(
3436
$slug,
3537
array()

tests/QueueTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
<?php
22

33
use PHPUnit\Framework\TestCase;
4-
use Brain\Monkey;
5-
use Brain\Monkey\Functions;
64

75
class QueueTest extends TestCase
86
{
9-
protected function setUp() : void
10-
{
11-
parent::setUp();
12-
13-
Monkey\setUp();
14-
}
15-
16-
protected function tearDown() : void
17-
{
18-
Monkey\tearDown();
19-
parent::tearDown();
20-
}
217

228
/**
239
* @covers MC4WP_Queue::all
@@ -100,7 +86,6 @@ public function test_save()
10086

10187
// add something, then save
10288
$queue->put(array( 'key' => 'value' ));
103-
Functions\when('update_option')->justReturn(true);
10489
self::assertTrue($queue->save());
10590
}
10691
}

tests/bootstrap.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

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

5-
require __DIR__ . '/../autoload.php';
6-
require __DIR__ . '/../vendor/antecedent/patchwork/Patchwork.php';
75
require __DIR__ . '/mock.php';
8-
require __DIR__ . '/../vendor/autoload.php';
6+
7+
require dirname(__DIR__) . '/autoload.php';

tests/mock.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<?php
22

3-
if (! defined('ABSPATH')) {
4-
define('ABSPATH', '/');
5-
}
6-
3+
define('ABSPATH', '/');
74
define('HOUR_IN_SECONDS', 3600);
8-
define('MC4WP_PLUGIN_DIR', __DIR__ . '/..');
5+
define('MC4WP_PLUGIN_DIR', dirname(__DIR__));
96

10-
class WP_Post {}
7+
class WP_Post
8+
{
9+
public $ID;
10+
public $post_type;
11+
public $post_title;
12+
public $post_content;
13+
public $post_status;
14+
}
1115

1216

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

3438
/** @ignore */
35-
function absint($v) { return $v; }
39+
function absint($v)
40+
{
41+
return $v;
42+
}
3643

3744
/** @ignore */
3845
function update_option($a, $b, $c)
3946
{
47+
return true;
4048
}
4149

4250
/** @ignore */
43-
function apply_filters($hook, $value, $parameter_1 = null)
51+
function apply_filters($hook, $value, $a = null, $b = null, $c = null)
4452
{
4553
return $value;
4654
}
@@ -88,8 +96,9 @@ function __($string, $text_domain = '')
8896
return $string;
8997
}
9098

91-
function esc_html__($string, $text_domain) {
92-
return $string;
99+
function esc_html__($string, $text_domain)
100+
{
101+
return $string;
93102
}
94103

95104
/** @ignore */
@@ -108,7 +117,7 @@ function get_post($id)
108117
/** @ignore */
109118
function mock_post(array $props) : WP_Post
110119
{
111-
$post = new WP_Post;
120+
$post = new WP_Post();
112121
$props = array_merge(
113122
array(
114123
'ID' => 1,
@@ -119,7 +128,7 @@ function mock_post(array $props) : WP_Post
119128
),
120129
$props
121130
);
122-
foreach($props as $key => $value) {
131+
foreach ($props as $key => $value) {
123132
$post->$key = $value;
124133
}
125134

0 commit comments

Comments
 (0)