root/framework/trunk/src/test/php/net/stubbles/ioc/stubAppTestCase.php @ 2081

Revision 2081, 4.6 kB (checked in by mikey, 19 months ago)

implement refactorings #194 (Do not bind website cache factory if mode forbids caching) and #196 (Remove dependency to stubMode in website cache)
This is still unstable and not very well tested. Before finalizing this refactoring #197 needs to be implemented.

  • Property svn:keywords set to Id
Line 
1<?php
2/**
3 * Test for net::stubbles::ioc::stubApp.
4 *
5 * @package     stubbles
6 * @subpackage  ioc_test
7 * @version     $Id$
8 */
9stubClassLoader::load('net::stubbles::ioc::stubApp');
10/**
11 * Helper class for the test.
12 *
13 * @package     stubbles
14 * @subpackage  ioc_test
15 */
16class stubAppTestBindingModuleOne extends stubBaseObject implements stubBindingModule
17{
18    /**
19     * configure the binder
20     *
21     * @param  stubBinder  $binder
22     */
23    public function configure(stubBinder $binder)
24    {
25        $binder->bind('foo')->to('stdClass');
26    }
27}
28/**
29 * Helper class for the test.
30 *
31 * @package     stubbles
32 * @subpackage  ioc_test
33 */
34class stubAppTestBindingModuleTwo extends stubBaseObject implements stubBindingModule
35{
36    /**
37     * configure the binder
38     *
39     * @param  stubBinder  $binder
40     */
41    public function configure(stubBinder $binder)
42    {
43        $binder->bind('bar')->to('stdClass');
44    }
45}
46/**
47 * Helper class for the test.
48 *
49 * @package     stubbles
50 * @subpackage  ioc_test
51 */
52class stubAppTestIpoBindingModule extends stubBaseObject implements stubBindingModule
53{
54    /**
55     * request instance
56     *
57     * @var  stubRequest
58     */
59    protected $request;
60    /**
61     * session instance
62     *
63     * @var  stubSession
64     */
65    protected $session;
66    /**
67     * response instance
68     *
69     * @var  stubResponse
70     */
71    protected $response;
72   
73    /**
74     * constructor
75     *
76     * @param  stubRequest   $request
77     * @param  stubSession   $session
78     * @param  stubResponse  $response
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     * configure the binder
89     *
90     * @param  stubBinder  $binder
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 * Test for net::stubbles::ioc::stubApp.
101 *
102 * @package     stubbles
103 * @subpackage  ioc_test
104 * @group       ioc
105 */
106class stubAppTestCase extends PHPUnit_Framework_TestCase
107{
108    /**
109     * set up test environment
110     */
111    public function setUp()
112    {
113        stubRegistry::set(stubBinder::REGISTRY_KEY, null);
114    }
115
116    /**
117     * clean up test environment
118     */
119    public function tearDown()
120    {
121        stubRegistry::set(stubBinder::REGISTRY_KEY, null);
122    }
123
124    /**
125     * invalid binding module class throws illegal argument exception
126     *
127     * @test
128     * @expectedException  stubIllegalArgumentException
129     */
130    public function invalidBindingModuleClassThrowsIllegalArgumentException()
131    {
132        stubApp::createInjector('stdClass');
133    }
134
135    /**
136     * invalid binding module instance throws illegal argument exception
137     *
138     * @test
139     * @expectedException  stubIllegalArgumentException
140     */
141    public function invalidBindingModuleInstanceThrowsIllegalArgumentException()
142    {
143        stubApp::createInjector(new stdClass());
144    }
145
146    /**
147     * binding modules are process if they are instances or class names
148     *
149     * @test
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     * shortcut for creating front controller should work
164     *
165     * @test
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?>
Note: See TracBrowser for help on using the browser.