20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
35 protected function setUp()
38 $this->dummyObject->setProperty(
'string1');
39 $this->dummyObject->setAnotherProperty(42);
40 $this->dummyObject->shouldNotBePickedUp =
true;
49 $this->assertEquals($property,
'string1');
58 $this->assertEquals($property, 42,
'A property of a given object was not returned correctly.');
67 $this->assertEquals($property,
'unexposed',
'A property of a given object was not returned correctly.');
75 $this->dummyObject->unknownProperty =
'unknown';
77 $this->assertEquals($property,
'unknown',
'A property of a given object was not returned correctly.');
85 $this->expectException(PropertyNotAccessibleException::class);
86 $this->expectExceptionCode(1302855001);
95 $this->expectException(PropertyNotAccessibleException::class);
96 $this->expectExceptionCode(1476109666);
106 $this->assertNull($result);
115 $this->assertTrue($property);
123 $this->expectException(\InvalidArgumentException::class);
124 $this->expectExceptionCode(1231178303);
133 $this->expectException(\InvalidArgumentException::class);
134 $this->expectExceptionCode(1231178878);
152 $this->assertAttributeEquals(
'was set anyway',
'unexposedProperty', $this->dummyObject);
161 $this->assertAttributeEquals(
'was set anyway',
'unknownProperty', $this->dummyObject);
170 $this->assertEquals($this->dummyObject->getProperty(), 4242,
'setProperty does not work with setter.');
179 $this->assertEquals($this->dummyObject->publicProperty, 4242,
'setProperty does not work with public property.');
187 $arrayObject = new \ArrayObject();
191 $this->assertEquals(4242, $arrayObject[
'publicProperty']);
192 $this->assertEquals(
'value', $array[
'key']);
200 $arrayObject = new \ArrayObject([
'key' =>
'value']);
202 $this->assertEquals(
'value', $actual,
'getProperty does not work with ArrayObject property.');
210 $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
211 $object = new \stdClass();
212 $objectStorage->attach($object);
214 $this->assertSame($object, $actual,
'getProperty does not work with ObjectStorage property.');
222 $arrayAccessInstance = new \TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\ArrayAccessClass([
'key' =>
'value']);
224 $this->assertEquals(
'value', $actual,
'getProperty does not work with Array Access property.');
232 $arrayAccessInstance = new \TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\ArrayAccessClass([]);
234 $this->assertEquals(
'default-value', $actual,
'getProperty does not work with Array Access property.');
242 $arrayAccessInstance = new \TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\ArrayAccessClass([
'virtual' =>
'overridden-value']);
244 $this->assertEquals(
'overridden-value', $actual,
'getProperty does not work with Array Access property.');
252 $array = [
'key' =>
'value'];
254 $this->assertEquals($expected,
'value',
'getProperty does not work with Array property.');
262 $array = [
'parent' => [
'key' =>
'value']];
264 $this->assertEquals(
'value', $actual,
'getPropertyPath does not work with Array property.');
272 $array = [
'parent' => new \ArrayObject([
'key' =>
'value'])];
274 $this->assertEquals(
'value', $actual,
'getPropertyPath does not work with Array Access property.');
284 'parent' => $objectStorage,
297 foreach ($objectStorage as $object) {
301 $this->assertSame(2, $i);
310 $exampleObject = new \stdClass();
311 $exampleObject->key =
'value';
312 $exampleObject2 = new \stdClass();
313 $exampleObject2->key =
'value2';
314 $objectStorage->attach($exampleObject);
315 $objectStorage->attach($exampleObject2);
316 return $objectStorage;
326 'parent' => $objectStorage,
339 foreach ($objectStorage as $object) {
343 $this->assertSame(2, $i);
351 $objectStorage = new \SplObjectStorage();
352 $exampleObject = new \stdClass();
353 $exampleObject->key =
'value';
354 $exampleObject2 = new \stdClass();
355 $exampleObject2->key =
'value2';
356 $objectStorage->attach($exampleObject);
357 $objectStorage->attach($exampleObject2);
358 return $objectStorage;
367 $expectedPropertyNames = [
'anotherBooleanProperty',
'anotherProperty',
'booleanProperty',
'property',
'property2',
'publicProperty',
'publicProperty2',
'someValue'];
368 $this->assertEquals($gettablePropertyNames, $expectedPropertyNames,
'getGettablePropertyNames returns not all gettable properties.');
376 $dateTimeZone = new \DateTimeZone(
'+2');
378 $expectedPropertyNames = [
'location',
'name'];
379 $this->assertArraySubset($expectedPropertyNames, $gettablePropertyNames);
388 $expectedPropertyNames = [
'anotherBooleanProperty',
'anotherProperty',
'property',
'property2',
'publicProperty',
'publicProperty2',
'writeOnlyMagicProperty'];
389 $this->assertEquals($settablePropertyNames, $expectedPropertyNames,
'getSettablePropertyNames returns not all settable properties.');
397 $stdClassObject = new \stdClass();
398 $stdClassObject->property =
'string1';
399 $stdClassObject->property2 =
null;
401 $expectedPropertyNames = [
'property',
'property2'];
402 $this->assertEquals($expectedPropertyNames, $settablePropertyNames,
'getSettablePropertyNames returns not all settable properties.');
411 $expectedProperties = [
412 'anotherBooleanProperty' =>
true,
413 'anotherProperty' => 42,
414 'booleanProperty' =>
true,
415 'property' =>
'string1',
417 'publicProperty' =>
null,
418 'publicProperty2' => 42,
421 $this->assertEquals($allProperties, $expectedProperties,
'expectedProperties did not return the right values for the properties.');
429 $stdClassObject = new \stdClass();
430 $stdClassObject->property =
'string1';
431 $stdClassObject->property2 =
null;
432 $stdClassObject->publicProperty2 = 42;
434 $expectedProperties = [
435 'property' =>
'string1',
437 'publicProperty2' => 42
439 $this->assertEquals($expectedProperties, $allProperties,
'expectedProperties did not return the right values for the properties.');
459 $stdClassObject = new \stdClass();
460 $stdClassObject->property =
'foo';
483 [
'publicProperty',
true],
485 [
'booleanProperty',
true],
486 [
'anotherBooleanProperty',
true],
487 [
'privateProperty',
false],
488 [
'writeOnlyMagicProperty',
false]
497 $arrayObject = new \ArrayObject();
498 $arrayObject[
'key'] =
'v';
508 $stdClassObject = new \stdClass();
509 $stdClassObject->property =
'foo';
520 $alternativeObject->setProperty(
'test');
521 $this->dummyObject->setProperty2($alternativeObject);
524 $this->assertEquals($expected, $actual);
533 $alternativeObject->setProperty(
new \stdClass());
534 $this->dummyObject->setProperty2($alternativeObject);
543 $string =
'Hello world';
552 $object = new \stdClass();
553 $object->foo =
'Hello World';