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