File: 0008-fix-error-with-phpunit10-assertObjectHasAttribute-de.patch

package info (click to toggle)
php-codeigniter-framework 3.1.13%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,228 kB
  • sloc: php: 37,178; xml: 205; makefile: 138; python: 66; sh: 65
file content (202 lines) | stat: -rw-r--r-- 8,638 bytes parent folder | download | duplicates (2)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
From 31f32b45fc8aca8960fc7f5c90f9f2d034b6f8ae Mon Sep 17 00:00:00 2001
From: tenzap <fabstz-it@yahoo.fr>
Date: Wed, 21 Jun 2023 07:18:40 +0200
Subject: [PATCH 8/8] fix error with phpunit10 (assertObjectHasAttribute
 deprecated)

---
 tests/codeigniter/core/Loader_test.php      | 36 +++++++++++++--------
 tests/codeigniter/libraries/Driver_test.php | 17 +++++++---
 2 files changed, 35 insertions(+), 18 deletions(-)

--- a/tests/codeigniter/core/Loader_test.php
+++ b/tests/codeigniter/core/Loader_test.php
@@ -4,6 +4,8 @@
 
 	private $ci_obj;
 
+	private $realAssertObjectHasProperty;
+
 	public function set_up()
 	{
 		// Instantiate a new loader
@@ -16,6 +18,12 @@
 		// Set subclass prefix
 		$this->prefix = 'MY_';
 		$this->ci_set_config('subclass_prefix', $this->prefix);
+
+		// assertObjectHasAttribute() is deprecated and will be removed in PHPUnit 10.
+		// It was replaced by assertObjectHasProperty() in phpunit 10.1.0+
+		$this->realAssertObjectHasProperty = method_exists($this, 'assertObjectHasProperty')
+			? 'assertObjectHasProperty'
+			: 'assertObjectHasAttribute';
 	}
 
 	// --------------------------------------------------------------------
@@ -36,7 +44,7 @@
 		// Test loading as an array.
 		$this->assertInstanceOf('CI_Loader', $this->load->library(array($lib)));
 		$this->assertTrue(class_exists($class), $class.' does not exist');
-		$this->assertObjectHasAttribute($lib, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($lib, $this->ci_obj));
 		$this->assertInstanceOf($class, $this->ci_obj->$lib);
 
 		// Create library in VFS
@@ -88,21 +96,21 @@
 		$this->assertInstanceOf('CI_Loader', $this->load->library($lib));
 		$this->assertTrue(class_exists($class), $class.' does not exist');
 		$this->assertTrue(class_exists($ext), $ext.' does not exist');
-		$this->assertObjectHasAttribute($name, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($name, $this->ci_obj));
 		$this->assertInstanceOf($class, $this->ci_obj->$name);
 		$this->assertInstanceOf($ext, $this->ci_obj->$name);
 
 		// Test reloading with object name
 		$obj = 'exttest';
 		$this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj));
-		$this->assertObjectHasAttribute($obj, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($obj, $this->ci_obj));
 		$this->assertInstanceOf($class, $this->ci_obj->$obj);
 		$this->assertInstanceOf($ext, $this->ci_obj->$obj);
 
 		// Test reloading
 		unset($this->ci_obj->$name);
 		$this->assertInstanceOf('CI_Loader', $this->load->library($lib));
-		$this->assertObjectHasAttribute($name, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($name, $this->ci_obj));
 
 		// Create baseless library
 		$name = 'ext_baseless_lib';
@@ -140,7 +148,7 @@
 		$obj = 'testy';
 		$this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj));
 		$this->assertTrue(class_exists($class), $class.' does not exist');
-		$this->assertObjectHasAttribute($obj, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($obj, $this->ci_obj));
 		$this->assertInstanceOf($class, $this->ci_obj->$obj);
 		$this->assertEquals($cfg, $this->ci_obj->$obj->config);
 
@@ -172,7 +180,7 @@
 
 		// Was the model class instantiated.
 		$this->assertTrue(class_exists($class), $class.' does not exist');
-		$this->assertObjectHasAttribute($lib, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($lib, $this->ci_obj));
 		$this->assertInstanceOf($class, $this->ci_obj->$lib);
 	}
 
@@ -193,13 +201,13 @@
 		// Test loading as an array.
 		$this->assertInstanceOf('CI_Loader', $this->load->driver(array($driver)));
 		$this->assertTrue(class_exists($class), $class.' does not exist');
-		$this->assertObjectHasAttribute($driver, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($driver, $this->ci_obj));
 		$this->assertInstanceOf($class, $this->ci_obj->$driver);
 
 		// Test loading as a library with a name
 		$obj = 'testdrive';
 		$this->assertInstanceOf('CI_Loader', $this->load->library($driver, NULL, $obj));
-		$this->assertObjectHasAttribute($obj, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($obj, $this->ci_obj));
 		$this->assertInstanceOf($class, $this->ci_obj->$obj);
 
 		// Test a string given to params
@@ -222,7 +230,7 @@
 
 		// Was the model class instantiated.
 		$this->assertTrue(class_exists($model));
-		$this->assertObjectHasAttribute($model, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($model, $this->ci_obj));
 
 		// Test no model given
 		$this->assertInstanceOf('CI_Loader', $this->load->model(''));
@@ -248,8 +256,8 @@
 
 		// Was the model class instantiated?
 		$this->assertTrue(class_exists($model));
-		$this->assertObjectHasAttribute($name, $this->ci_obj);
-		$this->assertObjectHasAttribute($name, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($name, $this->ci_obj));
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($name, $this->ci_obj));
 		$this->assertInstanceOf($base, $this->ci_obj->$name);
 		$this->assertInstanceOf($model, $this->ci_obj->$name);
 
@@ -575,17 +583,17 @@
 
 		// Verify library
 		$this->assertTrue(class_exists($lib_class), $lib_class.' does not exist');
-		$this->assertObjectHasAttribute($lib, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($lib, $this->ci_obj));
 		$this->assertInstanceOf($lib_class, $this->ci_obj->$lib);
 
 		// Verify driver
 		$this->assertTrue(class_exists($drv_class), $drv_class.' does not exist');
-		$this->assertObjectHasAttribute($drv, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($drv, $this->ci_obj));
 		$this->assertInstanceOf($drv_class, $this->ci_obj->$drv);
 
 		// Verify model
 		$this->assertTrue(class_exists($model), $model.' does not exist');
-		$this->assertObjectHasAttribute($model, $this->ci_obj);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($model, $this->ci_obj));
 		$this->assertInstanceOf($model, $this->ci_obj->$model);
 
 		// Verify config calls
--- a/tests/codeigniter/libraries/Driver_test.php
+++ b/tests/codeigniter/libraries/Driver_test.php
@@ -7,6 +7,8 @@
 
 	private $name;
 
+	private $realAssertObjectHasProperty;
+
 	/**
 	 * Set up test framework
 	 */
@@ -25,6 +27,12 @@
 		// Create mock driver library
 		$this->name = 'Driver';
 		$this->lib = new Mock_Libraries_Driver();
+
+		// assertObjectHasAttribute() is deprecated and will be removed in PHPUnit 10.
+		// It was replaced by assertObjectHasProperty() in phpunit 10.1.0+
+		$this->realAssertObjectHasProperty = method_exists($this, 'assertObjectHasProperty')
+			? 'assertObjectHasProperty'
+			: 'assertObjectHasAttribute';
 	}
 
 	/**
@@ -51,12 +59,12 @@
 		$this->assertEquals($this->name, $this->lib->get_name());
 
 		// Was driver loaded?
-		$this->assertObjectHasAttribute($driver, $this->lib);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($driver, $this->lib));
 		$this->assertInstanceOf($class, $this->lib->$driver);
 		$this->assertInstanceOf('CI_Driver', $this->lib->$driver);
 
 		// Was decorate called?
-		$this->assertObjectHasAttribute($prop, $this->lib->$driver);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($prop, $this->lib->$driver));
 		$this->assertTrue($this->lib->$driver->$prop);
 
 		// Do we get an error for an invalid driver?
@@ -86,7 +94,8 @@
 		$this->assertNotNull($this->lib->load_driver($driver));
 
 		// Was driver loaded?
-		$this->assertObjectHasAttribute($driver, $this->lib);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($driver, $this->lib));
+
 		$this->assertInstanceOf($class, $this->lib->$driver);
 		$this->assertInstanceOf('CI_Driver', $this->lib->$driver);
 
@@ -120,7 +129,7 @@
 		$this->assertNotNull($this->lib->load_driver($driver));
 
 		// Was driver loaded?
-		$this->assertObjectHasAttribute($driver, $this->lib);
+		call_user_func_array(array($this, $this->realAssertObjectHasProperty), array($driver, $this->lib));
 		$this->assertInstanceOf($class, $this->lib->$driver);
 		$this->assertInstanceOf($baseclass, $this->lib->$driver);
 		$this->assertInstanceOf('CI_Driver', $this->lib->$driver);