Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractFactoryRuntimeDefinitionsTestCases.php
Go to the documentation of this file.
1 <?php
8 
17 
18 abstract class AbstractFactoryRuntimeDefinitionsTestCases extends \PHPUnit\Framework\TestCase
19 {
20  const ALIAS_OVERRIDDEN_STRING = 'overridden';
22 
25 
27  protected $factory;
28 
34  abstract protected function createFactoryToTest();
35 
36  public function setUp()
37  {
38  $this->factory = $this->createFactoryToTest();
39 
46  $this->complexDependenciesObject = $this->factory->create(ComplexDependencies::class);
47  }
48 
50  {
51  $this->assertInstanceOf(ComplexDependencies::class, $this->complexDependenciesObject);
52  }
53 
54  public function testCreateBasic()
55  {
56  $this->assertInstanceOf(Basic::class, $this->complexDependenciesObject->getBasic());
57  }
58 
59  public function testCreateBasicInjection()
60  {
61  $this->assertInstanceOf(BasicInjection::class, $this->complexDependenciesObject->getBasicInjection());
62  $this->assertInstanceOf(
63  Basic::class,
64  $this->complexDependenciesObject->getBasicInjection()->getBasicDependency()
65  );
66  }
67 
68  public function testCreateInterface()
69  {
70  $this->assertInstanceOf(TestAssetInterface::class, $this->complexDependenciesObject->getTestAssetInterface());
71  }
72 
74  {
75  $this->assertInstanceOf(
76  ConstructorNineArguments::class,
77  $this->complexDependenciesObject->getConstructorNineArguments()
78  );
79  $this->assertInstanceOf(
80  Basic::class,
81  $this->complexDependenciesObject->getConstructorNineArguments()->getBasicDependency()
82  );
83  }
84 
86  {
87  $this->assertInstanceOf(DependsOnInterface::class, $this->complexDependenciesObject->getDependsOnInterface());
88  $this->assertInstanceOf(
89  TestAssetInterface::class,
90  $this->complexDependenciesObject->getDependsOnInterface()->getInterfaceDependency()
91  );
92  }
93 
95  {
96  $this->assertInstanceOf(
97  HasOptionalParameters::class,
98  $this->complexDependenciesObject->getHasOptionalParameters()
99  );
100  $this->assertEquals(
102  $this->complexDependenciesObject->getHasOptionalParameters()->getOptionalIntegerParameter()
103  );
104  $this->assertEquals(
106  $this->complexDependenciesObject->getHasOptionalParameters()->getOptionalStringParameter()
107  );
108  $this->assertInstanceOf(
109  TestAssetInterface::class,
110  $this->complexDependenciesObject->getHasOptionalParameters()->getRequiredInterfaceParam()
111  );
112  $this->assertInstanceOf(
113  Basic::class,
114  $this->complexDependenciesObject->getHasOptionalParameters()->getRequiredObjectParameter()
115  );
116  }
117 
119  {
120  $this->assertInstanceOf(DependsOnAlias::class, $this->complexDependenciesObject->getDependsOnAlias());
121  $this->assertEquals(
122  self::ALIAS_OVERRIDDEN_STRING,
123  $this->complexDependenciesObject->getDependsOnAlias()->getOverriddenString()
124  );
125  $this->assertEquals(
126  self::ALIAS_OVERRIDDEN_INT,
127  $this->complexDependenciesObject->getDependsOnAlias()->getOverRiddenInteger()
128  );
129  }
130 }