TYPO3 CMS  TYPO3_8-7
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  */
18 
22 class ContainerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
27  protected $container;
28 
32  protected $cachedClassInfo;
33 
34  protected function setUp()
35  {
36  // The mocked cache will always indicate that he has nothing in the cache to force that we get the real class info
37  $mockedCache = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\Container\ClassInfoCache::class)
38  ->setMethods(['get', 'set', 'has'])
39  ->getMock();
40  $mockedCache->expects($this->any())->method('get')->will($this->returnValue(false));
41  $mockedCache->expects($this->never())->method('has');
42  $this->container = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\Container\Container::class)
43  ->setMethods(['log', 'getClassInfoCache'])
44  ->getMock();
45  $this->container->expects($this->any())->method('getClassInfoCache')->will($this->returnValue($mockedCache));
46  }
47 
52  {
53  $object = $this->container->getInstance('t3lib_object_tests_c');
54  $this->assertInstanceOf('t3lib_object_tests_c', $object);
55  }
56 
61  {
62  $object = $this->container->getInstance(\TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\NamespacedClass::class);
63  $this->assertInstanceOf(\TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\NamespacedClass::class, $object);
64  }
65 
70  {
71  $object = $this->container->getInstance('t3lib_object_tests_b');
72  $this->assertInstanceOf('t3lib_object_tests_b', $object);
73  $this->assertInstanceOf('t3lib_object_tests_c', $object->c);
74  }
75 
80  {
81  $object = $this->container->getInstance('t3lib_object_tests_a');
82  $this->assertInstanceOf('t3lib_object_tests_a', $object);
83  $this->assertInstanceOf('t3lib_object_tests_c', $object->b->c);
84  }
85 
90  {
91  $object = $this->container->getInstance('t3lib_object_tests_amixed_array');
92  $this->assertInstanceOf('t3lib_object_tests_amixed_array', $object);
93  $this->assertEquals(['some' => 'default'], $object->myvalue);
94  }
95 
100  {
101  $object = $this->container->getInstance('t3lib_object_tests_amixed_null');
102  $this->assertInstanceOf('t3lib_object_tests_amixed_null', $object);
103  $this->assertNull($object->myvalue);
104  }
105 
110  {
111  $this->expectException(Exception::class);
112  $this->expectExceptionCode(1292858051);
113  $this->container->getInstance('t3lib_object_tests_amixed_array_singleton', ['somevalue']);
114  }
115 
120  {
121  $object = $this->container->getInstance('t3lib_object_tests_amixed_array');
122  $this->assertInstanceOf('t3lib_object_tests_b', $object->b);
123  $this->assertInstanceOf('t3lib_object_tests_c', $object->c);
124  $this->assertEquals(['some' => 'default'], $object->myvalue);
125  }
126 
131  {
132  $mockObject = $this->createMock('t3lib_object_tests_c');
133  $object = $this->container->getInstance('t3lib_object_tests_a', [$mockObject]);
134  $this->assertInstanceOf('t3lib_object_tests_a', $object);
135  $this->assertSame($mockObject, $object->c);
136  }
137 
142  {
143  $object1 = $this->container->getInstance('t3lib_object_tests_a');
144  $object2 = $this->container->getInstance('t3lib_object_tests_a');
145  $this->assertNotSame($object1, $object2);
146  }
147 
152  {
153  $object1 = $this->container->getInstance('t3lib_object_tests_singleton');
154  $object2 = $this->container->getInstance('t3lib_object_tests_singleton');
155  $this->assertSame($object1, $object2);
156  }
157 
162  {
163  $this->expectException(CannotBuildObjectException::class);
164  $this->expectExceptionCode(1295611406);
165  $this->container->getInstance('t3lib_object_tests_cyclic1WithSetterDependency');
166  }
167 
172  {
173  $this->expectException(CannotBuildObjectException::class);
174  $this->expectExceptionCode(1295611406);
175  $this->container->getInstance('t3lib_object_tests_cyclic1');
176  }
177 
182  {
183  $this->expectException(Exception::class);
184  $this->expectExceptionCode(1289386765);
185  $this->container->getInstance('nonextistingclass_bla');
186  }
187 
192  {
193  $className = \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\NamespacedClass::class;
194  $classNameHash = md5($className);
195  $mockedCache = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\Container\ClassInfoCache::class)
196  ->setMethods(['has', 'set', 'get'])
197  ->getMock();
198  $container = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\Container\Container::class)
199  ->setMethods(['log', 'getClassInfoCache'])
200  ->getMock();
201  $container->expects($this->any())->method('getClassInfoCache')->will($this->returnValue($mockedCache));
202  $mockedCache->expects($this->never())->method('has');
203  $mockedCache->expects($this->once())->method('get')->with($classNameHash)->will($this->returnValue(false));
204  $mockedCache->expects($this->once())->method('set')->with($classNameHash, $this->anything())->will($this->returnCallback([$this, 'setClassInfoCacheCallback']));
205  $container->getInstance($className);
206  $this->assertInstanceOf(\TYPO3\CMS\Extbase\Object\Container\ClassInfo::class, $this->cachedClassInfo);
207  $this->assertEquals($className, $this->cachedClassInfo->getClassName());
208  }
209 
214  {
215  $instance = $this->container->getInstance('t3lib_object_tests_initializable');
216  $this->assertTrue($instance->isInitialized());
217  }
218 
225  public function setClassInfoCacheCallback($id, \TYPO3\CMS\Extbase\Object\Container\ClassInfo $value)
226  {
227  $this->cachedClassInfo = $value;
228  }
229 
234  {
235  $object = $this->container->getEmptyObject('t3lib_object_tests_c');
236  $this->assertInstanceOf('t3lib_object_tests_c', $object);
237  }
238 
243  {
244  $object = $this->container->getEmptyObject('t3lib_object_tests_serializable');
245  $this->assertInstanceOf('t3lib_object_tests_serializable', $object);
246  }
247 
252  {
253  $object = $this->container->getEmptyObject('t3lib_object_tests_initializable');
254  $this->assertTrue($object->isInitialized());
255  }
256 
260  public function test_canGetChildClass()
261  {
262  $object = $this->container->getInstance('t3lib_object_tests_b_child');
263  $this->assertInstanceOf('t3lib_object_tests_b_child', $object);
264  }
265 
270  {
271  $this->container->registerImplementation('t3lib_object_tests_someinterface', 't3lib_object_tests_someimplementation');
272  $object = $this->container->getInstance('t3lib_object_tests_needsinterface');
273  $this->assertInstanceOf('t3lib_object_tests_needsinterface', $object);
274  $this->assertInstanceOf('t3lib_object_tests_someinterface', $object->dependency);
275  $this->assertInstanceOf('t3lib_object_tests_someimplementation', $object->dependency);
276  }
277 
282  {
283  $object = $this->container->getInstance('t3lib_object_tests_resolveablecyclic1');
284  $this->assertInstanceOf('t3lib_object_tests_resolveablecyclic1', $object);
285  $this->assertInstanceOf('t3lib_object_tests_resolveablecyclic1', $object->o2->o3->o1);
286  }
287 
292  {
293  $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);
294  $object = $this->container->getInstance('t3lib_object_singletonNeedsPrototype');
295  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
296  }
297 
302  {
303  $this->container->expects($this->never())->method('log');
304  $object = $this->container->getInstance('t3lib_object_singletonNeedsSingleton');
305  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
306  }
307 
312  {
313  $this->container->expects($this->never())->method('log');
314  $object = $this->container->getInstance('t3lib_object_prototypeNeedsPrototype');
315  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
316  }
317 
322  {
323  $this->container->expects($this->never())->method('log');
324  $object = $this->container->getInstance('t3lib_object_prototypeNeedsSingleton');
325  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
326  }
327 
332  {
333  $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);
334  $object = $this->container->getInstance('t3lib_object_singletonNeedsPrototypeInConstructor');
335  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
336  }
337 
342  {
343  $this->container->expects($this->never())->method('log');
344  $object = $this->container->getInstance('t3lib_object_singletonNeedsSingletonInConstructor');
345  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
346  }
347 
352  {
353  $this->container->expects($this->never())->method('log');
354  $object = $this->container->getInstance('t3lib_object_prototypeNeedsPrototypeInConstructor');
355  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
356  }
357 
362  {
363  $this->container->expects($this->never())->method('log');
364  $object = $this->container->getInstance('t3lib_object_prototypeNeedsSingletonInConstructor');
365  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
366  }
367 
372  {
373  $this->assertTrue($this->container->isSingleton(\TYPO3\CMS\Extbase\Object\Container\Container::class));
374  $this->assertFalse($this->container->isSingleton(\TYPO3\CMS\Extbase\Core\Bootstrap::class));
375  }
376 
381  {
382  $this->assertFalse($this->container->isPrototype(\TYPO3\CMS\Extbase\Object\Container\Container::class));
383  $this->assertTrue($this->container->isPrototype(\TYPO3\CMS\Extbase\Core\Bootstrap::class));
384  }
385 
386  /************************************************
387  * Test regarding constructor argument injection
388  ************************************************/
389 
395  {
396  $object = $this->container->getInstance(
397  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\SimpleTypeConstructorArgument::class,
398  [true]
399  );
400  $this->assertTrue($object->foo);
401  }
402 
408  {
409  $object = $this->container->getInstance(
410  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\SimpleTypeConstructorArgument::class
411  );
412  $this->assertFalse($object->foo);
413  }
414 
420  {
421  $argumentTestClass = new Fixtures\ArgumentTestClass();
422  $object = $this->container->getInstance(
423  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgument::class,
424  [$argumentTestClass]
425  );
426  $this->assertInstanceOf(
427  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgument::class,
428  $object
429  );
430  $this->assertSame($argumentTestClass, $object->argumentTestClass);
431  }
432 
438  {
439  $object = $this->container->getInstance(
440  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgument::class
441  );
442  $this->assertInstanceOf(
443  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgument::class,
444  $object
445  );
446  $this->assertInstanceOf(
447  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
448  $object->argumentTestClass
449  );
450  }
451 
457  {
458  $object = $this->container->getInstance(
459  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class
460  );
461  $this->assertInstanceOf(
462  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class,
463  $object
464  );
465  $this->assertNull($object->argumentTestClass);
466  }
467 
473  {
474  $object = $this->container->getInstance(
475  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class,
476  [null]
477  );
478  $this->assertInstanceOf(
479  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class,
480  $object
481  );
482  $this->assertNull($object->argumentTestClass);
483  }
484 
490  {
491  $argumentTestClass = new Fixtures\ArgumentTestClass();
492  $object = $this->container->getInstance(
493  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class,
494  [$argumentTestClass]
495  );
496  $this->assertInstanceOf(
497  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\OptionalConstructorArgument::class,
498  $object
499  );
500  $this->assertSame($argumentTestClass, $object->argumentTestClass);
501  }
502 
508  {
509  $firstArgument = new Fixtures\ArgumentTestClass();
510  $secondArgument = new Fixtures\ArgumentTestClass();
511  $object = $this->container->getInstance(
512  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
513  [$firstArgument, $secondArgument]
514  );
515  $this->assertInstanceOf(
516  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
517  $object
518  );
519  $this->assertSame(
520  $firstArgument,
521  $object->argumentTestClass
522  );
523  $this->assertSame(
524  $secondArgument,
525  $object->argumentTestClassTwo
526  );
527  }
528 
534  {
535  $object = $this->container->getInstance(
536  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class
537  );
538  $this->assertInstanceOf(
539  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
540  $object
541  );
542  $this->assertInstanceOf(
543  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
544  $object->argumentTestClass
545  );
546  $this->assertInstanceOf(
547  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
548  $object->argumentTestClassTwo
549  );
550  $this->assertNotSame(
551  $object->argumentTestClass,
552  $object->argumentTestClassTwo
553  );
554  }
555 
561  {
562  $firstArgument = new Fixtures\ArgumentTestClass();
563  $object = $this->container->getInstance(
564  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
565  [$firstArgument]
566  );
567  $this->assertInstanceOf(
568  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
569  $object
570  );
571  $this->assertSame(
572  $firstArgument,
573  $object->argumentTestClass
574  );
575  $this->assertInstanceOf(
576  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
577  $object->argumentTestClassTwo
578  );
579  $this->assertNotSame(
580  $object->argumentTestClass,
581  $object->argumentTestClassTwo
582  );
583  }
584 
590  {
591  $secondArgument = new Fixtures\ArgumentTestClass();
592  $object = $this->container->getInstance(
593  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
594  [null, $secondArgument]
595  );
596  $this->assertInstanceOf(
597  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\MandatoryConstructorArgumentTwo::class,
598  $object
599  );
600  $this->assertInstanceOf(
601  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
602  $object->argumentTestClass
603  );
604  $this->assertInstanceOf(
605  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
606  $object->argumentTestClassTwo
607  );
608  $this->assertSame(
609  $secondArgument,
610  $object->argumentTestClassTwo
611  );
612  $this->assertNotSame(
613  $object->argumentTestClass,
614  $object->argumentTestClassTwo
615  );
616  }
617 
623  {
624  $firstArgument = new Fixtures\ArgumentTestClass();
625  $secondArgument = new Fixtures\ArgumentTestClass();
626  $object = $this->container->getInstance(
627  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
628  [$firstArgument, $secondArgument]
629  );
630  $this->assertInstanceOf(
631  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
632  $object
633  );
634  $this->assertSame(
635  $firstArgument,
636  $object->argumentTestClass
637  );
638  $this->assertSame(
639  $secondArgument,
640  $object->argumentTestClassTwo
641  );
642  }
643 
649  {
650  $object = $this->container->getInstance(
651  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class
652  );
653  $this->assertInstanceOf(
654  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
655  $object
656  );
657  $this->assertInstanceOf(
658  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
659  $object->argumentTestClass
660  );
661  $this->assertNull($object->argumentTestClassTwo);
662  }
663 
669  {
670  $object = $this->container->getInstance(
671  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
672  [null, null]
673  );
674  $this->assertInstanceOf(
675  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
676  $object
677  );
678  $this->assertInstanceOf(
679  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
680  $object->argumentTestClass
681  );
682  $this->assertNull($object->argumentTestClassTwo);
683  }
684 
690  {
691  $firstArgument = new Fixtures\ArgumentTestClass();
692  $object = $this->container->getInstance(
693  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
694  [$firstArgument]
695  );
696  $this->assertInstanceOf(
697  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
698  $object
699  );
700  $this->assertSame(
701  $firstArgument,
702  $object->argumentTestClass
703  );
704  $this->assertNull($object->argumentTestClassTwo);
705  }
706 
712  {
713  $firstArgument = new Fixtures\ArgumentTestClass();
714  $object = $this->container->getInstance(
715  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
716  [$firstArgument, null]
717  );
718  $this->assertInstanceOf(
719  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
720  $object
721  );
722  $this->assertSame(
723  $firstArgument,
724  $object->argumentTestClass
725  );
726  $this->assertNull($object->argumentTestClassTwo);
727  }
728 
735  {
736  $object = $this->container->getInstance(
737  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
738  [null]
739  );
740  $this->assertInstanceOf(
741  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
742  $object
743  );
744  $this->assertInstanceOf(
745  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
746  $object->argumentTestClassTwo
747  );
748  }
749 
755  {
756  $first = new Fixtures\ArgumentTestClass();
757  $second = new Fixtures\ArgumentTestClass();
758  $object = $this->container->getInstance(
759  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
760  [$first, $second]
761  );
762  $this->assertInstanceOf(
763  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
764  $object
765  );
766  $this->assertSame(
767  $first,
768  $object->argumentTestClass
769  );
770  $this->assertSame(
771  $second,
772  $object->argumentTestClassTwo
773  );
774  }
775 
781  {
782  $first = new Fixtures\ArgumentTestClass();
783  $object = $this->container->getInstance(
784  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
785  [$first]
786  );
787  $this->assertInstanceOf(
788  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
789  $object
790  );
791  $this->assertSame(
792  $first,
793  $object->argumentTestClass
794  );
795  $this->assertInstanceOf(
796  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
797  $object->argumentTestClassTwo
798  );
799  $this->assertNotSame(
800  $object->argumentTestClass,
801  $object->argumentTestClassTwo
802  );
803  }
804 
811  {
812  $second = new Fixtures\ArgumentTestClass();
813  $object = $this->container->getInstance(
814  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
815  [null, $second]
816  );
817  $this->assertInstanceOf(
818  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
819  $object
820  );
821  $this->assertSame(
822  $second,
823  $object->argumentTestClassTwo
824  );
825  }
826 
833  {
834  $object = $this->container->getInstance(
835  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
836  [null, null]
837  );
838  $this->assertInstanceOf(
839  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
840  $object
841  );
842  $this->assertInstanceOf(
843  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass::class,
844  $object->argumentTestClassTwo
845  );
846  }
847 
853  {
854  $first = new Fixtures\ArgumentTestClass();
855  $second = new Fixtures\ArgumentTestClass();
856  $object = $this->container->getInstance(
857  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
858  [$first, $second]
859  );
860  $this->assertInstanceOf(
861  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
862  $object
863  );
864  $this->assertSame(
865  $first,
866  $object->argumentTestClass
867  );
868  $this->assertSame(
869  $second,
870  $object->argumentTestClassTwo
871  );
872  }
873 
879  {
880  $object = $this->container->getInstance(
881  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
882  [null, null]
883  );
884  $this->assertInstanceOf(
885  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
886  $object
887  );
888  $this->assertNull($object->argumentTestClass);
889  $this->assertNull($object->argumentTestClassTwo);
890  }
891 
897  {
898  $object = $this->container->getInstance(
899  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class
900  );
901  $this->assertInstanceOf(
902  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
903  $object
904  );
905  $this->assertNull($object->argumentTestClass);
906  $this->assertNull($object->argumentTestClassTwo);
907  }
908 
914  {
915  $first = new Fixtures\ArgumentTestClass();
916  $object = $this->container->getInstance(
917  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
918  [$first]
919  );
920  $this->assertInstanceOf(
921  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
922  $object
923  );
924  $this->assertSame(
925  $first,
926  $object->argumentTestClass
927  );
928  $this->assertNull($object->argumentTestClassTwo);
929  }
930 
936  {
937  $first = new Fixtures\ArgumentTestClass();
938  $object = $this->container->getInstance(
939  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
940  [$first, null]
941  );
942  $this->assertInstanceOf(
943  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
944  $object
945  );
946  $this->assertSame(
947  $first,
948  $object->argumentTestClass
949  );
950  $this->assertNull($object->argumentTestClassTwo);
951  }
952 
958  {
959  $second = new Fixtures\ArgumentTestClass();
960  $object = $this->container->getInstance(
961  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
962  [null, $second]
963  );
964  $this->assertInstanceOf(
965  \TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
966  $object
967  );
968  $this->assertNull($object->argumentTestClass);
969  $this->assertSame(
970  $second,
971  $object->argumentTestClassTwo
972  );
973  }
974 }
setClassInfoCacheCallback($id, \TYPO3\CMS\Extbase\Object\Container\ClassInfo $value)