| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | stubClassLoader::load('net::stubbles::ioc::stubApp'); |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | class stubAppTestBindingModuleOne extends stubBaseObject implements stubBindingModule |
|---|
| 17 | { |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | public function configure(stubBinder $binder) |
|---|
| 24 | { |
|---|
| 25 | $binder->bind('foo')->to('stdClass'); |
|---|
| 26 | } |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | class stubAppTestBindingModuleTwo extends stubBaseObject implements stubBindingModule |
|---|
| 35 | { |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | public function configure(stubBinder $binder) |
|---|
| 42 | { |
|---|
| 43 | $binder->bind('bar')->to('stdClass'); |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | class stubAppTestIpoBindingModule extends stubBaseObject implements stubBindingModule |
|---|
| 53 | { |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | protected $request; |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | protected $session; |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | protected $response; |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | public function __construct(stubRequest $request, stubSession $session, stubResponse $response) |
|---|
| 81 | { |
|---|
| 82 | $this->request = $request; |
|---|
| 83 | $this->session = $session; |
|---|
| 84 | $this->response = $response; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | public function configure(stubBinder $binder) |
|---|
| 93 | { |
|---|
| 94 | $binder->bind('stubRequest')->toInstance($this->request); |
|---|
| 95 | $binder->bind('stubSession')->toInstance($this->session); |
|---|
| 96 | $binder->bind('stubResponse')->toInstance($this->response); |
|---|
| 97 | } |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | class stubAppTestCase extends PHPUnit_Framework_TestCase |
|---|
| 107 | { |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | public function setUp() |
|---|
| 112 | { |
|---|
| 113 | stubRegistry::set(stubBinder::REGISTRY_KEY, null); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | public function tearDown() |
|---|
| 120 | { |
|---|
| 121 | stubRegistry::set(stubBinder::REGISTRY_KEY, null); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | public function invalidBindingModuleClassThrowsIllegalArgumentException() |
|---|
| 131 | { |
|---|
| 132 | stubApp::createInjector('stdClass'); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | public function invalidBindingModuleInstanceThrowsIllegalArgumentException() |
|---|
| 142 | { |
|---|
| 143 | stubApp::createInjector(new stdClass()); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | public function bindingModulesAreProcessed() |
|---|
| 152 | { |
|---|
| 153 | $injector = stubApp::createInjector(new stubAppTestBindingModuleOne(), |
|---|
| 154 | 'stubAppTestBindingModuleTwo' |
|---|
| 155 | ); |
|---|
| 156 | $this->assertTrue($injector->hasBinding('foo')); |
|---|
| 157 | $this->assertTrue($injector->hasBinding('bar')); |
|---|
| 158 | $this->assertTrue($injector->hasBinding('stubInjector')); |
|---|
| 159 | $this->assertSame($injector, $injector->getInstance('stubInjector')); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | public function frontControllerCanBeCreatedWithDefaultBindings() |
|---|
| 168 | { |
|---|
| 169 | $frontController = stubApp::createFrontController(new stubAppTestIpoBindingModule($this->getMock('stubRequest'), |
|---|
| 170 | $this->getMock('stubSession'), |
|---|
| 171 | $this->getMock('stubResponse') |
|---|
| 172 | ), |
|---|
| 173 | stubWebsiteBindingModule::createWithXmlProcessorAsDefault() |
|---|
| 174 | ->runningInMode(stubMode::$DEV) |
|---|
| 175 | ); |
|---|
| 176 | $this->assertType('stubFrontController', $frontController); |
|---|
| 177 | } |
|---|
| 178 | } |
|---|
| 179 | ?> |
|---|