‪TYPO3CMS  9.5
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 use Psr\Log\LoggerInterface;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪ContainerTest extends UnitTestCase
31 {
35  protected ‪$resetSingletonInstances = true;
36 
40  protected ‪$subject;
41 
45  protected ‪$logger;
46 
47  protected function ‪setUp()
48  {
49  $this->logger = $this->getMockBuilder(Logger::class)
50  ->setMethods(['notice'])
51  ->disableOriginalConstructor()
52  ->getMock();
53 
54  $this->subject = $this->getMockBuilder(Container::class)
55  ->setMethods(['getLogger'])
56  ->getMock();
57  $this->subject->expects($this->any())->method('getLogger')->will($this->returnValue($this->logger));
58  }
59 
64  {
65  $object = $this->subject->getInstance('t3lib_object_tests_c');
66  $this->assertInstanceOf('t3lib_object_tests_c', $object);
67  }
68 
73  {
74  $object = $this->subject->getInstance(\‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\NamespacedClass::class);
75  $this->assertInstanceOf(\‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\NamespacedClass::class, $object);
76  }
77 
82  {
83  $object = $this->subject->getInstance('t3lib_object_tests_b');
84  $this->assertInstanceOf('t3lib_object_tests_b', $object);
85  $this->assertInstanceOf('t3lib_object_tests_c', $object->c);
86  }
87 
92  {
93  $object = $this->subject->getInstance('t3lib_object_tests_a');
94  $this->assertInstanceOf('t3lib_object_tests_a', $object);
95  $this->assertInstanceOf('t3lib_object_tests_c', $object->b->c);
96  }
97 
102  {
103  $object = $this->subject->getInstance('t3lib_object_tests_amixed_array');
104  $this->assertInstanceOf('t3lib_object_tests_amixed_array', $object);
105  $this->assertEquals(['some' => 'default'], $object->myvalue);
106  }
107 
112  {
113  $object = $this->subject->getInstance('t3lib_object_tests_amixed_null');
114  $this->assertInstanceOf('t3lib_object_tests_amixed_null', $object);
115  $this->assertNull($object->myvalue);
116  }
117 
122  {
123  $this->expectException(Exception::class);
124  $this->expectExceptionCode(1292858051);
125  $this->subject->getInstance('t3lib_object_tests_amixed_array_singleton', ['somevalue']);
126  }
127 
132  {
133  $object = $this->subject->getInstance('t3lib_object_tests_amixed_array');
134  $this->assertInstanceOf('t3lib_object_tests_b', $object->b);
135  $this->assertInstanceOf('t3lib_object_tests_c', $object->c);
136  $this->assertEquals(['some' => 'default'], $object->myvalue);
137  }
138 
143  {
144  $mockObject = $this->createMock('t3lib_object_tests_c');
145  $object = $this->subject->getInstance('t3lib_object_tests_a', [$mockObject]);
146  $this->assertInstanceOf('t3lib_object_tests_a', $object);
147  $this->assertSame($mockObject, $object->c);
148  }
149 
154  {
155  $object1 = $this->subject->getInstance('t3lib_object_tests_a');
156  $object2 = $this->subject->getInstance('t3lib_object_tests_a');
157  $this->assertNotSame($object1, $object2);
158  }
159 
164  {
165  $object1 = $this->subject->getInstance('t3lib_object_tests_singleton');
166  $object2 = $this->subject->getInstance('t3lib_object_tests_singleton');
167  $this->assertSame($object1, $object2);
168  }
169 
174  {
175  $this->expectException(CannotBuildObjectException::class);
176  $this->expectExceptionCode(1295611406);
177  $this->subject->getInstance('t3lib_object_tests_cyclic1WithSetterDependency');
178  }
179 
184  {
185  $this->expectException(CannotBuildObjectException::class);
186  $this->expectExceptionCode(1295611406);
187  $this->subject->getInstance('t3lib_object_tests_cyclic1');
188  }
189 
194  {
195  $this->expectException(UnknownClassException::class);
196  $this->expectExceptionCode(1278450972);
197  $this->subject->getInstance('nonextistingclass_bla');
198  }
199 
203  public function ‪getInstanceInitializesObjects()
204  {
205  $instance = $this->subject->getInstance('t3lib_object_tests_initializable');
206  $this->assertTrue($instance->isInitialized());
207  }
208 
213  {
214  $object = $this->subject->getEmptyObject('t3lib_object_tests_c');
215  $this->assertInstanceOf('t3lib_object_tests_c', $object);
216  }
217 
222  {
223  $object = $this->subject->getEmptyObject('t3lib_object_tests_serializable');
224  $this->assertInstanceOf('t3lib_object_tests_serializable', $object);
225  }
226 
230  public function ‪getEmptyObjectInitializesObjects()
231  {
232  $object = $this->subject->getEmptyObject('t3lib_object_tests_initializable');
233  $this->assertTrue($object->isInitialized());
234  }
235 
239  public function ‪test_canGetChildClass()
240  {
241  $object = $this->subject->getInstance('t3lib_object_tests_b_child');
242  $this->assertInstanceOf('t3lib_object_tests_b_child', $object);
243  }
244 
248  public function ‪test_canInjectInterfaceInClass()
249  {
250  $this->subject->registerImplementation('t3lib_object_tests_someinterface', 't3lib_object_tests_someimplementation');
251  $object = $this->subject->getInstance('t3lib_object_tests_needsinterface');
252  $this->assertInstanceOf('t3lib_object_tests_needsinterface', $object);
253  $this->assertInstanceOf('t3lib_object_tests_someinterface', $object->dependency);
254  $this->assertInstanceOf('t3lib_object_tests_someimplementation', $object->dependency);
255  }
256 
261  {
262  $object = $this->subject->getInstance('t3lib_object_tests_resolveablecyclic1');
263  $this->assertInstanceOf('t3lib_object_tests_resolveablecyclic1', $object);
264  $this->assertInstanceOf('t3lib_object_tests_resolveablecyclic1', $object->o2->o3->o1);
265  }
266 
271  {
272  $this->logger->expects($this->once())->method('notice')->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.');
273  $object = $this->subject->getInstance('t3lib_object_singletonNeedsPrototype');
274  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
275  }
276 
281  {
282  $this->logger->expects($this->never())->method('notice');
283  $object = $this->subject->getInstance('t3lib_object_singletonNeedsSingleton');
284  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
285  }
286 
291  {
292  $this->logger->expects($this->never())->method('notice');
293  $object = $this->subject->getInstance('t3lib_object_prototypeNeedsPrototype');
294  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
295  }
296 
301  {
302  $this->logger->expects($this->never())->method('notice');
303  $object = $this->subject->getInstance('t3lib_object_prototypeNeedsSingleton');
304  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
305  }
306 
311  {
312  $this->logger->expects($this->once())->method('notice')->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.');
313  $object = $this->subject->getInstance('t3lib_object_singletonNeedsPrototypeInConstructor');
314  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
315  }
316 
321  {
322  $this->logger->expects($this->never())->method('notice');
323  $object = $this->subject->getInstance('t3lib_object_singletonNeedsSingletonInConstructor');
324  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
325  }
326 
331  {
332  $this->logger->expects($this->never())->method('notice');
333  $object = $this->subject->getInstance('t3lib_object_prototypeNeedsPrototypeInConstructor');
334  $this->assertInstanceOf('t3lib_object_prototype', $object->dependency);
335  }
336 
341  {
342  $this->logger->expects($this->never())->method('notice');
343  $object = $this->subject->getInstance('t3lib_object_prototypeNeedsSingletonInConstructor');
344  $this->assertInstanceOf('t3lib_object_singleton', $object->dependency);
345  }
346 
351  {
352  $this->assertTrue($this->subject->isSingleton(Container::class));
353  $this->assertFalse($this->subject->isSingleton(\‪TYPO3\CMS\‪Extbase\Core\Bootstrap::class));
354  }
355 
360  {
361  $this->assertFalse($this->subject->isPrototype(Container::class));
362  $this->assertTrue($this->subject->isPrototype(\‪TYPO3\CMS\‪Extbase\Core\Bootstrap::class));
363  }
364 
365  /************************************************
366  * Test regarding constructor argument injection
367  ************************************************/
368 
374  {
375  $object = $this->subject->getInstance(
376  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\SimpleTypeConstructorArgument::class,
377  [true]
378  );
379  $this->assertTrue($object->foo);
380  }
381 
387  {
388  $object = $this->subject->getInstance(
389  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\SimpleTypeConstructorArgument::class
390  );
391  $this->assertFalse($object->foo);
392  }
393 
399  {
400  $argumentTestClass = new ‪Fixtures\ArgumentTestClass();
401  $object = $this->subject->getInstance(
402  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgument::class,
403  [$argumentTestClass]
404  );
405  $this->assertInstanceOf(
406  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgument::class,
407  $object
408  );
409  $this->assertSame($argumentTestClass, $object->argumentTestClass);
410  }
411 
417  {
418  $object = $this->subject->getInstance(
419  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgument::class
420  );
421  $this->assertInstanceOf(
422  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgument::class,
423  $object
424  );
425  $this->assertInstanceOf(
426  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\ArgumentTestClass::class,
427  $object->argumentTestClass
428  );
429  }
430 
436  {
437  $object = $this->subject->getInstance(
438  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\OptionalConstructorArgument::class
439  );
440  $this->assertInstanceOf(
441  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\OptionalConstructorArgument::class,
442  $object
443  );
444  $this->assertNull($object->argumentTestClass);
445  }
446 
452  {
453  $object = $this->subject->getInstance(
454  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\OptionalConstructorArgument::class,
455  [null]
456  );
457  $this->assertInstanceOf(
458  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\OptionalConstructorArgument::class,
459  $object
460  );
461  $this->assertNull($object->argumentTestClass);
462  }
463 
469  {
470  $argumentTestClass = new ‪Fixtures\ArgumentTestClass();
471  $object = $this->subject->getInstance(
472  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\OptionalConstructorArgument::class,
473  [$argumentTestClass]
474  );
475  $this->assertInstanceOf(
476  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\OptionalConstructorArgument::class,
477  $object
478  );
479  $this->assertSame($argumentTestClass, $object->argumentTestClass);
480  }
481 
487  {
488  $firstArgument = new ‪Fixtures\ArgumentTestClass();
489  $secondArgument = new ‪Fixtures\ArgumentTestClass();
490  $object = $this->subject->getInstance(
491  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgumentTwo::class,
492  [$firstArgument, $secondArgument]
493  );
494  $this->assertInstanceOf(
495  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgumentTwo::class,
496  $object
497  );
498  $this->assertSame(
499  $firstArgument,
500  $object->argumentTestClass
501  );
502  $this->assertSame(
503  $secondArgument,
504  $object->argumentTestClassTwo
505  );
506  }
507 
513  {
514  $object = $this->subject->getInstance(
515  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgumentTwo::class
516  );
517  $this->assertInstanceOf(
518  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgumentTwo::class,
519  $object
520  );
521  $this->assertInstanceOf(
522  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\ArgumentTestClass::class,
523  $object->argumentTestClass
524  );
525  $this->assertInstanceOf(
526  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\ArgumentTestClass::class,
527  $object->argumentTestClassTwo
528  );
529  $this->assertNotSame(
530  $object->argumentTestClass,
531  $object->argumentTestClassTwo
532  );
533  }
534 
540  {
541  $firstArgument = new ‪Fixtures\ArgumentTestClass();
542  $object = $this->subject->getInstance(
543  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgumentTwo::class,
544  [$firstArgument]
545  );
546  $this->assertInstanceOf(
547  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgumentTwo::class,
548  $object
549  );
550  $this->assertSame(
551  $firstArgument,
552  $object->argumentTestClass
553  );
554  $this->assertInstanceOf(
555  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\ArgumentTestClass::class,
556  $object->argumentTestClassTwo
557  );
558  $this->assertNotSame(
559  $object->argumentTestClass,
560  $object->argumentTestClassTwo
561  );
562  }
563 
569  {
570  $secondArgument = new ‪Fixtures\ArgumentTestClass();
571  $object = $this->subject->getInstance(
572  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgumentTwo::class,
573  [null, $secondArgument]
574  );
575  $this->assertInstanceOf(
576  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\MandatoryConstructorArgumentTwo::class,
577  $object
578  );
579  $this->assertInstanceOf(
580  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\ArgumentTestClass::class,
581  $object->argumentTestClass
582  );
583  $this->assertInstanceOf(
584  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\ArgumentTestClass::class,
585  $object->argumentTestClassTwo
586  );
587  $this->assertSame(
588  $secondArgument,
589  $object->argumentTestClassTwo
590  );
591  $this->assertNotSame(
592  $object->argumentTestClass,
593  $object->argumentTestClassTwo
594  );
595  }
596 
602  {
603  $firstArgument = new ‪Fixtures\ArgumentTestClass();
604  $secondArgument = new ‪Fixtures\ArgumentTestClass();
605  $object = $this->subject->getInstance(
606  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
607  [$firstArgument, $secondArgument]
608  );
609  $this->assertInstanceOf(
610  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
611  $object
612  );
613  $this->assertSame(
614  $firstArgument,
615  $object->argumentTestClass
616  );
617  $this->assertSame(
618  $secondArgument,
619  $object->argumentTestClassTwo
620  );
621  }
622 
628  {
629  $object = $this->subject->getInstance(
630  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsSecondOptional::class
631  );
632  $this->assertInstanceOf(
633  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
634  $object
635  );
636  $this->assertInstanceOf(
637  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\ArgumentTestClass::class,
638  $object->argumentTestClass
639  );
640  $this->assertNull($object->argumentTestClassTwo);
641  }
642 
648  {
649  $object = $this->subject->getInstance(
650  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
651  [null, null]
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  $firstArgument = new ‪Fixtures\ArgumentTestClass();
671  $object = $this->subject->getInstance(
672  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
673  [$firstArgument]
674  );
675  $this->assertInstanceOf(
676  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
677  $object
678  );
679  $this->assertSame(
680  $firstArgument,
681  $object->argumentTestClass
682  );
683  $this->assertNull($object->argumentTestClassTwo);
684  }
685 
691  {
692  $firstArgument = new ‪Fixtures\ArgumentTestClass();
693  $object = $this->subject->getInstance(
694  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
695  [$firstArgument, null]
696  );
697  $this->assertInstanceOf(
698  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsSecondOptional::class,
699  $object
700  );
701  $this->assertSame(
702  $firstArgument,
703  $object->argumentTestClass
704  );
705  $this->assertNull($object->argumentTestClassTwo);
706  }
707 
714  {
715  $object = $this->subject->getInstance(
716  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
717  [null]
718  );
719  $this->assertInstanceOf(
720  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
721  $object
722  );
723  $this->assertInstanceOf(
724  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\ArgumentTestClass::class,
725  $object->argumentTestClassTwo
726  );
727  }
728 
734  {
735  $first = new ‪Fixtures\ArgumentTestClass();
736  $second = new ‪Fixtures\ArgumentTestClass();
737  $object = $this->subject->getInstance(
738  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
739  [$first, $second]
740  );
741  $this->assertInstanceOf(
742  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
743  $object
744  );
745  $this->assertSame(
746  $first,
747  $object->argumentTestClass
748  );
749  $this->assertSame(
750  $second,
751  $object->argumentTestClassTwo
752  );
753  }
754 
760  {
761  $first = new ‪Fixtures\ArgumentTestClass();
762  $object = $this->subject->getInstance(
763  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
764  [$first]
765  );
766  $this->assertInstanceOf(
767  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
768  $object
769  );
770  $this->assertSame(
771  $first,
772  $object->argumentTestClass
773  );
774  $this->assertInstanceOf(
775  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\ArgumentTestClass::class,
776  $object->argumentTestClassTwo
777  );
778  $this->assertNotSame(
779  $object->argumentTestClass,
780  $object->argumentTestClassTwo
781  );
782  }
783 
790  {
791  $second = new ‪Fixtures\ArgumentTestClass();
792  $object = $this->subject->getInstance(
793  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
794  [null, $second]
795  );
796  $this->assertInstanceOf(
797  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
798  $object
799  );
800  $this->assertSame(
801  $second,
802  $object->argumentTestClassTwo
803  );
804  }
805 
812  {
813  $object = $this->subject->getInstance(
814  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
815  [null, null]
816  );
817  $this->assertInstanceOf(
818  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsFirstOptional::class,
819  $object
820  );
821  $this->assertInstanceOf(
822  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\ArgumentTestClass::class,
823  $object->argumentTestClassTwo
824  );
825  }
826 
832  {
833  $first = new ‪Fixtures\ArgumentTestClass();
834  $second = new ‪Fixtures\ArgumentTestClass();
835  $object = $this->subject->getInstance(
836  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
837  [$first, $second]
838  );
839  $this->assertInstanceOf(
840  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
841  $object
842  );
843  $this->assertSame(
844  $first,
845  $object->argumentTestClass
846  );
847  $this->assertSame(
848  $second,
849  $object->argumentTestClassTwo
850  );
851  }
852 
858  {
859  $object = $this->subject->getInstance(
860  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
861  [null, null]
862  );
863  $this->assertInstanceOf(
864  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
865  $object
866  );
867  $this->assertNull($object->argumentTestClass);
868  $this->assertNull($object->argumentTestClassTwo);
869  }
870 
876  {
877  $object = $this->subject->getInstance(
878  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class
879  );
880  $this->assertInstanceOf(
881  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
882  $object
883  );
884  $this->assertNull($object->argumentTestClass);
885  $this->assertNull($object->argumentTestClassTwo);
886  }
887 
893  {
894  $first = new ‪Fixtures\ArgumentTestClass();
895  $object = $this->subject->getInstance(
896  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
897  [$first]
898  );
899  $this->assertInstanceOf(
900  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
901  $object
902  );
903  $this->assertSame(
904  $first,
905  $object->argumentTestClass
906  );
907  $this->assertNull($object->argumentTestClassTwo);
908  }
909 
915  {
916  $first = new ‪Fixtures\ArgumentTestClass();
917  $object = $this->subject->getInstance(
918  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
919  [$first, null]
920  );
921  $this->assertInstanceOf(
922  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
923  $object
924  );
925  $this->assertSame(
926  $first,
927  $object->argumentTestClass
928  );
929  $this->assertNull($object->argumentTestClassTwo);
930  }
931 
937  {
938  $second = new ‪Fixtures\ArgumentTestClass();
939  $object = $this->subject->getInstance(
940  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
941  [null, $second]
942  );
943  $this->assertInstanceOf(
944  \‪TYPO3\CMS\‪Extbase\Tests\Unit\Object\‪Container\Fixtures\TwoConstructorArgumentsBothOptional::class,
945  $object
946  );
947  $this->assertNull($object->argumentTestClass);
948  $this->assertSame(
949  $second,
950  $object->argumentTestClassTwo
951  );
952  }
953 
957  public function ‪getInstanceInjectsPublicProperties()
958  {
959  $container = new ‪Container();
960  $object = $container->getInstance(PublicPropertyInjectClass::class);
961  self::assertInstanceOf(ArgumentTestClassForPublicPropertyInjection::class, $object->foo);
962  }
963 
968  {
969  $container = new ‪Container();
970  $object = $container->getInstance(ProtectedPropertyInjectClass::class);
971  self::assertInstanceOf(ArgumentTestClassForPublicPropertyInjection::class, $object->getFoo());
972  }
973 }
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceOnTwoOptionalGivesNoArgumentsToConstructorIfArgumentsAreNull
‪getInstanceOnTwoOptionalGivesNoArgumentsToConstructorIfArgumentsAreNull()
Definition: ContainerTest.php:854
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\singletonWhichRequiresSingletonViaConstructorInjectionWorks
‪singletonWhichRequiresSingletonViaConstructorInjectionWorks()
Definition: ContainerTest.php:317
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\$logger
‪LoggerInterface PHPUnit_Framework_MockObject_MockObject $logger
Definition: ContainerTest.php:42
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceOnFirstOptionalAndSecondMandatoryInjectsSecondArgumentIfFirstIsGivenAsNull
‪getInstanceOnFirstOptionalAndSecondMandatoryInjectsSecondArgumentIfFirstIsGivenAsNull()
Definition: ContainerTest.php:710
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceGivesExistingConstructorArgumentToClassInstance
‪getInstanceGivesExistingConstructorArgumentToClassInstance()
Definition: ContainerTest.php:395
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ProtectedPropertyInjectClass
Definition: ContainerPropertyInjectionTestClasses.php:21
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\prototypeWhichRequiresPrototypeViaConstructorInjectionWorks
‪prototypeWhichRequiresPrototypeViaConstructorInjectionWorks()
Definition: ContainerTest.php:327
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceDoesNotInfluenceSimpleTypeConstructorArgumentIfNotGiven
‪getInstanceDoesNotInfluenceSimpleTypeConstructorArgumentIfNotGiven()
Definition: ContainerTest.php:383
‪TYPO3\CMS\Extbase\Object\Container\Container
Definition: Container.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceInjectsSecondMandatoryArgumentIfFirstIsGiven
‪getInstanceInjectsSecondMandatoryArgumentIfFirstIsGiven()
Definition: ContainerTest.php:536
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceThrowsExceptionWhenTryingToInstanciateASingletonWithConstructorParameters
‪getInstanceThrowsExceptionWhenTryingToInstanciateASingletonWithConstructorParameters()
Definition: ContainerTest.php:118
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceOnTwoOptionalGivesNoArgumentsToConstructorIfNoneAreGiven
‪getInstanceOnTwoOptionalGivesNoArgumentsToConstructorIfNoneAreGiven()
Definition: ContainerTest.php:872
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceReturnsAFreshInstanceIfObjectIsNoSingleton
‪getInstanceReturnsAFreshInstanceIfObjectIsNoSingleton()
Definition: ContainerTest.php:150
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container
Definition: ContainerTest.php:2
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceInjectsTwoMandatoryArguments
‪getInstanceInjectsTwoMandatoryArguments()
Definition: ContainerTest.php:509
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceOnTwoOptionalGivesOneArgumentToConstructorIfFirstIsNullAndSecondIsObject
‪getInstanceOnTwoOptionalGivesOneArgumentToConstructorIfFirstIsNullAndSecondIsObject()
Definition: ContainerTest.php:933
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceOnFirstOptionalAndSecondMandatoryGivesSecondArgumentAsIsIfFirstIsGivenAsNullAndSecondIsGiven
‪getInstanceOnFirstOptionalAndSecondMandatoryGivesSecondArgumentAsIsIfFirstIsGivenAsNullAndSecondIsGiven()
Definition: ContainerTest.php:786
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceThrowsExceptionIfClassWasNotFound
‪getInstanceThrowsExceptionIfClassWasNotFound()
Definition: ContainerTest.php:190
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\isPrototypeReturnsFalseForSingletonInstancesAndTrueForPrototypes
‪isPrototypeReturnsFalseForSingletonInstancesAndTrueForPrototypes()
Definition: ContainerTest.php:356
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceOnTwoOptionalGivesOneArgumentToConstructorIfFirstIsObjectAndSecondIsNull
‪getInstanceOnTwoOptionalGivesOneArgumentToConstructorIfFirstIsObjectAndSecondIsNull()
Definition: ContainerTest.php:911
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceDoesNotInjectAnOptionalArgumentIfGivenArgumentIsNull
‪getInstanceDoesNotInjectAnOptionalArgumentIfGivenArgumentIsNull()
Definition: ContainerTest.php:448
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\$subject
‪Container $subject
Definition: ContainerTest.php:38
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstancePassesGivenParameterToTheNewObject
‪getInstancePassesGivenParameterToTheNewObject()
Definition: ContainerTest.php:139
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceReturnsInstanceOfAClassWithConstructorInjectionAndDefaultConstructorParameters
‪getInstanceReturnsInstanceOfAClassWithConstructorInjectionAndDefaultConstructorParameters()
Definition: ContainerTest.php:128
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceInjectsPublicProperties
‪getInstanceInjectsPublicProperties()
Definition: ContainerTest.php:954
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceGivesTwoArgumentsToClassConstructorIfSecondIsOptional
‪getInstanceGivesTwoArgumentsToClassConstructorIfSecondIsOptional()
Definition: ContainerTest.php:598
‪TYPO3\CMS\Extbase\Object\Exception\CannotBuildObjectException
Definition: CannotBuildObjectException.php:21
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceOnFirstOptionalAndSecondMandatoryInjectsSecondArgumentIfFirstIsGiven
‪getInstanceOnFirstOptionalAndSecondMandatoryInjectsSecondArgumentIfFirstIsGiven()
Definition: ContainerTest.php:756
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceDoesNotInjectAnOptionalArgumentIfNotGiven
‪getInstanceDoesNotInjectAnOptionalArgumentIfNotGiven()
Definition: ContainerTest.php:432
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceInitializesObjects
‪getInstanceInitializesObjects()
Definition: ContainerTest.php:200
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\test_canInjectInterfaceInClass
‪test_canInjectInterfaceInClass()
Definition: ContainerTest.php:245
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\singletonWhichRequiresPrototypeViaSetterInjectionWorksAndAddsDebugMessage
‪singletonWhichRequiresPrototypeViaSetterInjectionWorksAndAddsDebugMessage()
Definition: ContainerTest.php:267
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceGivesFirstArgumentToConstructorIfSecondIsOptionalFirstIsGivenAndSecondIsGivenNull
‪getInstanceGivesFirstArgumentToConstructorIfSecondIsOptionalFirstIsGivenAndSecondIsGivenNull()
Definition: ContainerTest.php:687
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceThrowsExceptionIfPrototypeObjectsWiredViaSetterInjectionContainCyclicDependencies
‪getInstanceThrowsExceptionIfPrototypeObjectsWiredViaSetterInjectionContainCyclicDependencies()
Definition: ContainerTest.php:180
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceOnTwoOptionalGivesTwoGivenArgumentsToConstructor
‪getInstanceOnTwoOptionalGivesTwoGivenArgumentsToConstructor()
Definition: ContainerTest.php:828
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceThrowsExceptionIfPrototypeObjectsWiredViaConstructorInjectionContainCyclicDependencies
‪getInstanceThrowsExceptionIfPrototypeObjectsWiredViaConstructorInjectionContainCyclicDependencies()
Definition: ContainerTest.php:170
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceReturnsInstanceOfAClassWithMixedSimpleTypeAndConstructorInjectionWithNullDefaultValue
‪getInstanceReturnsInstanceOfAClassWithMixedSimpleTypeAndConstructorInjectionWithNullDefaultValue()
Definition: ContainerTest.php:108
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceReturnsInstanceOfAClassWithMixedSimpleTypeAndConstructorInjection
‪getInstanceReturnsInstanceOfAClassWithMixedSimpleTypeAndConstructorInjection()
Definition: ContainerTest.php:98
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceOnFirstOptionalAndSecondMandatoryInjectsSecondArgumentIfFirstIsGivenAsNullAndSecondIsNull
‪getInstanceOnFirstOptionalAndSecondMandatoryInjectsSecondArgumentIfFirstIsGivenAsNullAndSecondIsNull()
Definition: ContainerTest.php:808
‪TYPO3\CMS\Extbase\Reflection\Exception\UnknownClassException
Definition: UnknownClassException.php:21
‪TYPO3\CMS\Extbase\Object\Exception
Definition: CannotBuildObjectException.php:2
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceInjectsFirstMandatoryArgumentIfSecondIsOptionalAndNoneAreGiven
‪getInstanceInjectsFirstMandatoryArgumentIfSecondIsOptionalAndNoneAreGiven()
Definition: ContainerTest.php:624
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getEmptyObjectReturnsInstanceOfClassImplementingSerializable
‪getEmptyObjectReturnsInstanceOfClassImplementingSerializable()
Definition: ContainerTest.php:218
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\singletonWhichRequiresPrototypeViaConstructorInjectionWorksAndAddsDebugMessage
‪singletonWhichRequiresPrototypeViaConstructorInjectionWorksAndAddsDebugMessage()
Definition: ContainerTest.php:307
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceReturnsSameInstanceInstanceIfObjectIsSingleton
‪getInstanceReturnsSameInstanceInstanceIfObjectIsSingleton()
Definition: ContainerTest.php:160
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\PublicPropertyInjectClass
Definition: ContainerPropertyInjectionTestClasses.php:9
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\setUp
‪setUp()
Definition: ContainerTest.php:44
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getEmptyObjectReturnsInstanceOfSimpleClass
‪getEmptyObjectReturnsInstanceOfSimpleClass()
Definition: ContainerTest.php:209
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\test_canGetChildClass
‪test_canGetChildClass()
Definition: ContainerTest.php:236
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ContainerTest.php:34
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\test_canBuildCyclicDependenciesOfSingletonsWithSetter
‪test_canBuildCyclicDependenciesOfSingletonsWithSetter()
Definition: ContainerTest.php:257
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest
Definition: ContainerTest.php:31
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceReturnsInstanceOfSimpleNamespacedClass
‪getInstanceReturnsInstanceOfSimpleNamespacedClass()
Definition: ContainerTest.php:69
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClass
Definition: ContainerConstructorInjectionTestFixtures.php:20
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceInjectsFirstMandatoryArgumentIfSecondIsOptionalAndBothAreGivenAsNull
‪getInstanceInjectsFirstMandatoryArgumentIfSecondIsOptionalAndBothAreGivenAsNull()
Definition: ContainerTest.php:644
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\isSingletonReturnsTrueForSingletonInstancesAndFalseForPrototypes
‪isSingletonReturnsTrueForSingletonInstancesAndFalseForPrototypes()
Definition: ContainerTest.php:347
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\prototypeWhichRequiresSingletonViaConstructorInjectionWorks
‪prototypeWhichRequiresSingletonViaConstructorInjectionWorks()
Definition: ContainerTest.php:337
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceGivesSimpleConstructorArgumentToClassInstance
‪getInstanceGivesSimpleConstructorArgumentToClassInstance()
Definition: ContainerTest.php:370
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\prototypeWhichRequiresSingletonViaSetterInjectionWorks
‪prototypeWhichRequiresSingletonViaSetterInjectionWorks()
Definition: ContainerTest.php:297
‪TYPO3\CMS\Core\Log\Logger
Definition: Logger.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceGivesExistingConstructorArgumentToClassInstanceIfArgumentIsGiven
‪getInstanceGivesExistingConstructorArgumentToClassInstanceIfArgumentIsGiven()
Definition: ContainerTest.php:465
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getEmptyObjectInitializesObjects
‪getEmptyObjectInitializesObjects()
Definition: ContainerTest.php:227
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceGivesFirstArgumentToConstructorIfSecondIsOptionalAndFirstIsGiven
‪getInstanceGivesFirstArgumentToConstructorIfSecondIsOptionalAndFirstIsGiven()
Definition: ContainerTest.php:665
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceOnFirstOptionalAndSecondMandatoryGivesTwoGivenArgumentsToConstructor
‪getInstanceOnFirstOptionalAndSecondMandatoryGivesTwoGivenArgumentsToConstructor()
Definition: ContainerTest.php:730
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\Fixtures\ArgumentTestClassForPublicPropertyInjection
Definition: ContainerPropertyInjectionTestClasses.php:17
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceReturnsInstanceOfSimpleClass
‪getInstanceReturnsInstanceOfSimpleClass()
Definition: ContainerTest.php:60
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\singletonWhichRequiresSingletonViaSetterInjectionWorks
‪singletonWhichRequiresSingletonViaSetterInjectionWorks()
Definition: ContainerTest.php:277
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceReturnsInstanceOfAClassWithConstructorInjection
‪getInstanceReturnsInstanceOfAClassWithConstructorInjection()
Definition: ContainerTest.php:78
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceOnTwoOptionalGivesOneArgumentToConstructorIfFirstIsObjectAndSecondIsNotGiven
‪getInstanceOnTwoOptionalGivesOneArgumentToConstructorIfFirstIsObjectAndSecondIsNotGiven()
Definition: ContainerTest.php:889
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceInjectsProtectedProperties
‪getInstanceInjectsProtectedProperties()
Definition: ContainerTest.php:964
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceInjectsNewInstanceOfClassToClassIfArgumentIsMandatory
‪getInstanceInjectsNewInstanceOfClassToClassIfArgumentIsMandatory()
Definition: ContainerTest.php:413
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceReturnsInstanceOfAClassWithTwoLevelDependency
‪getInstanceReturnsInstanceOfAClassWithTwoLevelDependency()
Definition: ContainerTest.php:88
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceGivesTwoArgumentsToClassConstructor
‪getInstanceGivesTwoArgumentsToClassConstructor()
Definition: ContainerTest.php:483
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\getInstanceInjectsFirstMandatoryArgumentIfSecondIsGiven
‪getInstanceInjectsFirstMandatoryArgumentIfSecondIsGiven()
Definition: ContainerTest.php:565
‪TYPO3\CMS\Extbase\Tests\Unit\Object\Container\ContainerTest\prototypeWhichRequiresPrototypeViaSetterInjectionWorks
‪prototypeWhichRequiresPrototypeViaSetterInjectionWorks()
Definition: ContainerTest.php:287