Completed
Push — master ( 75905b...69c9ad )
by Damian
14:56 queued 02:22
created

ObjectTest::testExtend()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 21

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 27
rs 8.8571
cc 1
eloc 21
nc 1
nop 0
1
<?php
2
/**
3
 * @package framework
4
 * @subpackage tests
5
 *
6
 * @todo tests for addStaticVars()
7
 * @todo tests for setting statics which are not defined on the object as built-in PHP statics
8
 * @todo tests for setting statics through extensions (#2387)
9
 */
10
class ObjectTest extends SapphireTest {
11
12
	public function setUp() {
13
		parent::setUp();
14
		Injector::inst()->unregisterAllObjects();
15
	}
16
17
	public function testHasmethodBehaviour() {
18
		$obj = new ObjectTest_ExtendTest();
19
20
		$this->assertTrue($obj->hasMethod('extendableMethod'), "Extension method found in original spelling");
21
		$this->assertTrue($obj->hasMethod('ExTendableMethod'), "Extension method found case-insensitive");
22
23
		$objs = array();
24
		$objs[] = new ObjectTest_T2();
25
		$objs[] = new ObjectTest_T2();
26
		$objs[] = new ObjectTest_T2();
27
28
		// All these methods should exist and return true
29
		$trueMethods = array('testMethod','otherMethod','someMethod','t1cMethod','normalMethod');
30
31
		foreach($objs as $i => $obj) {
32
			foreach($trueMethods as $method) {
33
				$methodU = strtoupper($method);
34
				$methodL = strtoupper($method);
35
				$this->assertTrue($obj->hasMethod($method), "Test that obj#$i has method $method ($obj->class)");
36
				$this->assertTrue($obj->hasMethod($methodU), "Test that obj#$i has method $methodU");
37
				$this->assertTrue($obj->hasMethod($methodL), "Test that obj#$i has method $methodL");
38
39
				$this->assertTrue($obj->$method(), "Test that obj#$i can call method $method");
40
				$this->assertTrue($obj->$methodU(), "Test that obj#$i can call method $methodU");
41
				$this->assertTrue($obj->$methodL(), "Test that obj#$i can call method $methodL");
42
			}
43
44
			$this->assertTrue($obj->hasMethod('Wrapping'), "Test that obj#$i has method Wrapping");
45
			$this->assertTrue($obj->hasMethod('WRAPPING'), "Test that obj#$i has method WRAPPING");
46
			$this->assertTrue($obj->hasMethod('wrapping'), "Test that obj#$i has method wrapping");
47
48
			$this->assertEquals("Wrapping", $obj->Wrapping(), "Test that obj#$i can call method Wrapping");
49
			$this->assertEquals("Wrapping", $obj->WRAPPING(), "Test that obj#$i can call method WRAPPIGN");
50
			$this->assertEquals("Wrapping", $obj->wrapping(), "Test that obj#$i can call method wrapping");
51
		}
52
53
	}
54
55
	public function testSingletonCreation() {
56
		$myObject = singleton('ObjectTest_MyObject');
57
		$this->assertEquals($myObject->class, 'ObjectTest_MyObject',
58
			'singletons are creating a correct class instance');
59
		$this->assertEquals(get_class($myObject), 'ObjectTest_MyObject',
60
			'singletons are creating a correct class instance');
61
62
		$mySubObject = singleton('ObjectTest_MySubObject');
63
		$this->assertEquals($mySubObject->class, 'ObjectTest_MySubObject',
64
			'singletons are creating a correct subclass instance');
65
		$this->assertEquals(get_class($mySubObject), 'ObjectTest_MySubObject',
66
			'singletons are creating a correct subclass instance');
67
68
		$myFirstObject = singleton('ObjectTest_MyObject');
69
		$mySecondObject = singleton('ObjectTest_MyObject');
70
		$this->assertTrue($myFirstObject === $mySecondObject,
71
			'singletons are using the same object on subsequent calls');
72
	}
73
74
	public function testStaticGetterMethod() {
75
		$obj = singleton('ObjectTest_MyObject');
76
		$this->assertEquals(
77
			'MyObject',
78
			$obj->stat('mystaticProperty'),
79
			'Uninherited statics through stat() on a singleton behave the same as built-in PHP statics'
80
		);
81
	}
82
83
	public function testStaticInheritanceGetters() {
84
		$obj = singleton('ObjectTest_MyObject');
85
		$subObj = singleton('ObjectTest_MyObject');
86
		$this->assertEquals(
87
			$subObj->stat('mystaticProperty'),
88
			'MyObject',
89
			'Statics defined on a parent class are available through stat() on a subclass'
90
		);
91
	}
92
93
	public function testStaticSettingOnSingletons() {
94
		$singleton1 = singleton('ObjectTest_MyObject');
95
		$singleton2 = singleton('ObjectTest_MyObject');
96
		$singleton1->set_stat('mystaticProperty', 'changed');
97
		$this->assertEquals(
98
			$singleton2->stat('mystaticProperty'),
99
			'changed',
100
			'Statics setting is populated throughout singletons without explicitly clearing cache'
101
		);
102
	}
103
104
	public function testStaticSettingOnInstances() {
105
		$instance1 = new ObjectTest_MyObject();
106
		$instance2 = new ObjectTest_MyObject();
107
		$instance1->set_stat('mystaticProperty', 'changed');
108
		$this->assertEquals(
109
			$instance2->stat('mystaticProperty'),
110
			'changed',
111
			'Statics setting through set_stat() is populated throughout instances without explicitly clearing cache'
112
		);
113
	}
114
115
	/**
116
	 * Tests that {@link Object::create()} correctly passes all arguments to the new object
117
	 */
118
	public function testCreateWithArgs() {
119
		$createdObj = ObjectTest_CreateTest::create('arg1', 'arg2', array(), null, 'arg5');
120
		$this->assertEquals($createdObj->constructArguments, array('arg1', 'arg2', array(), null, 'arg5'));
121
122
		$strongObj = Object::strong_create('ObjectTest_CreateTest', 'arg1', 'arg2', array(), null, 'arg5');
123
		$this->assertEquals($strongObj->constructArguments, array('arg1', 'arg2', array(), null, 'arg5'));
0 ignored issues
show
Bug introduced by
The property constructArguments does not seem to exist in Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
124
	}
125
126
	public function testCreateLateStaticBinding() {
127
		$createdObj = ObjectTest_CreateTest::create('arg1', 'arg2', array(), null, 'arg5');
128
		$this->assertEquals($createdObj->constructArguments, array('arg1', 'arg2', array(), null, 'arg5'));
129
	}
130
131
	/**
132
	 * Tests that {@link Object::useCustomClass()} correnctly replaces normal and strong objects
133
	 */
134
	public function testUseCustomClass() {
135
		$obj1 = ObjectTest_CreateTest::create();
136
		$this->assertTrue($obj1 instanceof ObjectTest_CreateTest);
137
138
		Object::useCustomClass('ObjectTest_CreateTest', 'ObjectTest_CreateTest2');
139
		$obj2 = ObjectTest_CreateTest::create();
140
		$this->assertTrue($obj2 instanceof ObjectTest_CreateTest2);
141
142
		$obj2_2 = Object::strong_create('ObjectTest_CreateTest');
143
		$this->assertTrue($obj2_2 instanceof ObjectTest_CreateTest);
144
145
		Object::useCustomClass('ObjectTest_CreateTest', 'ObjectTest_CreateTest3', true);
146
		$obj3 = ObjectTest_CreateTest::create();
147
		$this->assertTrue($obj3 instanceof ObjectTest_CreateTest3);
148
149
		$obj3_2 = Object::strong_create('ObjectTest_CreateTest');
150
		$this->assertTrue($obj3_2 instanceof ObjectTest_CreateTest3);
151
	}
152
153
	/**
154
	 * Tests {@link Object::singleton()}
155
	 */
156
	public function testSingleton() {
157
		$inst = Controller::singleton();
158
		$this->assertInstanceOf('Controller', $inst);
159
		$inst2 = Controller::singleton();
160
		$this->assertSame($inst2, $inst);
161
	}
162
163
	public function testGetExtensions() {
164
		$this->assertEquals(
165
			Object::get_extensions('ObjectTest_ExtensionTest'),
166
			array(
167
				'oBjEcTTEST_ExtendTest1',
168
				"ObjectTest_ExtendTest2",
169
			)
170
		);
171
		$this->assertEquals(
172
			Object::get_extensions('ObjectTest_ExtensionTest', true),
173
			array(
174
				'oBjEcTTEST_ExtendTest1',
175
				"ObjectTest_ExtendTest2('FOO', 'BAR')",
176
			)
177
		);
178
		$inst = new ObjectTest_ExtensionTest();
179
		$extensions = $inst->getExtensionInstances();
180
		$this->assertEquals(count($extensions), 2);
181
		$this->assertInstanceOf(
182
			'ObjectTest_ExtendTest1',
183
			$extensions['ObjectTest_ExtendTest1']
184
		);
185
		$this->assertInstanceOf(
186
			'ObjectTest_ExtendTest2',
187
			$extensions['ObjectTest_ExtendTest2']
188
		);
189
		$this->assertInstanceOf(
190
			'ObjectTest_ExtendTest1',
191
			$inst->getExtensionInstance('ObjectTest_ExtendTest1')
192
		);
193
		$this->assertInstanceOf(
194
			'ObjectTest_ExtendTest2',
195
			$inst->getExtensionInstance('ObjectTest_ExtendTest2')
196
		);
197
	}
198
199
	/**
200
	 * Tests {@link Object::has_extension()}, {@link Object::add_extension()}
201
	 */
202
	public function testHasAndAddExtension() {
203
		// ObjectTest_ExtendTest1 is built in via $extensions
204
		$this->assertTrue(
205
			ObjectTest_ExtensionTest::has_extension('OBJECTTEST_ExtendTest1'),
206
			"Extensions are detected when set on Object::\$extensions on has_extension() without case-sensitivity"
207
		);
208
		$this->assertTrue(
209
			ObjectTest_ExtensionTest::has_extension('ObjectTest_ExtendTest1'),
210
			"Extensions are detected when set on Object::\$extensions on has_extension() without case-sensitivity"
211
		);
212
		$this->assertTrue(
213
			singleton('ObjectTest_ExtensionTest')->hasExtension('ObjectTest_ExtendTest1'),
214
			"Extensions are detected when set on Object::\$extensions on instance hasExtension() without"
215
				. " case-sensitivity"
216
		);
217
218
		// ObjectTest_ExtendTest2 is built in via $extensions (with parameters)
219
		$this->assertTrue(
220
			ObjectTest_ExtensionTest::has_extension('ObjectTest_ExtendTest2'),
221
			"Extensions are detected with static has_extension() when set on Object::\$extensions with"
222
				. " additional parameters"
223
		);
224
		$this->assertTrue(
225
			singleton('ObjectTest_ExtensionTest')->hasExtension('ObjectTest_ExtendTest2'),
226
			"Extensions are detected with instance hasExtension() when set on Object::\$extensions with"
227
				. " additional parameters"
228
		);
229
		$this->assertFalse(
230
			ObjectTest_ExtensionTest::has_extension('ObjectTest_ExtendTest3'),
231
			"Other extensions available in the system are not present unless explicitly added to this object"
232
				. " when checking through has_extension()"
233
		);
234
		$this->assertFalse(
235
			singleton('ObjectTest_ExtensionTest')->hasExtension('ObjectTest_ExtendTest3'),
236
			"Other extensions available in the system are not present unless explicitly added to this object"
237
				. " when checking through instance hasExtension()"
238
		);
239
240
		// ObjectTest_ExtendTest3 is added manually
241
		ObjectTest_ExtensionTest::add_extension('ObjectTest_ExtendTest3("Param")');
242
		$this->assertTrue(
243
			ObjectTest_ExtensionTest::has_extension('ObjectTest_ExtendTest3'),
244
			"Extensions are detected with static has_extension() when added through add_extension()"
245
		);
246
		// ObjectTest_ExtendTest4 is added manually
247
		ObjectTest_ExtensionTest3::add_extension('ObjectTest_ExtendTest4("Param")');
248
		// test against ObjectTest_ExtendTest3, not ObjectTest_ExtendTest3
249
		$this->assertTrue(
250
			ObjectTest_ExtensionTest3::has_extension('ObjectTest_ExtendTest4'),
251
			"Extensions are detected with static has_extension() when added through add_extension()"
252
		);
253
		// test against ObjectTest_ExtendTest3, not ObjectTest_ExtendTest4 to test if it picks up
254
		// the sub classes of ObjectTest_ExtendTest3
255
		$this->assertTrue(
256
			ObjectTest_ExtensionTest3::has_extension('ObjectTest_ExtendTest3'),
257
			"Sub-Extensions are detected with static has_extension() when added through add_extension()"
258
		);
259
		// strictly test against ObjectTest_ExtendTest3, not ObjectTest_ExtendTest4 to test if it picks up
260
		// the sub classes of ObjectTest_ExtendTest3
261
		$this->assertFalse(
262
			ObjectTest_ExtensionTest3::has_extension('ObjectTest_ExtendTest3', null, true),
263
			"Sub-Extensions are detected with static has_extension() when added through add_extension()"
264
		);
265
		// a singleton() wouldn't work as its already initialized
266
		$objectTest_ExtensionTest = new ObjectTest_ExtensionTest();
267
		$this->assertTrue(
268
			$objectTest_ExtensionTest->hasExtension('ObjectTest_ExtendTest3'),
269
			"Extensions are detected with instance hasExtension() when added through add_extension()"
270
		);
271
272
		// @todo At the moment, this does NOT remove the extension due to parameterized naming,
273
		//  meaning the extension will remain added in further test cases
274
		ObjectTest_ExtensionTest::remove_extension('ObjectTest_ExtendTest3');
275
	}
276
277
	public function testRemoveExtension() {
278
		// manually add ObjectTest_ExtendTest2
279
		ObjectTest_ExtensionRemoveTest::add_extension('ObjectTest_ExtendTest2');
280
		$this->assertTrue(
281
			ObjectTest_ExtensionRemoveTest::has_extension('ObjectTest_ExtendTest2'),
282
			"Extension added through \$add_extension() are added correctly"
283
		);
284
285
		ObjectTest_ExtensionRemoveTest::remove_extension('ObjectTest_ExtendTest2');
286
		$this->assertFalse(
287
			ObjectTest_ExtensionRemoveTest::has_extension('ObjectTest_ExtendTest2'),
288
			"Extension added through \$add_extension() are detected as removed in has_extension()"
289
		);
290
		$this->assertFalse(
291
			singleton('ObjectTest_ExtensionRemoveTest')->hasExtension('ObjectTest_ExtendTest2'),
292
			"Extensions added through \$add_extension() are detected as removed in instances through hasExtension()"
293
		);
294
295
		// ObjectTest_ExtendTest1 is already present in $extensions
296
		ObjectTest_ExtensionRemoveTest::remove_extension('ObjectTest_ExtendTest1');
297
298
		$this->assertFalse(
299
			ObjectTest_ExtensionRemoveTest::has_extension('ObjectTest_ExtendTest1'),
300
			"Extension added through \$extensions are detected as removed in has_extension()"
301
		);
302
303
		$objectTest_ExtensionRemoveTest = new ObjectTest_ExtensionRemoveTest();
304
		$this->assertFalse(
305
			$objectTest_ExtensionRemoveTest->hasExtension('ObjectTest_ExtendTest1'),
306
			"Extensions added through \$extensions are detected as removed in instances through hasExtension()"
307
		);
308
	}
309
310
	public function testRemoveExtensionWithParameters() {
311
		ObjectTest_ExtensionRemoveTest::add_extension('ObjectTest_ExtendTest2("MyParam")');
312
313
		$this->assertTrue(
314
			ObjectTest_ExtensionRemoveTest::has_extension('ObjectTest_ExtendTest2'),
315
			"Extension added through \$add_extension() are added correctly"
316
		);
317
318
		ObjectTest_ExtensionRemoveTest::remove_extension('ObjectTest_ExtendTest2');
319
		$this->assertFalse(
320
			Object::has_extension('ObjectTest_ExtensionRemoveTest', 'ObjectTest_ExtendTest2'),
321
			"Extension added through \$add_extension() are detected as removed in has_extension()"
322
		);
323
324
		$objectTest_ExtensionRemoveTest = new ObjectTest_ExtensionRemoveTest();
325
		$this->assertFalse(
326
			$objectTest_ExtensionRemoveTest->hasExtension('ObjectTest_ExtendTest2'),
327
			"Extensions added through \$extensions are detected as removed in instances through hasExtension()"
328
		);
329
	}
330
331
	public function testParentClass() {
332
		$this->assertEquals(ObjectTest_MyObject::create()->parentClass(), 'Object');
333
	}
334
335
	public function testIsA() {
336
		$this->assertTrue(ObjectTest_MyObject::create() instanceof Object);
337
		$this->assertTrue(ObjectTest_MyObject::create() instanceof ObjectTest_MyObject);
338
	}
339
340
	/**
341
	 * Tests {@link Object::hasExtension() and Object::getExtensionInstance()}
342
	 */
343
	public function testExtInstance() {
344
		$obj = new ObjectTest_ExtensionTest2();
345
346
		$this->assertTrue($obj->hasExtension('ObjectTest_Extension'));
347
		$this->assertTrue($obj->getExtensionInstance('ObjectTest_Extension') instanceof ObjectTest_Extension);
348
	}
349
350
	public function testCacheToFile() {
351
		$this->markTestIncomplete();
352
		/*
353
		// This doesn't run properly on our build slave.
354
		$obj = new ObjectTest_CacheTest();
355
356
		$obj->clearCache('cacheMethod');
357
		$obj->clearCache('cacheMethod', null, array(true));
358
		$obj->clearCache('incNumber');
359
360
		$this->assertEquals('noarg', $obj->cacheToFile('cacheMethod', -1));
361
		$this->assertEquals('hasarg', $obj->cacheToFile('cacheMethod', -1, null, array(true)));
362
		$this->assertEquals('hasarg', $obj->cacheToFile('cacheMethod', 3600, null, array(true)));
363
364
		// -1 lifetime will ensure that the cache isn't read - number incremented
365
		$this->assertEquals(1, $obj->cacheToFile('incNumber', -1));
366
		// -1 lifetime will ensure that the cache isn't read - number incremented
367
		$this->assertEquals(2, $obj->cacheToFile('incNumber', -1));
368
		// Number shouldn't be incremented now because we're using the cached version
369
		$this->assertEquals(2, $obj->cacheToFile('incNumber'));
370
		*/
371
	}
372
373
	public function testExtend() {
374
		$object   = new ObjectTest_ExtendTest();
375
		$argument = 'test';
376
377
		$this->assertEquals($object->extend('extendableMethod'), array('ExtendTest2()'));
378
		$this->assertEquals($object->extend('extendableMethod', $argument), array('ExtendTest2(modified)'));
379
		$this->assertEquals($argument, 'modified');
380
381
		$this->assertEquals($object->invokeWithExtensions('extendableMethod'), array('ExtendTest()', 'ExtendTest2()'));
382
		$this->assertEquals (
383
			$object->invokeWithExtensions('extendableMethod', 'test'),
384
			array('ExtendTest(test)', 'ExtendTest2(modified)')
385
		);
386
387
		$object2 = new ObjectTest_Extending();
388
		$first = 1;
389
		$second = 2;
390
		$third = 3;
391
		$result = $object2->getResults($first, $second, $third);
392
		$this->assertEquals(
393
			array(array('before', 'extension', 'after')),
394
			$result
395
		);
396
		$this->assertEquals(31, $first);
397
		$this->assertEquals(32, $second);
398
		$this->assertEquals(33, $third);
399
	}
400
401
	public function testParseClassSpec() {
402
		// Simple case
403
		$this->assertEquals(
404
			array('Versioned',array('Stage', 'Live')),
405
			Object::parse_class_spec("Versioned('Stage','Live')")
406
		);
407
		// String with commas
408
		$this->assertEquals(
409
			array('Versioned',array('Stage,Live', 'Stage')),
410
			Object::parse_class_spec("Versioned('Stage,Live','Stage')")
411
		);
412
		// String with quotes
413
		$this->assertEquals(
414
			array('Versioned',array('Stage\'Stage,Live\'Live', 'Live')),
415
			Object::parse_class_spec("Versioned('Stage\'Stage,Live\'Live','Live')")
416
		);
417
418
		// True, false and null values
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
419
		$this->assertEquals(
420
			array('ClassName', array('string', true, array('string', false))),
421
			Object::parse_class_spec('ClassName("string", true, array("string", false))')
422
		);
423
		$this->assertEquals(
424
			array('ClassName', array(true, false, null)),
425
			Object::parse_class_spec('ClassName(true, false, null)')
426
		);
427
428
		// Array
429
		$this->assertEquals(
430
			array('Enum',array(array('Accepted', 'Pending', 'Declined', 'Unsubmitted'), 'Unsubmitted')),
431
			Object::parse_class_spec("Enum(array('Accepted', 'Pending', 'Declined', 'Unsubmitted'), 'Unsubmitted')")
432
		);
433
		// Nested array
434
		$this->assertEquals(
435
			array('Enum',array(array('Accepted', 'Pending', 'Declined', array('UnsubmittedA','UnsubmittedB')),
436
				'Unsubmitted')),
437
			Object::parse_class_spec(
438
				"Enum(array('Accepted', 'Pending', 'Declined', array('UnsubmittedA','UnsubmittedB')), 'Unsubmitted')")
439
		);
440
		// 5.4 Shorthand Array
441
		$this->assertEquals(
442
			array('Enum',array(array('Accepted', 'Pending', 'Declined', 'Unsubmitted'), 'Unsubmitted')),
443
			Object::parse_class_spec("Enum(['Accepted', 'Pending', 'Declined', 'Unsubmitted'), 'Unsubmitted']")
444
		);
445
		// 5.4 Nested shorthand array
446
		$this->assertEquals(
447
			array('Enum',array(array('Accepted', 'Pending', 'Declined', array('UnsubmittedA','UnsubmittedB')),
448
				'Unsubmitted')),
449
			Object::parse_class_spec(
450
				"Enum(['Accepted', 'Pending', 'Declined', ['UnsubmittedA','UnsubmittedB']], 'Unsubmitted')")
451
		);
452
		// Namespaced class
453
		$this->assertEquals(
454
			array('Test\MyClass', array()),
455
			Object::parse_class_spec('Test\MyClass')
456
		);
457
		// Fully qualified namespaced class
458
		$this->assertEquals(
459
			array('\Test\MyClass', array()),
460
			Object::parse_class_spec('\Test\MyClass')
461
		);
462
	}
463
}
464
465
/**#@+
466
 * @ignore
467
 */
468
469
class ObjectTest_T1A extends Object {
470
	public function testMethod() {
471
		return true;
472
	}
473
	public function otherMethod() {
474
		return true;
475
	}
476
}
477
478
class ObjectTest_T1B extends Object {
479
	public function someMethod() {
480
		return true;
481
	}
482
}
483
484
class ObjectTest_T1C extends Object {
485
	public function t1cMethod() {
486
		return true;
487
	}
488
}
489
490
class ObjectTest_T2 extends Object {
491
	protected $failover;
492
	protected $failoverArr = array();
493
494
	public function __construct() {
495
		$this->failover = new ObjectTest_T1A();
496
		$this->failoverArr[0] = new ObjectTest_T1B();
497
		$this->failoverArr[1] = new ObjectTest_T1C();
498
499
		parent::__construct();
500
	}
501
502
	public function defineMethods() {
503
		$this->addWrapperMethod('Wrapping', 'wrappedMethod');
504
505
		$this->addMethodsFrom('failover');
506
		$this->addMethodsFrom('failoverArr',0);
507
		$this->addMethodsFrom('failoverArr',1);
508
509
		$this->createMethod('testCreateMethod', 'return "created";');
510
	}
511
512
	public function wrappedMethod($val) {
513
		return $val;
514
	}
515
516
	public function normalMethod() {
517
		return true;
518
	}
519
520
}
521
522
class ObjectTest_MyObject extends Object {
523
	public $title = 'my object';
524
	/** @config */
525
	private static $mystaticProperty = "MyObject";
526
	static $mystaticArray = array('one');
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $mystaticArray.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
527
}
528
529
class ObjectTest_MySubObject extends ObjectTest_MyObject {
530
	public $title = 'my subobject';
531
	private static $mystaticProperty = "MySubObject";
532
	static $mystaticSubProperty = "MySubObject";
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $mystaticSubProperty.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
533
	static $mystaticArray = array('two');
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $mystaticArray.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
534
}
535
536
class ObjectTest_CreateTest extends Object {
537
538
	public $constructArguments;
539
540
	public function __construct() {
541
		$this->constructArguments = func_get_args();
542
		parent::__construct();
543
	}
544
545
}
546
547
class ObjectTest_CreateTest2 extends Object {}
548
class ObjectTest_CreateTest3 extends Object {}
549
550
class ObjectTest_ExtensionTest extends Object {
551
552
	private static $extensions = array (
553
		'oBjEcTTEST_ExtendTest1',
554
		"ObjectTest_ExtendTest2('FOO', 'BAR')",
555
	);
556
557
}
558
559
class ObjectTest_ExtensionTest2 extends Object {
560
	private static $extensions = array('ObjectTest_Extension');
561
}
562
563
564
class ObjectTest_ExtensionTest3 extends Object {
565
}
566
567
class ObjectTest_ExtensionRemoveTest extends Object {
568
569
	private static $extensions = array (
570
		'ObjectTest_ExtendTest1',
571
	);
572
573
}
574
575
class ObjectTest_Extension extends Extension {}
576
577
class ObjectTest_CacheTest extends Object {
578
579
	public $count = 0;
580
581
	public function cacheMethod($arg1 = null) {
582
		return ($arg1) ? 'hasarg' : 'noarg';
583
	}
584
585
	public function incNumber() {
586
		$this->count++;
587
		return $this->count;
588
	}
589
590
}
591
592
class ObjectTest_ExtendTest extends Object {
593
	private static $extensions = array('ObjectTest_ExtendTest1', 'ObjectTest_ExtendTest2');
594
	public function extendableMethod($argument = null) { return "ExtendTest($argument)"; }
595
}
596
597
class ObjectTest_ExtendTest1 extends Extension {
598
	public function extendableMethod(&$argument = null) {
599
		if($argument) $argument = 'modified';
600
		return null;
601
	}
602
}
603
604
class ObjectTest_ExtendTest2 extends Extension {
605
	public function extendableMethod($argument = null) { return "ExtendTest2($argument)"; }
606
}
607
608
class ObjectTest_ExtendTest3 extends Extension {
609
	public function extendableMethod($argument = null) { return "ExtendTest3($argument)"; }
610
}
611
612
class ObjectTest_ExtendTest4 extends ObjectTest_ExtendTest3 {
613
	public function extendableMethod($argument = null) { return "ExtendTest4($argument)"; }
614
}
615
616
class ObjectTest_Extending extends Object implements TestOnly {
617
618
	private static $extensions = array(
619
		'ObjectTest_Extending_Extension'
620
	);
621
622
	public function getResults(&$first, &$second, &$third) {
623
		// Before extending should be invoked second
624
		$this->beforeExtending('updateResult', function(&$first, &$second, &$third) {
625
			if($first === 1 && $second === 2 && $third === 3) {
626
				$first = 11;
627
				$second = 12;
628
				$third = 13;
629
				return 'before';
630
			}
631
			return 'before-error';
632
		});
633
634
		// After extending should be invoked fourth
635
		$this->afterExtending('updateResult', function(&$first, &$second, &$third) {
636
			if($first === 21 && $second === 22 && $third = 23) {
637
				$first = 31;
638
				$second = 32;
639
				$third = 33;
640
				return 'after';
641
			}
642
			return 'after-error';
643
		});
644
645
		// Function body invoked first
646
		$result = $this->extend('updateResult', $first, $second, $third);
647
		return array($result);
648
	}
649
}
650
651
class ObjectTest_Extending_Extension extends Extension implements TestOnly {
652
	public function updateResult(&$first, &$second, &$third) {
653
		// Extension should be invoked third
654
		if($first === 11 && $second === 12 && $third == 13) {
655
			$first = 21;
656
			$second = 22;
657
			$third = 23;
658
			return 'extension';
659
		}
660
		return 'extension-error';
661
	}
662
}
663
664
/**#@-*/
665