-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathTinyTestCase.php
More file actions
103 lines (83 loc) · 2.73 KB
/
TinyTestCase.php
File metadata and controls
103 lines (83 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
require_once dirname( __FILE__ ) . '/../helpers/mock-http-stream-wrapper.php';
require_once dirname( __FILE__ ) . '/../helpers/mock-tinify-client.php';
require_once dirname( __FILE__ ) . '/../helpers/wordpress.php';
require_once dirname( __FILE__ ) . '/../helpers/wordpress-cli.php';
require_once dirname( __FILE__ ) . '/../../src/config/class-tiny-config.php';
require_once dirname( __FILE__ ) . '/../../src/compatibility/wpml/class-tiny-wpml.php';
require_once dirname( __FILE__ ) . '/../../src/compatibility/as3cf/class-tiny-as3cf.php';
require_once dirname( __FILE__ ) . '/../../src/compatibility/woocommerce/class-tiny-woocommerce.php';
require_once 'vendor/autoload.php';
use org\bovigo\vfs\vfsStream;
use \PHPUnit\Framework\TestCase;
function plugin_autoloader( $class ) {
$file = dirname( __FILE__ ) . '/../../src/class-' .
str_replace( '_', '-', strtolower( $class ) ) . '.php';
if ( file_exists( $file ) ) {
include $file;
} else {
spl_autoload( $class );
}
}
spl_autoload_register( 'plugin_autoloader' );
class Tiny_PHP {
public static $fopen_available = true;
public static $client_supported = true;
public static function fopen_available() {
return self::$fopen_available;
}
public static function client_supported() {
return self::$client_supported;
}
}
abstract class Tiny_TestCase extends TestCase {
/**
* WordPress stubs
*
* @var \WordPressStubs
*/
protected $wp;
protected $vfs;
// @codingStandardsIgnoreStart
public static function setUpBeforeClass(): void {
static::set_up_before_class();
}
public static function tearDownAfterClass(): void {
static::tear_down_after_class();
}
protected function setUp(): void {
$this->set_up();
}
protected function tearDown(): void {
$this->tear_down();
}
protected function assertBetween($lower_bound, $upper_bound, $actual, $message = '') {
$this->assertGreaterThanOrEqual( $lower_bound, $actual, $message );
$this->assertLessThanOrEqual( $upper_bound, $actual, $message );
}
protected function assertEqualWithinDelta($expected, $actual, $delta, $message = '') {
$this->assertGreaterThanOrEqual( $expected - $delta, $actual, $message );
$this->assertLessThanOrEqual( $expected + $delta, $actual, $message );
}
// @codingStandardsIgnoreEnd
protected function json( $file_name ) {
return json_decode(
file_get_contents(
dirname( __FILE__ ) . '/../fixtures/json/' . $file_name . '.json'
),
true
);
}
public static function set_up_before_class() {
}
public static function tear_down_after_class() {
Tiny_PHP::$client_supported = true;
Tiny_PHP::$fopen_available = true;
}
protected function set_up() {
$this->vfs = vfsStream::setup();
$this->wp = new WordPressStubs( $this->vfs );
}
protected function tear_down() {
}
}