| @@ 73-103 (lines=31) @@ | ||
| 70 | ); |
|
| 71 | } |
|
| 72 | ||
| 73 | public function testBasicInjector() |
|
| 74 | { |
|
| 75 | $injector = new Injector(); |
|
| 76 | $injector->setAutoScanProperties(true); |
|
| 77 | $config = array( |
|
| 78 | 'SampleService' => array( |
|
| 79 | 'src' => TEST_SERVICES . '/SampleService.php', |
|
| 80 | 'class' => SampleService::class, |
|
| 81 | ) |
|
| 82 | ); |
|
| 83 | ||
| 84 | $injector->load($config); |
|
| 85 | ||
| 86 | ||
| 87 | $this->assertFalse($injector->has('UnknownService')); |
|
| 88 | $this->assertNull($injector->getServiceName('UnknownService')); |
|
| 89 | ||
| 90 | $this->assertTrue($injector->has('SampleService')); |
|
| 91 | $this->assertEquals( |
|
| 92 | 'SampleService', |
|
| 93 | $injector->getServiceName('SampleService') |
|
| 94 | ); |
|
| 95 | ||
| 96 | $myObject = new TestObject(); |
|
| 97 | $injector->inject($myObject); |
|
| 98 | ||
| 99 | $this->assertInstanceOf( |
|
| 100 | SampleService::class, |
|
| 101 | $myObject->sampleService |
|
| 102 | ); |
|
| 103 | } |
|
| 104 | ||
| 105 | public function testConfiguredInjector() |
|
| 106 | { |
|
| @@ 254-284 (lines=31) @@ | ||
| 251 | ); |
|
| 252 | } |
|
| 253 | ||
| 254 | public function testAutoSetInjector() |
|
| 255 | { |
|
| 256 | $injector = new Injector(); |
|
| 257 | $injector->setAutoScanProperties(true); |
|
| 258 | $injector->addAutoProperty('auto', 'somevalue'); |
|
| 259 | $config = array( |
|
| 260 | 'SampleService' => array( |
|
| 261 | 'src' => TEST_SERVICES . '/SampleService.php', |
|
| 262 | 'class' => SampleService::class |
|
| 263 | ) |
|
| 264 | ); |
|
| 265 | $injector->load($config); |
|
| 266 | ||
| 267 | $this->assertTrue($injector->has('SampleService')); |
|
| 268 | $this->assertEquals( |
|
| 269 | 'SampleService', |
|
| 270 | $injector->getServiceName('SampleService') |
|
| 271 | ); |
|
| 272 | // We expect a false because the AnotherService::class is actually |
|
| 273 | // just a replacement of the SilverStripe\Core\Tests\Injector\AopProxyServiceTest\SampleService |
|
| 274 | ||
| 275 | $myObject = new InjectorTest\TestObject(); |
|
| 276 | ||
| 277 | $injector->inject($myObject); |
|
| 278 | ||
| 279 | $this->assertInstanceOf( |
|
| 280 | SampleService::class, |
|
| 281 | $myObject->sampleService |
|
| 282 | ); |
|
| 283 | $this->assertEquals($myObject->auto, 'somevalue'); |
|
| 284 | } |
|
| 285 | ||
| 286 | public function testSettingSpecificProperty() |
|
| 287 | { |
|