Changeset 1014

Show
Ignore:
Timestamp:
11/09/07 12:31:44 (1 year ago)
Author:
schst
Message:

Added stubConfigurationException, added unit tests for stubSessionResourceManager, added several sanity checks and fixed some small bugs in stubSessionResourceManager

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/session/resourcemanager/stubSessionResourceManager.php

    r984 r1014  
    1212 */ 
    1313stubClassLoader::load('net.stubbles.ipo.session.resourcemanager.stubSessionResource', 
     14                      'net.stubbles.lang.exceptions.stubConfigurationException', 
    1415                      'net.stubbles.ioc.stubInjectionProvider'); 
    1516 
     
    108109 
    109110        $this->resources[$implementation] = $this->createResource($implementation); 
     111        $interfaceClazz = new stubReflectionClass($interface); 
     112        $shortInterfaceName = $interfaceClazz->getName(); 
     113        if (!$this->resources[$implementation] instanceof $shortInterfaceName) { 
     114            throw new stubConfigurationException("{$implementation} does not implement interface {$interface}."); 
     115        } 
     116 
    110117        $this->session->putValue($sessionKey, $this->resources[$implementation]); 
    111118        return $this->resources[$implementation]; 
     
    120127     * @param  string|stubReflectionClass $interface 
    121128     * @return string 
    122      * @todo   check, whether the interface exists and extends stubSession Resource 
    123129     */ 
    124130    protected function getFullQualifiedInterfaceName($interface) { 
    125131        if (is_string($interface) === true) { 
     132            $interfaceClazz = new stubReflectionClass($interface); 
     133            if ($interfaceClazz->isInterface() === false) { 
     134                throw new stubIllegalArgumentException($interfaceClazz->getFullQualifiedClassName() . ' is no interface.'); 
     135            } 
     136            if (!$interfaceClazz->isSubclassOf(new stubReflectionClass('stubSessionResource'))) { 
     137                throw new stubIllegalArgumentException($interfaceClazz->getFullQualifiedClassName() . ' is no session resource interface.'); 
     138            } 
    126139            return $interface; 
    127140        } 
    128141        if ($interface instanceof stubReflectionClass) { 
    129142            if ($interface->isInterface() === false) { 
    130                 throw new stubIllegalArgumentException($interface->getFullQualifiedClassName . ' is no interface.'); 
    131             } 
    132             $interface = $interface->getFullQualifiedClassName(); 
     143                throw new stubIllegalArgumentException($interface->getFullQualifiedClassName() . ' is no interface.'); 
     144            } 
     145            if (!$interface->isSubclassOf(new stubReflectionClass('stubSessionResource'))) { 
     146                throw new stubIllegalArgumentException($interface->getFullQualifiedClassName() . ' is no session resource interface.'); 
     147            } 
     148            return $interface->getFullQualifiedClassName(); 
    133149        } 
    134150        throw new stubIllegalArgumentException('Neither string nor stubReflectionClass instance given.'); 
     
    155171    protected function getImplementation($interface) { 
    156172        if (isset($this->resourceDefinitions[$interface]) === false) { 
    157             throw new stubException('Resource ' . $interface . ' is not availabale.'); 
     173            throw new stubIllegalArgumentException('Resource ' . $interface . ' is not availabale.'); 
    158174        } 
    159175        return $this->resourceDefinitions[$interface]; 
     
    165181     * @param string $implementation 
    166182     * @return stubSessionResource 
    167      * 
    168      * @todo   check, whether the implementation actually implements the interface 
    169183     */ 
    170184    protected function createResource($implementation) { 
  • trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php

    r817 r1014  
    2323        $this->TestSuite('All ipo tests'); 
    2424        $this->addTestFile($dir . '/interceptors/stubInterceptorXJConfInitializerTestCase.php'); 
    25          
     25 
    2626        $this->addTestFile($dir . '/request/stubAbstractRequestTestCase.php'); 
    2727        $this->addTestFile($dir . '/request/stubRequestPrefixDecoratorTestCase.php'); 
    2828        $this->addTestFile($dir . '/request/stubRequestValueErrorTestCase.php'); 
    29          
     29 
    3030        $this->addTestFile($dir . '/request/broker/stubRequestBrokerTestCase.php'); 
    3131        $this->addTestFile($dir . '/request/broker/annotations/stubAbstractFilterAnnotationTestCase.php'); 
     
    3737        $this->addTestFile($dir . '/request/broker/annotations/stubStringFilterAnnotationTestCase.php'); 
    3838        $this->addTestFile($dir . '/request/broker/annotations/stubTextFilterAnnotationTestCase.php'); 
    39          
     39 
    4040        $this->addTestFile($dir . '/request/filters/stubFloatFilterTestCase.php'); 
    4141        $this->addTestFile($dir . '/request/filters/stubHTTPURLFilterTestCase.php'); 
     
    4747        $this->addTestFile($dir . '/request/filters/stubStringFilterTestCase.php'); 
    4848        $this->addTestFile($dir . '/request/filters/stubTextFilterTestCase.php'); 
    49          
     49 
    5050        $this->addTestFile($dir . '/response/stubCookieTestCase.php'); 
    5151        $this->addTestFile($dir . '/response/stubDecoratedResponseTestCase.php'); 
    52          
     52 
    5353        $this->addTestFile($dir . '/session/stubAbstractSessionTestCase.php'); 
    5454        $this->addTestFile($dir . '/session/stubNoneDurableSessionTestCase.php'); 
    5555        $this->addTestFile($dir . '/session/stubPHPSessionTestCase.php'); 
     56        $this->addTestFile($dir . '/session/resourcemanager/stubSessionResourceManagerTestCase.php'); 
    5657    } 
    5758}