| 20 | | |
|---|
| 21 | | class stubInjectorTestCase_ImplicitDependency { |
|---|
| 22 | | protected $goodyear; |
|---|
| 23 | | |
|---|
| 24 | | /** |
|---|
| 25 | | * @Inject |
|---|
| 26 | | */ |
|---|
| 27 | | public function __construct(stubInjectorTestCase_Goodyear $goodyear) { |
|---|
| 28 | | $this->goodyear = $goodyear; |
|---|
| 29 | | } |
|---|
| 30 | | |
|---|
| 31 | | public function getGoodyear() { |
|---|
| 32 | | return $this->goodyear; |
|---|
| 33 | | } |
|---|
| 34 | | } |
|---|
| 35 | | |
|---|
| 36 | | |
|---|
| 37 | | interface stubInjectorTestCase_Vehicle { |
|---|
| | 44 | /** |
|---|
| | 45 | * Helper class to test implicit binding with concrete class names. |
|---|
| | 46 | * |
|---|
| | 47 | * @package stubbles |
|---|
| | 48 | * @subpackage ioc_test |
|---|
| | 49 | */ |
|---|
| | 50 | class stubInjectorTestCase_ImplicitDependency |
|---|
| | 51 | { |
|---|
| | 52 | /** |
|---|
| | 53 | * instance from constructor injection |
|---|
| | 54 | * |
|---|
| | 55 | * @var stubInjectorTestCase_Goodyear |
|---|
| | 56 | */ |
|---|
| | 57 | protected $goodyearByConstructor; |
|---|
| | 58 | /** |
|---|
| | 59 | * instance from setter injection |
|---|
| | 60 | * |
|---|
| | 61 | * @var stubInjectorTestCase_Goodyear |
|---|
| | 62 | */ |
|---|
| | 63 | protected $goodyearBySetter; |
|---|
| | 64 | |
|---|
| | 65 | /** |
|---|
| | 66 | * constructor |
|---|
| | 67 | * |
|---|
| | 68 | * @param stubInjectorTestCase_Goodyear $goodyear |
|---|
| | 69 | * @Inject |
|---|
| | 70 | */ |
|---|
| | 71 | public function __construct(stubInjectorTestCase_Goodyear $goodyear) |
|---|
| | 72 | { |
|---|
| | 73 | $this->goodyearByConstructor = $goodyear; |
|---|
| | 74 | } |
|---|
| | 75 | |
|---|
| | 76 | /** |
|---|
| | 77 | * setter |
|---|
| | 78 | * |
|---|
| | 79 | * @param stubInjectorTestCase_Goodyear $goodyear |
|---|
| | 80 | * @Inject |
|---|
| | 81 | */ |
|---|
| | 82 | public function setGoodyear(stubInjectorTestCase_Goodyear $goodyear) |
|---|
| | 83 | { |
|---|
| | 84 | $this->goodyearBySetter = $goodyear; |
|---|
| | 85 | } |
|---|
| | 86 | |
|---|
| | 87 | /** |
|---|
| | 88 | * returns the instance from constructor injection |
|---|
| | 89 | * |
|---|
| | 90 | * @return stubInjectorTestCase_Goodyear |
|---|
| | 91 | */ |
|---|
| | 92 | public function getGoodyearByConstructor() |
|---|
| | 93 | { |
|---|
| | 94 | return $this->goodyearByConstructor; |
|---|
| | 95 | } |
|---|
| | 96 | |
|---|
| | 97 | /** |
|---|
| | 98 | * returns the instance from setter injection |
|---|
| | 99 | * |
|---|
| | 100 | * @return stubInjectorTestCase_Goodyear |
|---|
| | 101 | */ |
|---|
| | 102 | public function getGoodyearBySetter() |
|---|
| | 103 | { |
|---|
| | 104 | return $this->goodyearBySetter; |
|---|
| | 105 | } |
|---|
| | 106 | } |
|---|
| | 107 | /** |
|---|
| | 108 | * Helper class to test implicit binding related to bug #102. |
|---|
| | 109 | * |
|---|
| | 110 | * @package stubbles |
|---|
| | 111 | * @subpackage ioc_test |
|---|
| | 112 | * @link http://stubbles.net/ticket/102 |
|---|
| | 113 | */ |
|---|
| | 114 | class stubInjectorTestCase_ImplicitDependencyBug102 |
|---|
| | 115 | { |
|---|
| | 116 | /** |
|---|
| | 117 | * instance from setter injection |
|---|
| | 118 | * |
|---|
| | 119 | * @var stubInjectorTestCase_Goodyear |
|---|
| | 120 | */ |
|---|
| | 121 | protected $goodyearBySetter; |
|---|
| | 122 | |
|---|
| | 123 | /** |
|---|
| | 124 | * setter |
|---|
| | 125 | * |
|---|
| | 126 | * @param stubInjectorTestCase_Goodyear $goodyear |
|---|
| | 127 | * @Inject |
|---|
| | 128 | */ |
|---|
| | 129 | public function setGoodyear(stubInjectorTestCase_Goodyear $goodyear) |
|---|
| | 130 | { |
|---|
| | 131 | $this->goodyearBySetter = $goodyear; |
|---|
| | 132 | } |
|---|
| | 133 | |
|---|
| | 134 | /** |
|---|
| | 135 | * returns the instance from setter injection |
|---|
| | 136 | * |
|---|
| | 137 | * @return stubInjectorTestCase_Goodyear |
|---|
| | 138 | */ |
|---|
| | 139 | public function getGoodyearBySetter() |
|---|
| | 140 | { |
|---|
| | 141 | return $this->goodyearBySetter; |
|---|
| | 142 | } |
|---|
| | 143 | } |
|---|
| | 144 | /** |
|---|
| | 145 | * Another helper interface for injection and binding tests. |
|---|
| | 146 | * |
|---|
| | 147 | * @package stubbles |
|---|
| | 148 | * @subpackage ioc_test |
|---|
| | 149 | */ |
|---|
| | 150 | interface stubInjectorTestCase_Vehicle |
|---|
| | 151 | { |
|---|
| | 152 | /** |
|---|
| | 153 | * moves the vehicle forward |
|---|
| | 154 | * |
|---|
| | 155 | * @return string |
|---|
| | 156 | */ |
|---|
| | 177 | * @param stubInjectorTestCase_Tire $tire |
|---|
| | 178 | * @Inject |
|---|
| | 179 | */ |
|---|
| | 180 | public function __construct(stubInjectorTestCase_Tire $tire) |
|---|
| | 181 | { |
|---|
| | 182 | $this->tire = $tire; |
|---|
| | 183 | } |
|---|
| | 184 | |
|---|
| | 185 | /** |
|---|
| | 186 | * moves the vehicle forward |
|---|
| | 187 | * |
|---|
| | 188 | * @return string |
|---|
| | 189 | */ |
|---|
| | 190 | public function moveForward() |
|---|
| | 191 | { |
|---|
| | 192 | return $this->tire->rotate(); |
|---|
| | 193 | } |
|---|
| | 194 | } |
|---|
| | 195 | /** |
|---|
| | 196 | * Another helper class for injection and binding tests. |
|---|
| | 197 | * |
|---|
| | 198 | * @package stubbles |
|---|
| | 199 | * @subpackage ioc_test |
|---|
| | 200 | */ |
|---|
| | 201 | class stubInjectorTestCase_Bike implements stubInjectorTestCase_Vehicle |
|---|
| | 202 | { |
|---|
| | 203 | /** |
|---|
| | 204 | * injected tire instance |
|---|
| | 205 | * |
|---|
| | 206 | * @var stubInjectorTestCase_Tire |
|---|
| | 207 | */ |
|---|
| | 208 | public $tire; |
|---|
| | 209 | |
|---|
| | 210 | /** |
|---|
| | 211 | * sets the tire |
|---|
| | 212 | * |
|---|
| | 213 | * @param stubInjectorTestCase_Tire $tire |
|---|
| | 214 | * @Inject |
|---|
| | 215 | */ |
|---|
| | 216 | public function setTire(stubInjectorTestCase_Tire $tire) |
|---|
| | 217 | { |
|---|
| | 218 | $this->tire = $tire; |
|---|
| | 219 | } |
|---|
| | 220 | |
|---|
| | 221 | /** |
|---|
| | 222 | * moves the vehicle forward |
|---|
| | 223 | * |
|---|
| | 224 | * @return string |
|---|
| | 225 | */ |
|---|
| | 226 | public function moveForward() |
|---|
| | 227 | { |
|---|
| | 228 | return $this->tire->rotate(); |
|---|
| | 229 | } |
|---|
| | 230 | } |
|---|
| | 231 | /** |
|---|
| | 232 | * Another helper interface for injection and binding tests. |
|---|
| | 233 | * |
|---|
| | 234 | * @package stubbles |
|---|
| | 235 | * @subpackage ioc_test |
|---|
| | 236 | */ |
|---|
| | 237 | interface stubInjectorTestCase_Roof |
|---|
| | 238 | { |
|---|
| | 239 | /** |
|---|
| | 240 | * method to open the roof |
|---|
| | 241 | */ |
|---|
| | 242 | public function open(); |
|---|
| | 243 | /** |
|---|
| | 244 | * method to close the roof |
|---|
| | 245 | */ |
|---|
| | 246 | public function close(); |
|---|
| | 247 | } |
|---|
| | 248 | /** |
|---|
| | 249 | * Another helper class for injection and binding tests. |
|---|
| | 250 | * |
|---|
| | 251 | * @package stubbles |
|---|
| | 252 | * @subpackage ioc_test |
|---|
| | 253 | */ |
|---|
| | 254 | class stubInjectorTestCase_Convertible implements stubInjectorTestCase_Vehicle |
|---|
| | 255 | { |
|---|
| | 256 | /** |
|---|
| | 257 | * injected tire instance |
|---|
| | 258 | * |
|---|
| | 259 | * @var stubInjectorTestCase_Tire |
|---|
| | 260 | */ |
|---|
| | 261 | public $tire; |
|---|
| | 262 | /** |
|---|
| | 263 | * injected roof instance |
|---|
| | 264 | * |
|---|
| | 265 | * @var stubInjectorTestCase_Roof |
|---|
| | 266 | */ |
|---|
| | 267 | public $roof; |
|---|
| | 268 | |
|---|
| | 269 | /** |
|---|
| | 270 | * sets the tire |
|---|
| | 271 | * |
|---|
| 59 | | |
|---|
| 60 | | class stubInjectorTestCase_Bike implements stubInjectorTestCase_Vehicle { |
|---|
| 61 | | |
|---|
| 62 | | public $tire; |
|---|
| 63 | | |
|---|
| 64 | | /** |
|---|
| 65 | | * Set the tire |
|---|
| 66 | | * |
|---|
| 67 | | * @param Tire $tire |
|---|
| 68 | | * @Inject |
|---|
| 69 | | */ |
|---|
| 70 | | public function setTire(stubInjectorTestCase_Tire $tire) { |
|---|
| 71 | | $this->tire = $tire; |
|---|
| 72 | | } |
|---|
| 73 | | |
|---|
| 74 | | public function moveForward() { |
|---|
| 75 | | return $this->tire->rotate(); |
|---|
| 76 | | } |
|---|
| 77 | | } |
|---|
| 78 | | |
|---|
| 79 | | interface stubInjectorTestCase_Roof { |
|---|
| 80 | | public function open(); |
|---|
| 81 | | public function close(); |
|---|
| 82 | | } |
|---|
| 83 | | |
|---|
| 84 | | class stubInjectorTestCase_Convertible implements stubInjectorTestCase_Vehicle { |
|---|
| 85 | | |
|---|
| 86 | | public $tire; |
|---|
| 87 | | public $roof; |
|---|
| 88 | | |
|---|
| 89 | | /** |
|---|
| 90 | | * Set the tire |
|---|
| 91 | | * |
|---|
| 92 | | * @param Tire $tire |
|---|
| 93 | | * @Inject |
|---|
| 94 | | */ |
|---|
| 95 | | public function setTire(stubInjectorTestCase_Tire $tire) { |
|---|
| 96 | | $this->tire = $tire; |
|---|
| 97 | | } |
|---|
| 98 | | |
|---|
| 99 | | /** |
|---|
| 100 | | * Set the root |
|---|
| 101 | | * |
|---|
| 102 | | * @param Roof $roof |
|---|
| 103 | | * @Inject(optinal=true) |
|---|
| 104 | | */ |
|---|
| 105 | | public function setRoof(stubInjectorTestCase_Roof $roof) { |
|---|
| 106 | | $this->roof = $roof; |
|---|
| 107 | | } |
|---|
| 108 | | |
|---|
| 109 | | public function moveForward() { |
|---|
| 110 | | return $this->tire->rotate(); |
|---|
| 111 | | } |
|---|
| 112 | | } |
|---|
| 113 | | |
|---|
| 114 | | /** |
|---|
| 115 | | * Test for net.stubbles.ioc.stubInjector |
|---|
| 116 | | * |
|---|
| 117 | | * @package stubbles |
|---|
| 118 | | * @subpackage ioc_injection_test |
|---|
| | 302 | /** |
|---|
| | 303 | * Test for net::stubbles::ioc::stubInjector. |
|---|
| | 304 | * |
|---|
| | 305 | * @package stubbles |
|---|
| | 306 | * @subpackage ioc_test |
|---|
| 271 | | $this->assertIsA($obj->getGoodyear(), 'stubInjectorTestCase_Goodyear'); |
|---|
| | 457 | $this->assertIsA($obj->getGoodyearByConstructor(), 'stubInjectorTestCase_Goodyear'); |
|---|
| | 458 | $this->assertIsA($obj->getGoodyearBySetter(), 'stubInjectorTestCase_Goodyear'); |
|---|
| | 459 | } |
|---|
| | 460 | |
|---|
| | 461 | /** |
|---|
| | 462 | * test method for bug #102 |
|---|
| | 463 | * |
|---|
| | 464 | * @link http://stubbles.net/ticket/102 |
|---|
| | 465 | */ |
|---|
| | 466 | public function testBug102() |
|---|
| | 467 | { |
|---|
| | 468 | $obj = new stubInjectorTestCase_ImplicitDependencyBug102(); |
|---|
| | 469 | $binder = new stubBinder(); |
|---|
| | 470 | $injector = $binder->getInjector(); |
|---|
| | 471 | $injector->handleInjections($obj); |
|---|
| | 472 | $this->assertIsA($obj->getGoodyearBySetter(), 'stubInjectorTestCase_Goodyear'); |
|---|