TYPO3 CMS  TYPO3_7-6
ContainerTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
25  protected $container;
26 
30  protected $cachedClassInfo;
31 
32  protected function setUp()
33  {
34  // The mocked cache will always indicate that he has nothing in the cache to force that we get the real class info
35  $mockedCache = $this->getMock(\TYPO3\CMS\Extbase\Object\Container\ClassInfoCache::class, ['get', 'set']);
36  $mockedCache->expects($this->any())->method('get')->will($this->returnValue(false));
37  $mockedCache->expects($this->never())->method('has');
38  $this->container = $this->getMock(\TYPO3\CMS\Extbase\Object\Container\Container::class, ['log', 'getClassInfoCache']);
39  $this->container->expects($this->any())->method('getClassInfoCache')->will($this->returnValue($mockedCache));
40  }
41 
46  {
47  $object = $this->container->getInstance('t3lib_object_tests_c');
48  $this->assertInstanceOf('t3lib_object_tests_c', $object);
49  }
50 
55  {
56  $object = $this->container->getInstance(\TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\NamespacedClass::class);
57  $this->assertInstanceOf(\TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\NamespacedClass::class, $object);
58  }
59 
64  {
65  $object = $this->container->getInstance('t3lib_object_tests_b');
66  $this->assertInstanceOf('t3lib_object_tests_b', $object);
67  $this->assertInstanceOf('t3lib_object_tests_c', $object->c);
68  }
69 
74  {
75  $object = $this->container->getInstance('t3lib_object_tests_a');
76  $this->assertInstanceOf('t3lib_object_tests_a', $object);
77  $this->assertInstanceOf('t3lib_object_tests_c', $object->b->c);
78  }
79 
84  {
85  $object = $this->container->getInstance('t3lib_object_tests_amixed_array');
86  $this->assertInstanceOf('t3lib_object_tests_amixed_array', $object);
87  $this->assertEquals(['some' => 'default'], $object->myvalue);
88  }
89 
94  {
95  $object = $this->container->getInstance('t3lib_object_tests_amixed_null');
96  $this->assertInstanceOf('t3lib_object_tests_amixed_null', $object);
97  $this->assertNull($object->myvalue);
98  }
99 
105  {
106  $this->container->getInstance('t3lib_object_tests_amixed_array_singleton', ['somevalue']);
107  }
108 
113  {
114  $object = $this->container->getInstance('t3lib_object_tests_amixed_array');
115  $this->assertInstanceOf('t3lib_object_tests_b', $object->b);
116  $this->assertInstanceOf('t3lib_object_tests_c', $object->c);
117  $this->assertEquals(['some' => 'default'], $object->myvalue);
118  }
119 
124  {
125  $mockObject = $this->getMock('t3lib_object_tests_c');
126  $object = $this->container->getInstance('t3lib_object_tests_a', [$mockObject]);
127  $this->assertInstanceOf('t3lib_object_tests_a', $object);
128  $this->assertSame($mockObject, $object->c);
129  }
130 
135  {
136  $object1 = $this->container->getInstance('t3lib_object_tests_a');
137  $object2 = $this->container->getInstance('t3lib_object_tests_a');
138  $this->assertNotSame($object1, $object2);
139  }
140 
145  {
146  $object1 = $this->container->getInstance('t3lib_object_tests_singleton');
147  $object2 = $this->container->getInstance('t3lib_object_tests_singleton');
148  $this->assertSame($object1, $object2);
149  }
150 
156  {
157  $this->container->getInstance('t3lib_object_tests_cyclic1WithSetterDependency');
158  }
159 
165  {
166  $this->container->getInstance('t3lib_object_tests_cyclic1');
167  }
168 
174  {
175  $this->container->getInstance('nonextistingclass_bla');
176  }
177 
182  {
183  $className = \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\NamespacedClass::class;
184  $classNameHash = md5($className);
185  $mockedCache = $this->getMock(\TYPO3\CMS\Extbase\Object\Container\ClassInfoCache::class, ['has', 'set', 'get']);
186  $container = $this->getMock(\TYPO3\CMS\Extbase\Object\Container\Container::class, ['log', 'getClassInfoCache']);
187  $container->expects($this->any())->method('getClassInfoCache')->will($this->returnValue($mockedCache));
188  $mockedCache->expects($this->never())->method('has');
189  $mockedCache->expects($this->once())->method('get')->with($classNameHash)->will($this->returnValue(false));
190  $mockedCache->expects($this->once())->method('set')->with($classNameHash, $this->anything())->will($this->returnCallback([$this, 'setClassInfoCacheCallback']));
191  $container->getInstance($className);
192  $this->assertInstanceOf(\TYPO3\CMS\Extbase\Object\Container\ClassInfo::class, $this->cachedClassInfo);
193  $this->assertEquals($className, $this->cachedClassInfo->getClassName());
194  }
195 
200  {
201  $instance = $this->container->getInstance('t3lib_object_tests_initializable');
202  $this->assertTrue($instance->isInitialized());
203  }
204 
212  public function setClassInfoCacheCallback($id, \TYPO3\CMS\Extbase\Object\Container\ClassInfo $value)
213  {
214  $this->cachedClassInfo = $value;
215  }
216 
221  {
222  $object = $this->container->getEmptyObject('t3lib_object_tests_c');
223  $this->assertInstanceOf('t3lib_object_tests_c', $object);
224  }
225 
230  {
231  $object = $this->container->getEmptyObject('t3lib_object_tests_serializable');
232  $this->assertInstanceOf('t3lib_object_tests_serializable', $object);
233  }
234 
239  {
240  $object = $this->container->getEmptyObject('t3lib_object_tests_initializable');
241  $this->assertTrue($object->isInitialized());
242  }
243 
247  public function test_canGetChildClass()
248  {
249  $object = $this->container->getInstance('t3lib_object_tests_b_child');
250  $this->assertInstanceOf('t3lib_object_tests_b_child', $object);
251  }
252 
257  {
258  $this->container->registerImplementation('t3lib_object_tests_someinterface', 't3lib_object_tests_someimplementation');
259  $object = $this->container->getInstance('t3lib_object_tests_needsinterface');
260  $this->assertInstanceOf('t3lib_object_tests_needsinterface', $object);
261  $this->assertInstanceOf('t3lib_object_tests_someinterface', $object->dependency);
262  $this->assertInstanceOf('t3lib_object_tests_someimplementation', $object->dependency);
263  }
264 
269  {
270  $object = $this->container->getInstance('t3lib_object_tests_resolveablecyclic1');
271  $this->assertInstanceOf('t3lib_object_tests_resolveablecyclic1', $object);
272  $this->assertInstanceOf('t3lib_object_tests_resolveablecyclic1', $object->o2->o3->o1);
273  }
274 
279  {
280  $this->container->expects($this->once())->method('log')->with('The singleton "t3lib_object_singletonNeedsPrototype" needs a prototype in "injectDependency". This is often a bad code smell; often you rather want to inject a singleton.', 1);
281  $object = $this->container->getInstance('t3lib_object_singletonNeedsPrototype');
282  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
283  }
284 
289  {
290  $this->container->expects($this->never())->method('log');
291  $object = $this->container->getInstance('t3lib_object_singletonNeedsSingleton');
292  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
293  }
294 
299  {
300  $this->container->expects($this->never())->method('log');
301  $object = $this->container->getInstance('t3lib_object_prototypeNeedsPrototype');
302  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
303  }
304 
309  {
310  $this->container->expects($this->never())->method('log');
311  $object = $this->container->getInstance('t3lib_object_prototypeNeedsSingleton');
312  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
313  }
314 
319  {
320  $this->container->expects($this->once())->method('log')->with('The singleton "t3lib_object_singletonNeedsPrototypeInConstructor" needs a prototype in the constructor. This is often a bad code smell; often you rather want to inject a singleton.', 1);
321  $object = $this->container->getInstance('t3lib_object_singletonNeedsPrototypeInConstructor');
322  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
323  }
324 
329  {
330  $this->container->expects($this->never())->method('log');
331  $object = $this->container->getInstance('t3lib_object_singletonNeedsSingletonInConstructor');
332  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
333  }
334 
339  {
340  $this->container->expects($this->never())->method('log');
341  $object = $this->container->getInstance('t3lib_object_prototypeNeedsPrototypeInConstructor');
342  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
343  }
344 
349  {
350  $this->container->expects($this->never())->method('log');
351  $object = $this->container->getInstance('t3lib_object_prototypeNeedsSingletonInConstructor');
352  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
353  }
354 
359  {
360  $this->assertTrue($this->container->isSingleton(\TYPO3\CMS\Extbase\Object\Container\Container::class));
361  $this->assertFalse($this->container->isSingleton(\TYPO3\CMS\Extbase\Core\Bootstrap::class));
362  }
363 
368  {
369  $this->assertFalse($this->container->isPrototype(\TYPO3\CMS\Extbase\Object\Container\Container::class));
370  $this->assertTrue($this->container->isPrototype(\TYPO3\CMS\Extbase\Core\Bootstrap::class));
371  }
372 
373  /************************************************
374  * Test regarding constructor argument injection
375  ************************************************/
376 
382  {
383  $object = $this->container->getInstance(
384  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\SimpleTypeConstructorArgument::class,
385  [true]
386  );
387  $this->assertTrue($object->foo);
388  }
389 
395  {
396  $object = $this->container->getInstance(
397  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\SimpleTypeConstructorArgument::class
398  );
399  $this->assertFalse($object->foo);
400  }
401 
407  {
408  $argumentTestClass = new Fixtures\ArgumentTestClass();
409  $object = $this->container->getInstance(
410  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgument::class,
411  [$argumentTestClass]
412  );
413  $this->assertInstanceOf(
414  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgument::class,
415  $object
416  );
417  $this->assertSame($argumentTestClass, $object->argumentTestClass);
418  }
419 
425  {
426  $object = $this->container->getInstance(
427  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgument::class
428  );
429  $this->assertInstanceOf(
430  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgument::class,
431  $object
432  );
433  $this->assertInstanceOf(
434  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
435  $object->argumentTestClass
436  );
437  }
438 
444  {
445  $object = $this->container->getInstance(
446  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class
447  );
448  $this->assertInstanceOf(
449  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class,
450  $object
451  );
452  $this->assertNull($object->argumentTestClass);
453  }
454 
460  {
461  $object = $this->container->getInstance(
462  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class,
463  [null]
464  );
465  $this->assertInstanceOf(
466  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class,
467  $object
468  );
469  $this->assertNull($object->argumentTestClass);
470  }
471 
477  {
478  $argumentTestClass = new Fixtures\ArgumentTestClass();
479  $object = $this->container->getInstance(
480  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class,
481  [$argumentTestClass]
482  );
483  $this->assertInstanceOf(
484  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class,
485  $object
486  );
487  $this->assertSame($argumentTestClass, $object->argumentTestClass);
488  }
489 
495  {
496  $firstArgument = new Fixtures\ArgumentTestClass();
497  $secondArgument = new Fixtures\ArgumentTestClass();
498  $object = $this->container->getInstance(
499  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
500  [$firstArgument, $secondArgument]
501  );
502  $this->assertInstanceOf(
503  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
504  $object
505  );
506  $this->assertSame(
507  $firstArgument,
508  $object->argumentTestClass
509  );
510  $this->assertSame(
511  $secondArgument,
512  $object->argumentTestClassTwo
513  );
514  }
515 
521  {
522  $object = $this->container->getInstance(
523  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class
524  );
525  $this->assertInstanceOf(
526  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
527  $object
528  );
529  $this->assertInstanceOf(
530  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
531  $object->argumentTestClass
532  );
533  $this->assertInstanceOf(
534  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
535  $object->argumentTestClassTwo
536  );
537  $this->assertNotSame(
538  $object->argumentTestClass,
539  $object->argumentTestClassTwo
540  );
541  }
542 
548  {
549  $firstArgument = new Fixtures\ArgumentTestClass();
550  $object = $this->container->getInstance(
551  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
552  [$firstArgument]
553  );
554  $this->assertInstanceOf(
555  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
556  $object
557  );
558  $this->assertSame(
559  $firstArgument,
560  $object->argumentTestClass
561  );
562  $this->assertInstanceOf(
563  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
564  $object->argumentTestClassTwo
565  );
566  $this->assertNotSame(
567  $object->argumentTestClass,
568  $object->argumentTestClassTwo
569  );
570  }
571 
577  {
578  $secondArgument = new Fixtures\ArgumentTestClass();
579  $object = $this->container->getInstance(
580  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
581  [null, $secondArgument]
582  );
583  $this->assertInstanceOf(
584  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
585  $object
586  );
587  $this->assertInstanceOf(
588  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
589  $object->argumentTestClass
590  );
591  $this->assertInstanceOf(
592  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
593  $object->argumentTestClassTwo
594  );
595  $this->assertSame(
596  $secondArgument,
597  $object->argumentTestClassTwo
598  );
599  $this->assertNotSame(
600  $object->argumentTestClass,
601  $object->argumentTestClassTwo
602  );
603  }
604 
610  {
611  $firstArgument = new Fixtures\ArgumentTestClass();
612  $secondArgument = new Fixtures\ArgumentTestClass();
613  $object = $this->container->getInstance(
614  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
615  [$firstArgument, $secondArgument]
616  );
617  $this->assertInstanceOf(
618  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
619  $object
620  );
621  $this->assertSame(
622  $firstArgument,
623  $object->argumentTestClass
624  );
625  $this->assertSame(
626  $secondArgument,
627  $object->argumentTestClassTwo
628  );
629  }
630 
636  {
637  $object = $this->container->getInstance(
638  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class
639  );
640  $this->assertInstanceOf(
641  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
642  $object
643  );
644  $this->assertInstanceOf(
645  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
646  $object->argumentTestClass
647  );
648  $this->assertNull($object->argumentTestClassTwo);
649  }
650 
656  {
657  $object = $this->container->getInstance(
658  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
659  [null, null]
660  );
661  $this->assertInstanceOf(
662  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
663  $object
664  );
665  $this->assertInstanceOf(
666  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
667  $object->argumentTestClass
668  );
669  $this->assertNull($object->argumentTestClassTwo);
670  }
671 
677  {
678  $firstArgument = new Fixtures\ArgumentTestClass();
679  $object = $this->container->getInstance(
680  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
681  [$firstArgument]
682  );
683  $this->assertInstanceOf(
684  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
685  $object
686  );
687  $this->assertSame(
688  $firstArgument,
689  $object->argumentTestClass
690  );
691  $this->assertNull($object->argumentTestClassTwo);
692  }
693 
699  {
700  $firstArgument = new Fixtures\ArgumentTestClass();
701  $object = $this->container->getInstance(
702  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
703  [$firstArgument, null]
704  );
705  $this->assertInstanceOf(
706  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
707  $object
708  );
709  $this->assertSame(
710  $firstArgument,
711  $object->argumentTestClass
712  );
713  $this->assertNull($object->argumentTestClassTwo);
714  }
715 
722  {
723  $object = $this->container->getInstance(
724  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
725  [null]
726  );
727  $this->assertInstanceOf(
728  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
729  $object
730  );
731  $this->assertInstanceOf(
732  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
733  $object->argumentTestClassTwo
734  );
735  }
736 
742  {
743  $first = new Fixtures\ArgumentTestClass();
744  $second = new Fixtures\ArgumentTestClass();
745  $object = $this->container->getInstance(
746  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
747  [$first, $second]
748  );
749  $this->assertInstanceOf(
750  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
751  $object
752  );
753  $this->assertSame(
754  $first,
755  $object->argumentTestClass
756  );
757  $this->assertSame(
758  $second,
759  $object->argumentTestClassTwo
760  );
761  }
762 
768  {
769  $first = new Fixtures\ArgumentTestClass();
770  $object = $this->container->getInstance(
771  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
772  [$first]
773  );
774  $this->assertInstanceOf(
775  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
776  $object
777  );
778  $this->assertSame(
779  $first,
780  $object->argumentTestClass
781  );
782  $this->assertInstanceOf(
783  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
784  $object->argumentTestClassTwo
785  );
786  $this->assertNotSame(
787  $object->argumentTestClass,
788  $object->argumentTestClassTwo
789  );
790  }
791 
798  {
799  $second = new Fixtures\ArgumentTestClass();
800  $object = $this->container->getInstance(
801  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
802  [null, $second]
803  );
804  $this->assertInstanceOf(
805  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
806  $object
807  );
808  $this->assertSame(
809  $second,
810  $object->argumentTestClassTwo
811  );
812  }
813 
820  {
821  $object = $this->container->getInstance(
822  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
823  [null, null]
824  );
825  $this->assertInstanceOf(
826  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
827  $object
828  );
829  $this->assertInstanceOf(
830  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
831  $object->argumentTestClassTwo
832  );
833  }
834 
840  {
841  $first = new Fixtures\ArgumentTestClass();
842  $second = new Fixtures\ArgumentTestClass();
843  $object = $this->container->getInstance(
844  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
845  [$first, $second]
846  );
847  $this->assertInstanceOf(
848  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
849  $object
850  );
851  $this->assertSame(
852  $first,
853  $object->argumentTestClass
854  );
855  $this->assertSame(
856  $second,
857  $object->argumentTestClassTwo
858  );
859  }
860 
866  {
867  $object = $this->container->getInstance(
868  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
869  [null, null]
870  );
871  $this->assertInstanceOf(
872  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
873  $object
874  );
875  $this->assertNull($object->argumentTestClass);
876  $this->assertNull($object->argumentTestClassTwo);
877  }
878 
884  {
885  $object = $this->container->getInstance(
886  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class);
887  $this->assertInstanceOf(
888  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
889  $object
890  );
891  $this->assertNull($object->argumentTestClass);
892  $this->assertNull($object->argumentTestClassTwo);
893  }
894 
900  {
901  $first = new Fixtures\ArgumentTestClass();
902  $object = $this->container->getInstance(
903  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
904  [$first]
905  );
906  $this->assertInstanceOf(
907  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
908  $object
909  );
910  $this->assertSame(
911  $first,
912  $object->argumentTestClass
913  );
914  $this->assertNull($object->argumentTestClassTwo);
915  }
916 
922  {
923  $first = new Fixtures\ArgumentTestClass();
924  $object = $this->container->getInstance(
925  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
926  [$first, null]
927  );
928  $this->assertInstanceOf(
929  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
930  $object
931  );
932  $this->assertSame(
933  $first,
934  $object->argumentTestClass
935  );
936  $this->assertNull($object->argumentTestClassTwo);
937  }
938 
944  {
945  $second = new Fixtures\ArgumentTestClass();
946  $object = $this->container->getInstance(
947  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
948  [null, $second]
949  );
950  $this->assertInstanceOf(
951  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
952  $object
953  );
954  $this->assertNull($object->argumentTestClass);
955  $this->assertSame(
956  $second,
957  $object->argumentTestClassTwo
958  );
959  }
960 }
setClassInfoCacheCallback($id, \TYPO3\CMS\Extbase\Object\Container\ClassInfo $value)