Changeset 1272

Show
Ignore:
Timestamp:
01/21/08 09:29:29 (10 months ago)
Author:
mikey
Message:

continued refactoring #118: converted tests for net::stubbles::ipo

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/test/AllTests.php

    r1271 r1272  
    2727require_once $dir . '/php/net/stubbles/events/EventTestSuite.php'; 
    2828require_once $dir . '/php/net/stubbles/ioc/IOCTestSuite.php'; 
     29require_once $dir . '/php/net/stubbles/ipo/IPOTestSuite.php'; 
    2930require_once $dir . '/php/net/stubbles/websites/WebsitesTestSuite.php'; 
    3031require_once $dir . '/php/net/stubbles/websites/variantmanager/VariantManagerTestSuite.php'; 
     
    5859        $suite->addTestSuite('EventTestSuite'); 
    5960        $suite->addTestSuite('IOCTestSuite'); 
     61        $suite->addTestSuite('IPOTestSuite'); 
    6062        $suite->addTestSuite('WebsitesTestSuite'); 
    6163        $suite->addTestSuite('VariantManagerTestSuite'); 
  • trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php

    r1166 r1272  
    1313 * @subpackage  test 
    1414 */ 
    15 class IPOTestSuite extends TestSuite 
     15class IPOTestSuite extends PHPUnit_Framework_TestSuite 
    1616{ 
    1717    /** 
    18      * constructor 
     18     * returns the test suite to be run 
     19     * 
     20     * @return  PHPUnit_Framework_TestSuite 
    1921     */ 
    20     public function __construct() 
     22    public static function suite() 
    2123    { 
    22         $dir = dirname(__FILE__); 
    23         $this->TestSuite('All ipo tests'); 
    24         $this->addTestFile($dir . '/interceptors/stubInterceptorXJConfInitializerTestCase.php'); 
     24        $suite = new self(); 
     25        $dir   = dirname(__FILE__); 
     26        $suite->addTestFile($dir . '/interceptors/stubInterceptorXJConfInitializerTestCase.php'); 
    2527 
    26         $this->addTestFile($dir . '/request/stubAbstractRequestTestCase.php'); 
    27         $this->addTestFile($dir . '/request/stubRequestPrefixDecoratorTestCase.php'); 
    28         $this->addTestFile($dir . '/request/stubRequestValueErrorFactoryMappingDecoratorTestCase.php'); 
    29         $this->addTestFile($dir . '/request/stubRequestValueErrorTestCase.php'); 
     28        #$suite->addTestFile($dir . '/request/stubAbstractRequestTestCase.php'); 
     29        #$suite->addTestFile($dir . '/request/stubRequestPrefixDecoratorTestCase.php'); 
     30        #$suite->addTestFile($dir . '/request/stubRequestValueErrorFactoryMappingDecoratorTestCase.php'); 
     31        #$suite->addTestFile($dir . '/request/stubRequestValueErrorTestCase.php'); 
    3032 
    31         $this->addTestFile($dir . '/request/broker/stubRequestBrokerTestCase.php'); 
    32         $this->addTestFile($dir . '/request/broker/annotations/stubAbstractFilterAnnotationTestCase.php'); 
    33         $this->addTestFile($dir . '/request/broker/annotations/stubFloatFilterAnnotationTestCase.php'); 
    34         $this->addTestFile($dir . '/request/broker/annotations/stubHTTPURLFilterAnnotationTestCase.php'); 
    35         $this->addTestFile($dir . '/request/broker/annotations/stubIntegerFilterAnnotationTestCase.php'); 
    36         $this->addTestFile($dir . '/request/broker/annotations/stubMailFilterAnnotationTestCase.php'); 
    37         $this->addTestFile($dir . '/request/broker/annotations/stubPasswordFilterAnnotationTestCase.php'); 
    38         $this->addTestFile($dir . '/request/broker/annotations/stubStringFilterAnnotationTestCase.php'); 
    39         $this->addTestFile($dir . '/request/broker/annotations/stubTextFilterAnnotationTestCase.php'); 
     33        #$suite->addTestFile($dir . '/request/broker/stubRequestBrokerTestCase.php'); 
     34        #$suite->addTestFile($dir . '/request/broker/annotations/stubAbstractFilterAnnotationTestCase.php'); 
     35        #$suite->addTestFile($dir . '/request/broker/annotations/stubFloatFilterAnnotationTestCase.php'); 
     36        #$suite->addTestFile($dir . '/request/broker/annotations/stubHTTPURLFilterAnnotationTestCase.php'); 
     37        #$suite->addTestFile($dir . '/request/broker/annotations/stubIntegerFilterAnnotationTestCase.php'); 
     38        #$suite->addTestFile($dir . '/request/broker/annotations/stubMailFilterAnnotationTestCase.php'); 
     39        #$suite->addTestFile($dir . '/request/broker/annotations/stubPasswordFilterAnnotationTestCase.php'); 
     40        #$suite->addTestFile($dir . '/request/broker/annotations/stubStringFilterAnnotationTestCase.php'); 
     41        #$suite->addTestFile($dir . '/request/broker/annotations/stubTextFilterAnnotationTestCase.php'); 
    4042 
    41         $this->addTestFile($dir . '/request/filters/stubFloatFilterTestCase.php'); 
    42         $this->addTestFile($dir . '/request/filters/stubHTTPURLFilterTestCase.php'); 
    43         $this->addTestFile($dir . '/request/filters/stubIntegerFilterTestCase.php'); 
    44         $this->addTestFile($dir . '/request/filters/stubMailFilterTestCase.php'); 
    45         $this->addTestFile($dir . '/request/filters/stubMD5FilterTestCase.php'); 
    46         $this->addTestFile($dir . '/request/filters/stubPassThruFilterTestCase.php'); 
    47         $this->addTestFile($dir . '/request/filters/stubPasswordFilterTestCase.php'); 
    48         $this->addTestFile($dir . '/request/filters/stubRegexFilterDecoratorTestCase.php'); 
    49         $this->addTestFile($dir . '/request/filters/stubStringFilterTestCase.php'); 
    50         $this->addTestFile($dir . '/request/filters/stubTextFilterTestCase.php'); 
     43        #$suite->addTestFile($dir . '/request/filters/stubFloatFilterTestCase.php'); 
     44        #$suite->addTestFile($dir . '/request/filters/stubHTTPURLFilterTestCase.php'); 
     45        #$suite->addTestFile($dir . '/request/filters/stubIntegerFilterTestCase.php'); 
     46        #$suite->addTestFile($dir . '/request/filters/stubMailFilterTestCase.php'); 
     47        #$suite->addTestFile($dir . '/request/filters/stubMD5FilterTestCase.php'); 
     48        #$suite->addTestFile($dir . '/request/filters/stubPassThruFilterTestCase.php'); 
     49        #$suite->addTestFile($dir . '/request/filters/stubPasswordFilterTestCase.php'); 
     50        #$suite->addTestFile($dir . '/request/filters/stubRegexFilterDecoratorTestCase.php'); 
     51        #$suite->addTestFile($dir . '/request/filters/stubStringFilterTestCase.php'); 
     52        #$suite->addTestFile($dir . '/request/filters/stubTextFilterTestCase.php'); 
    5153 
    52         $this->addTestFile($dir . '/response/stubCookieTestCase.php'); 
    53         $this->addTestFile($dir . '/response/stubDecoratedResponseTestCase.php'); 
     54        $suite->addTestFile($dir . '/response/stubCookieTestCase.php'); 
     55        $suite->addTestFile($dir . '/response/stubDecoratedResponseTestCase.php'); 
    5456 
    55         $this->addTestFile($dir . '/session/stubAbstractSessionTestCase.php'); 
    56         $this->addTestFile($dir . '/session/stubNoneDurableSessionTestCase.php'); 
    57         $this->addTestFile($dir . '/session/stubPHPSessionTestCase.php'); 
    58         $this->addTestFile($dir . '/session/resourcemanager/stubSessionResourceManagerTestCase.php'); 
     57        $suite->addTestFile($dir . '/session/stubAbstractSessionTestCase.php'); 
     58        $suite->addTestFile($dir . '/session/stubNoneDurableSessionTestCase.php'); 
     59        $suite->addTestFile($dir . '/session/stubPHPSessionTestCase.php'); 
     60        $suite->addTestFile($dir . '/session/resourcemanager/stubSessionResourceManagerTestCase.php'); 
     61        return $suite; 
    5962    } 
    6063} 
  • trunk/src/test/php/net/stubbles/ipo/interceptors/stubInterceptorXJConfInitializerTestCase.php

    r1223 r1272  
    1111                      'net::stubbles::ipo::interceptors::stubPostInterceptor' 
    1212); 
    13 Mock::generate('stubPreInterceptor'); 
    14 Mock::generate('stubPostInterceptor'); 
     13/** 
     14 * Helper class for test: serializable pre- and postinterceptor. 
     15 * 
     16 * @package     stubbles 
     17 * @subpackage  ipo_interceptors_test 
     18 */ 
    1519class MockSerializableInterceptor extends stubSerializableObject implements stubPreInterceptor, stubPostInterceptor 
    1620{ 
    17     public function preProcess(stubRequest $request, stubSession $session, stubResponse $response) 
     21    /** 
     22     * does the preprocessing stuff 
     23     * 
     24     * @param  stubRequest   $request   access to request data 
     25     * @param  stubSession   $session   access to session data 
     26     * @param  stubResponse  $response  access to response data 
     27     */ 
     28    public function preProcess(stubRequest $request, stubSession $session, stubResponse $response) {} 
     29 
     30    /** 
     31     * does the postprocessing stuff 
     32     * 
     33     * @param  stubRequest   $request   access to request data 
     34     * @param  stubSession   $session   access to session data 
     35     * @param  stubResponse  $response  access to response data 
     36     */ 
     37    public function postProcess(stubRequest $request, stubSession $session, stubResponse $response) {} 
     38
     39/** 
     40 * Helper class for test: non-serializable preinterceptor. 
     41 * 
     42 * @package     stubbles 
     43 * @subpackage  ipo_interceptors_test 
     44 */ 
     45class MockPreInterceptor extends stubBaseObject implements stubPreInterceptor 
     46
     47    /** 
     48     * does the preprocessing stuff 
     49     * 
     50     * @param  stubRequest   $request   access to request data 
     51     * @param  stubSession   $session   access to session data 
     52     * @param  stubResponse  $response  access to response data 
     53     */ 
     54    public function preProcess(stubRequest $request, stubSession $session, stubResponse $response) {} 
     55 
     56    /** 
     57     * returns the full qualified class name 
     58     * 
     59     * @return  string 
     60     */ 
     61    public function getClassName() 
    1862    { 
    19          
     63        return 'MockPreInterceptor'; 
    2064    } 
    21      
    22     public function postProcess(stubRequest $request, stubSession $session, stubResponse $response) 
     65
     66/** 
     67 * Helper class for test: non-serializable postinterceptor. 
     68 * 
     69 * @package     stubbles 
     70 * @subpackage  ipo_interceptors_test 
     71 */ 
     72class MockPostInterceptor extends stubBaseObject implements stubPostInterceptor 
     73
     74    /** 
     75     * does the postprocessing stuff 
     76     * 
     77     * @param  stubRequest   $request   access to request data 
     78     * @param  stubSession   $session   access to session data 
     79     * @param  stubResponse  $response  access to response data 
     80     */ 
     81    public function postProcess(stubRequest $request, stubSession $session, stubResponse $response) {} 
     82 
     83    /** 
     84     * returns the full qualified class name 
     85     * 
     86     * @return  string 
     87     */ 
     88    public function getClassName() 
    2389    { 
    24          
     90        return 'MockPostInterceptor'; 
    2591    } 
    2692} 
     
    3197 * @subpackage  ipo_interceptors_test 
    3298 */ 
    33 class stubInterceptorXJConfInitializerTestCase extends UnitTestCase 
     99class stubInterceptorXJConfInitializerTestCase extends PHPUnit_Framework_TestCase 
    34100{ 
    35101    /** 
     
    58124    { 
    59125        $this->interceptorXJConfInitializer = new stubInterceptorXJConfInitializer(); 
    60         $this->preInterceptors[]            = new MockstubPreInterceptor(); 
    61         $this->preInterceptors[0]->setReturnValue('getClassName', 'MockstubPreInterceptor'); 
     126        $this->preInterceptors[]            = new MockPreInterceptor(); 
    62127        $this->preInterceptors[]            = new MockSerializableInterceptor(); 
    63128        $this->postInterceptors[]           = new MockSerializableInterceptor(); 
    64         $this->postInterceptors[]           = new MockstubPostInterceptor(); 
    65         $this->postInterceptors[1]->setReturnValue('getClassName', 'MockstubPostInterceptor'); 
     129        $this->postInterceptors[]           = new MockPostInterceptor(); 
    66130    } 
    67131 
    68132    /** 
    69133     * test descriptor 
     134     * 
     135     * @test 
    70136     */ 
    71     public function testDescriptor() 
     137    public function descriptor() 
    72138    { 
    73         $this->assertEqual($this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_CONFIG), 'interceptors'); 
    74         $this->assertEqual($this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_DEFINITION), 'interceptors'); 
     139        $this->assertEquals('interceptors', $this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_CONFIG)); 
     140        $this->assertEquals('interceptors', $this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_DEFINITION)); 
    75141        $this->interceptorXJConfInitializer->setDescriptor('foo'); 
    76         $this->assertEqual($this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_CONFIG), 'foo'); 
    77         $this->assertEqual($this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_DEFINITION), 'interceptors'); 
    78         $this->expectException('stubIllegalArgumentException'); 
     142        $this->assertEquals('foo', $this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_CONFIG)); 
     143        $this->assertEquals('interceptors', $this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_DEFINITION)); 
     144    } 
     145 
     146    /** 
     147     * test descriptor 
     148     * 
     149     * @test 
     150     * @expectedException  stubIllegalArgumentException 
     151     */ 
     152    public function descriptorWrongArgument() 
     153    { 
    79154        $this->interceptorXJConfInitializer->getDescriptor('bar'); 
    80155    } 
     
    82157    /** 
    83158     * check that the cache data is correct 
     159     * 
     160     * @test 
    84161     */ 
    85     public function testGetCacheData() 
     162    public function getCacheData() 
    86163    { 
    87164        $this->interceptorXJConfInitializer->setPreInterceptors($this->preInterceptors); 
    88165        $this->interceptorXJConfInitializer->setPostInterceptors($this->postInterceptors); 
    89166        $cacheData = $this->interceptorXJConfInitializer->getCacheData(); 
    90         $this->assertEqual($cacheData['preInterceptors'][0], 'MockstubPreInterceptor'); 
    91         $this->assertIsA($cacheData['preInterceptors'][1], 'stubSerializedObject'); 
    92         $this->assertIsA($cacheData['postInterceptors'][0], 'stubSerializedObject'); 
    93         $this->assertEqual($cacheData['postInterceptors'][1], 'MockstubPostInterceptor'); 
     167        $this->assertEquals('MockPreInterceptor', $cacheData['preInterceptors'][0]); 
     168        $this->assertType('stubSerializedObject', $cacheData['preInterceptors'][1]); 
     169        $this->assertType('stubSerializedObject', $cacheData['postInterceptors'][0]); 
     170        $this->assertEquals('MockPostInterceptor', $cacheData['postInterceptors'][1]); 
    94171         
    95172    } 
     
    97174    /** 
    98175     * check that cache data is used correct 
     176     * 
     177     * @test 
    99178     */ 
    100     public function testSetCacheData() 
     179    public function setCacheData() 
    101180    { 
    102         $cacheData['preInterceptors'][0]  = 'MockstubPreInterceptor'; 
     181        $cacheData['preInterceptors'][0]  = 'MockPreInterceptor'; 
    103182        $cacheData['preInterceptors'][1]  = $this->preInterceptors[1]->getSerialized(); 
    104183        $cacheData['postInterceptors'][0] = $this->postInterceptors[0]->getSerialized(); 
    105         $cacheData['postInterceptors'][1] = 'MockstubPostInterceptor'; 
     184        $cacheData['postInterceptors'][1] = 'MockPostInterceptor'; 
    106185        $this->interceptorXJConfInitializer->setCacheData($cacheData); 
    107186        $preInterceptors = $this->interceptorXJConfInitializer->getPreInterceptors(); 
    108         $this->assertIsA($preInterceptors[0], 'MockstubPreInterceptor'); 
    109         $this->assertIsA($preInterceptors[1], 'MockSerializableInterceptor'); 
     187        $this->assertType('MockPreInterceptor', $preInterceptors[0]); 
     188        $this->assertType('MockSerializableInterceptor', $preInterceptors[1]); 
    110189        $postInterceptors = $this->interceptorXJConfInitializer->getPostInterceptors(); 
    111         $this->assertIsA($postInterceptors[0], 'MockSerializableInterceptor'); 
    112         $this->assertIsA($postInterceptors[1], 'MockstubPostInterceptor'); 
     190        $this->assertType('MockSerializableInterceptor', $postInterceptors[0]); 
     191        $this->assertType('MockPostInterceptor', $postInterceptors[1]); 
    113192    } 
    114193} 
  • trunk/src/test/php/net/stubbles/ipo/response/stubCookieTestCase.php

    r1223 r1272  
    11<?php 
    22/** 
    3  * Tests for net::stubbles::ipo.response::stubCooki 
     3 * Tests for net::stubbles::ipo.response::stubCookie. 
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
    66 * @package     stubbles 
    7  * @subpackage  ipo_test 
     7 * @subpackage  ipo_response_test 
    88 */ 
    99stubClassLoader::load('net::stubbles::ipo.response::stubCookie'); 
    1010/** 
    11  * Tests for net::stubbles::ipo.response::stubCooki 
     11 * Tests for net::stubbles::ipo.response::stubCookie. 
    1212 * 
    1313 * @package     stubbles 
    14  * @subpackage  ipo_test 
     14 * @subpackage  ipo_response_test 
    1515 */ 
    16 class stubCookieTestCase extends UnitTestCase 
     16class stubCookieTestCase extends PHPUnit_Framework_TestCase 
    1717{ 
    1818    /** 
    1919     * test with default values 
     20     * 
     21     * @test 
    2022     */ 
    21     public function testValuesDefault() 
     23    public function defaultValues() 
    2224    { 
    2325        $cookie = stubCookie::create('foo', 'bar'); 
    24         $this->assertEqual($cookie->getName(), 'foo'); 
    25         $this->assertEqual($cookie->getValue(), 'bar'); 
    26         $this->assertEqual($cookie->getExpiration(), 0); 
     26        $this->assertEquals('foo', $cookie->getName()); 
     27        $this->assertEquals('bar', $cookie->getValue()); 
     28        $this->assertEquals(0, $cookie->getExpiration()); 
    2729        $this->assertNull($cookie->getPath()); 
    2830        $this->assertNull($cookie->getDomain()); 
     
    3335    /** 
    3436     * test that values are returned as expected 
     37     * 
     38     * @test 
    3539     */ 
    36     public function testValuesSet() 
     40    public function valuesSet() 
    3741    { 
    3842        $cookie = stubCookie::create('foo', 'bar')->expiringAt(100) 
     
    4145                                                  ->withSecurity(true) 
    4246                                                  ->usingHttpOnly(true); 
    43         $this->assertEqual($cookie->getName(), 'foo'); 
    44         $this->assertEqual($cookie->getValue(), 'bar'); 
    45         $this->assertEqual($cookie->getExpiration(), 100); 
    46         $this->assertEqual($cookie->getPath(), 'bar'); 
    47         $this->assertEqual($cookie->getDomain(), '.example.org'); 
     47        $this->assertEquals('foo', $cookie->getName()); 
     48        $this->assertEquals('bar', $cookie->getValue()); 
     49        $this->assertEquals(100, $cookie->getExpiration()); 
     50        $this->assertEquals('bar', $cookie->getPath()); 
     51        $this->assertEquals('.example.org', $cookie->getDomain()); 
    4852        $this->assertTrue($cookie->isSecure()); 
    4953        $this->assertTrue($cookie->isHttpOnly()); 
  • trunk/src/test/php/net/stubbles/ipo/response/stubDecoratedResponseTestCase.php

    r1223 r1272  
    88 */ 
    99stubClassLoader::load('net::stubbles::ipo::response::stubDecoratedResponse'); 
    10 Mock::generate('stubResponse'); 
    1110/** 
    1211 * Tests for net::stubbles::ipo::response::stubDecoratedResponse. 
     
    1514 * @subpackage  ipo_response_test 
    1615 */ 
    17 class stubDecoratedResponseTestCase extends UnitTestCase 
     16class stubDecoratedResponseTestCase extends PHPUnit_Framework_TestCase 
    1817{ 
    1918    /** 
     
    2625     * mocked response instance 
    2726     * 
    28      * @var  SimpleMock 
     27     * @var  PHPUnit_Framework_MockObject_MockObject 
    2928     */ 
    3029    protected $mockResponse; 
     
    3534    public function setUp() 
    3635    { 
    37         $this->mockResponse       = new MockstubResponse(); 
     36        $this->mockResponse       = $this->getMock('stubResponse'); 
    3837        $this->decoratedResponse  = new stubDecoratedResponse($this->mockResponse); 
    3938    } 
     
    4140    /** 
    4241     * assure that all methods of the decorated response are called correct 
     42     * 
     43     * @test 
    4344     */ 
    44     public function testPassthru() 
     45    public function passthru() 
    4546    { 
    46         $this->mockResponse->expectOnce('clear'); 
    47         $this->mockResponse->expectOnce('addHeader', array('name', 'value')); 
    48         $this->mockResponse->expectOnce('getHeaders'); 
    49         $this->mockResponse->setReturnValue('getHeaders', array('name' => 'value')); 
     47        $this->mockResponse->expects($this->once())->method('clear'); 
     48        $this->mockResponse->expects($this->once())->method('addHeader')->with($this->equalTo('name'), $this->equalTo('value')); 
     49        $this->mockResponse->expects($this->once())->method('getHeaders')->will($this->returnValue(array('name' => 'value'))); 
    5050        $cookie = stubCookie::create('name', 'value'); 
    51         $this->mockResponse->expectOnce('setCookie', array($cookie)); 
    52         $this->mockResponse->expectOnce('getCookies'); 
    53         $this->mockResponse->setReturnValue('getCookies', array('name' => $cookie)); 
    54         $this->mockResponse->expectOnce('write', array('data')); 
    55         $this->mockResponse->expectOnce('getData'); 
    56         $this->mockResponse->setReturnValue('getData', 'data'); 
    57         $this->mockResponse->expectOnce('replaceData', array('data')); 
    58         $this->mockResponse->expectOnce('send'); 
     51        $this->mockResponse->expects($this->once())->method('setCookie', array($cookie)); 
     52        $this->mockResponse->expects($this->once())->method('getCookies')->will($this->returnValue(array('name' => $cookie))); 
     53        $this->mockResponse->expects($this->once())->method('write', array('data')); 
     54        $this->mockResponse->expects($this->once())->method('getData')->will($this->returnValue('data')); 
     55        $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('data')); 
     56        $this->mockResponse->expects($this->once())->method('send'); 
    5957        $this->decoratedResponse->clear(); 
    6058        $this->decoratedResponse->addHeader('name', 'value'); 
    61         $this->assertEqual($this->decoratedResponse->getHeaders(), array('name' => 'value')); 
     59        $this->assertEquals(array('name' => 'value'), $this->decoratedResponse->getHeaders()); 
    6260        $this->decoratedResponse->setCookie($cookie); 
    63         $this->assertEqual($this->decoratedResponse->getCookies(), array('name' => $cookie)); 
     61        $this->assertEquals(array('name' => $cookie), $this->decoratedResponse->getCookies()); 
    6462        $this->decoratedResponse->write('data'); 
    65         $this->assertEqual($this->decoratedResponse->getData(), 'data'); 
     63        $this->assertEquals('data', $this->decoratedResponse->getData()); 
    6664        $this->decoratedResponse->replaceData('data'); 
    6765        $this->decoratedResponse->send(); 
  • trunk/src/test/php/net/stubbles/ipo/session/resourcemanager/stubSessionResourceManagerTestCase.php

    r1223 r1272  
    55 * @author      Stephan Schmidt <schst@stubbles.net> 
    66 * @package     stubbles 
    7  * @subpackage  ipo_session_test 
     7 * @subpackage  ipo_session_resourcemanager_test 
    88 */ 
    99stubClassLoader::load('net::stubbles::ipo::session::stubNoneDurableSession', 
    10                       'net::stubbles::ipo::session::resourcemanager::stubSessionResourceManager'); 
    11 Mock::generate('stubRequest'); 
    12  
     10                      'net::stubbles::ipo::session::resourcemanager::stubSessionResourceManager' 
     11); 
    1312/** 
    1413 * Session resource interface 
     
    6362 * 
    6463 * @package     stubbles 
    65  * @subpackage  ipo_session_test 
    66  */ 
    67 class stubSessionResourceManagerTestCase extends UnitTestCase 
     64 * @subpackage  ipo_session_resourcemanager_test 
     65 */ 
     66class stubSessionResourceManagerTestCase extends PHPUnit_Framework_TestCase 
    6867{ 
    6968    /** 
     69     * instance to test 
     70     * 
     71     * @var  stubSessionResourceManager 
     72     */ 
     73    protected $resourceManager; 
     74    /** 
     75     * session instance to be used 
     76     * 
     77     * @var  stubNoneDurableSession 
     78     */ 
     79    protected $session; 
     80 
     81    /** 
    7082     * set up test environment 
    7183     */ 
    7284    public function setUp() 
    7385    { 
     86        $this->session         = new stubNoneDurableSession($this->getMock('stubRequest'), 'test'); 
     87        $this->resourceManager = new stubSessionResourceManager($this->session); 
    7488    } 
    7589 
    7690    /** 
    7791     * Test fetching a resource via string 
    78      */ 
    79     public function testGetResourceByString() 
    80     { 
    81         $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 
    82         $manager = new stubSessionResourceManager($session); 
    83  
    84         $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
    85  
    86         $resource = $manager->getResource('stubSessionResourceManagerTestCase_MyResource'); 
    87         $this->assertIsA($resource, 'stubSessionResource'); 
    88         $this->assertIsA($resource, 'stubSessionResourceManagerTestCase_MyResource'); 
     92     * 
     93     * @test 
     94     */ 
     95    public function getResourceByString() 
     96    { 
     97        $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
     98        $resource = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource'); 
     99        $this->assertType('stubSessionResource', $resource); 
     100        $this->assertType('stubSessionResourceManagerTestCase_MyResource', $resource); 
    89101    } 
    90102 
    91103    /** 
    92104     * Test fetching a resource via clazz 
    93      */ 
    94     public function testGetResourceByClazz() 
    95     { 
    96         $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 
    97         $manager = new stubSessionResourceManager($session); 
    98  
    99         $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
    100  
    101         $resource = $manager->getResource(new stubReflectionClass('stubSessionResourceManagerTestCase_MyResource')); 
    102         $this->assertIsA($resource, 'stubSessionResource'); 
    103         $this->assertIsA($resource, 'stubSessionResourceManagerTestCase_MyResource'); 
     105     * 
     106     * @test 
     107     */ 
     108    public function getResourceByClazz() 
     109    { 
     110        $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
     111        $resource = $this->resourceManager->getResource(new stubReflectionClass('stubSessionResourceManagerTestCase_MyResource')); 
     112        $this->assertType('stubSessionResource', $resource); 
     113        $this->assertType('stubSessionResourceManagerTestCase_MyResource', $resource); 
    104114    } 
    105115 
    106116    /** 
    107117     * Test that always the same object is returned 
    108      */ 
    109     public function testGetResourceIdentical() 
    110     { 
    111         $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 
    112         $manager = new stubSessionResourceManager($session); 
    113  
    114         $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
    115  
    116         $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResource'); 
    117         $resource2 = $manager->getResource(new stubReflectionClass('stubSessionResourceManagerTestCase_MyResource')); 
    118         $this->assertIdentical($resource1, $resource2); 
     118     * 
     119     * @test 
     120     */ 
     121    public function getResourceIdentical() 
     122    { 
     123        $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
     124        $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource'); 
     125        $resource2 = $this->resourceManager->getResource(new stubReflectionClass('stubSessionResourceManagerTestCase_MyResource')); 
     126        $this->identicalTo($resource1, $resource2); 
    119127    } 
    120128 
    121129    /** 
    122130     * Test that always the same object is returned 
    123      */ 
    124     public function testGetResourceTwoInterfacesIdentical() 
    125     { 
    126         $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 
    127         $manager = new stubSessionResourceManager($session); 
    128  
    129         $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource', 'stubSessionResourceManagerTestCase_MyResource2')); 
    130  
    131         $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResource'); 
    132         $resource2 = $manager->getResource('stubSessionResourceManagerTestCase_MyResource2'); 
    133         $this->assertIdentical($resource1, $resource2); 
     131     * 
     132     * @test 
     133     */ 
     134    public function getResourceTwoInterfacesIdentical() 
     135    { 
     136        $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource', 'stubSessionResourceManagerTestCase_MyResource2')); 
     137        $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource'); 
     138        $resource2 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource2'); 
     139        $this->identicalTo($resource1, $resource2); 
    134140    } 
    135141 
    136142    /** 
    137143     * Test that an exception occurs, if the interface does not exist 
    138      */ 
    139     public function testGetResourceInterfaceNotExists() 
    140     { 
    141         $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 
    142         $manager = new stubSessionResourceManager($session); 
    143  
    144         $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
    145  
    146         $this->expectException('ReflectionException'); 
    147         $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResourceFoo'); 
     144     * 
     145     * @test 
     146     * @expectedException  ReflectionException 
     147     */ 
     148    public function getResourceInterfaceNotExists() 
     149    { 
     150        $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
     151        $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResourceFoo'); 
    148152    } 
    149153 
    150154    /** 
    151155     * Test that an exception occurs, if a class instead of interface has been passed 
    152      */ 
    153     public function testGetResourceNoInterface() 
    154     { 
    155         $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 
    156         $manager = new stubSessionResourceManager($session); 
    157  
    158         $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
    159  
    160         $this->expectException('stubIllegalArgumentException'); 
    161         $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResourceImpl'); 
     156     * 
     157     * @test 
     158     * @expectedException  stubIllegalArgumentException 
     159     */ 
     160    public function getResourceNoInterface() 
     161    { 
     162        $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
     163        $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResourceImpl'); 
    162164    } 
    163165 
    164166    /** 
    165167     * Test that an exception occurs, if a interfaces, that does not extend session resource has been passed 
    166      */ 
    167     public function testGetResourceNoSessionResource() 
    168     { 
    169         $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 
    170         $manager = new stubSessionResourceManager($session); 
    171  
    172         $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
    173  
    174         $this->expectException('stubIllegalArgumentException'); 
    175         $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResourceInvalid'); 
     168     * 
     169     * @test 
     170     * @expectedException  stubIllegalArgumentException 
     171     */ 
     172    public function getResourceNoSessionResource() 
     173    { 
     174        $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
     175        $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResourceInvalid'); 
    176176    } 
    177177 
    178178    /** 
    179179     * Test that an exception occurs, if a class instead of interface has been passed 
    180      */ 
    181     public function testGetResourceNotDefined() 
    182     { 
    183         $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 
    184         $manager = new stubSessionResourceManager($session); 
    185  
    186         $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
    187  
    188         $this->expectException('stubIllegalArgumentException'); 
    189         $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResource2'); 
     180     * 
     181     * @test 
     182     * @expectedException  stubIllegalArgumentException 
     183     */ 
     184    public function getResourceNotDefined() 
     185    { 
     186        $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 
     187        $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource2'); 
    190188    } 
    191189 
    192190    /** 
    193191     * Test that an exception occurs, if a class does not implement the specified interface 
    194      */ 
    195     public function testGetResourceWrongInterface() 
    196     { 
    197         $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 
    198         $manager = new stubSessionResourceManager($session); 
    199  
    200         $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource3')); 
    201  
    202         $this->expectException('stubConfigurationException'); 
    203         $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResource3'); 
     192     * 
     193     * @test 
     194     * @expectedException  stubConfigurationException 
     195     */ 
     196    public function getResourceWrongInterface() 
     197    { 
     198        $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource3')); 
     199        $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource3'); 
    204200    } 
    205201} 
  • trunk/src/test/php/net/stubbles/ipo/session/stubAbstractSessionTestCase.php

    r1223 r1272  
    88 */ 
    99stubClassLoader::load('net::stubbles::ipo::session::stubAbstractSession'); 
    10 Mock::generate('stubRequest'); 
    11 Mock::generate('stubSerializable'); 
    1210class stubTestSession extends stubAbstractSession 
    1311{ 
     
    5755 * @subpackage  ipo_session_test 
    5856 */ 
    59 class stubAbstractSessionTestCase extends UnitTestCase 
     57class stubAbstractSessionTestCase extends PHPUnit_Framework_TestCase 
    6058{ 
    6159    /** 
     
    7169    public function setUp() 
    7270    { 
    73         $this->session = new stubTestSession(new MockstubRequest(), 'foo'); 
     71        $this->session = new stubTestSession($this->getMock('stubRequest'), 'foo'); 
    7472    } 
    7573 
    7674    /** 
    7775     * test with default values 
    78      */ 
    79     public function testDefaultValues() 
    80     { 
    81         $this->assertEqual($this->session->getName(), 'foo'); 
     76     * 
     77     * @test 
     78     */ 
     79    public function defaultValues() 
     80    { 
     81        $this->assertEquals('foo', $this->session->getName()); 
    8282        $this->assertTrue($this->session->hasValue(stubSession::START_TIME)); 
    8383        $startTime = $this->session->getStartTime(); 
    84         $this->assertEqual($this->session->getValue(stubSession::FINGERPRINT), 'foobarbaz'); 
     84        $this->assertEquals('foobarbaz', $this->session->getValue(stubSession::FINGERPRINT)); 
    8585        $this->assertTrue($this->session->hasValue(stubSession::NEXT_TOKEN)); 
    8686        $this->assertTrue($this->session->isNew()); 
     
    8888        $nextToken = $this->session->getNextToken(); 
    8989         
    90         $this->session = new stubTestSession(new MockstubRequest(), $startTime . '|foobarbaz|' . $nextToken); 
    91         $this->assertEqual($this->session->getStartTime(), $startTime); 
     90        $this->session = new stubTestSession($this->getMock('stubRequest'), $startTime . '|foobarbaz|' . $nextToken); 
     91        $this->assertEquals($startTime, $this->session->getStartTime()); 
    9292        $this->assertFalse($this->session->isNew()); 
    93         $this->assertEqual($nextToken, $this->session->getCurrentToken()); 
     93        $this->assertEquals($nextToken, $this->session->getCurrentToken()); 
    9494        $this->assertTrue($this->session->isValid()); 
    9595    } 
     
    9797    /** 
    9898     * test that an invalid sesssion throws an exception 
    99      */ 
    100     public function testInvalidGetStartTime() 
    101     { 
    102         $this->session->invalidate(); 
    103         $this->assertFalse($this->session->isValid()); 
    104         $this->expectException('stubSessionException'); 
     99     * 
     100     * @test 
     101     * @expectedException  stubSessionException 
     102     */ 
     103    public function invalidGetStartTime() 
     104    { 
     105        $this->session->invalidate(); 
     106        $this->assertFalse($this->session->isValid()); 
    105107        $this->session->getStartTime(); 
    106108    } 
     
    108110    /** 
    109111     * test that an invalid sesssion throws an exception 
    110      */ 
    111     public function testInvalidGetValue() 
    112     { 
    113         $this->session->invalidate(); 
    114         $this->assertFalse($this->session->isValid()); 
    115         $this->expectException('stubSessionException'); 
     112     * 
     113     * @test 
     114     * @expectedException  stubSessionException 
     115     */ 
     116    public function invalidGetValue() 
     117    { 
     118        $this->session->invalidate(); 
     119        $this->assertFalse($this->session->isValid()); 
    116120        $this->session->getValue('foo'); 
    117121    } 
     
    119123    /** 
    120124     * test that an invalid sesssion throws an exception 
    121      */ 
    122     public function testInvalidRemoveValue() 
    123     { 
    124         $this->session->invalidate(); 
    125         $this->assertFalse($this->session->isValid()); 
    126         $this->expectException('stubSessionException'); 
     125     * 
     126     * @test 
     127     * @expectedException  stubSessionException 
     128     */ 
     129    public function invalidRemoveValue() 
     130    { 
     131        $this->session->invalidate(); 
     132        $this->assertFalse($this->session->isValid()); 
    127133        $this->session->removeValue('foo'); 
    128134    } 
     
    130136    /** 
    131137     * test that an invalid sesssion throws an exception 
    132      */ 
    133     public function testInvalidGetValueKeys() 
    134     { 
    135         $this->session->invalidate(); 
    136         $this->assertFalse($this->session->isValid()); 
    137         $this->expectException('stubSessionException'); 
     138     * 
     139     * @test 
     140     * @expectedException  stubSessionException 
     141     */ 
     142    public function invalidGetValueKeys() 
     143    { 
     144        $this->session->invalidate(); 
     145        $this->assertFalse($this->session->isValid()); 
    138146        $this->session->getValueKeys(); 
    139147    } 
     
    141149    /** 
    142150     * test getting a value from session 
    143      */ 
    144     public function testGetValue() 
     151     * 
     152     * @test 
     153     */ 
     154    public function getValue() 
    145155    { 
    146156        $this->assertNull($this->session->getValue('foo')); 
    147         $this->assertEqual($this->session->getValue('foo', 'bar'), 'bar'); 
     157        $this->assertEquals('bar', $this->session->getValue('foo', 'bar')); 
    148158        $this->session->putValue('foo', 'baz'); 
    149         $this->assertEqual($this->session->getValue('foo'), 'baz'); 
    150         $this->assertEqual($this->session->getValue('foo', 'bar'), 'baz'); 
     159        $this->assertEquals('baz', $this->session->getValue('foo')); 
     160        $this->assertEquals('baz', $this->session->getValue('foo', 'bar')); 
    151161    } 
    152162     
    153163    /** 
    154164     * test removing a value from session 
    155      */ 
    156     public function testRemoveValue() 
     165     * 
     166     * @test 
     167     */ 
     168    public function removeValue() 
    157169    { 
    158170        $this->assertFalse($this->session->removeValue('foo')); 
     
    166178    /** 
    167179     * assure that no session fixation is possible 
    168      */ 
    169     public function testSessionFixation() 
     180     * 
     181     * @test 
     182     */ 
     183    public function sessionFixation() 
    170184    { 
    171185        // session id is always regenerated for new sessions 
    172         $this->assertEqual($this->session->getId(), 'foo'); 
     186        $this->assertEquals('foo', $this->session->getId()); 
    173187    } 
    174188     
    175189    /** 
    176190     * assure that no session hijacking is possible 
    177      */ 
    178     public function testSessionHijacking() 
     191     * 
     192     * @test 
     193     */ 
     194    public function sessionHijacking() 
    179195    { 
    180196        // original session started at 50 with fingerprint blub 
    181         $this->session = new stubTestSession(new MockstubRequest(), '50|blub|dummy'); 
     197        $this->session = new stubTestSession($this->getMock('stubRequest'), '50|blub|dummy'); 
    182198        $this->assertTrue($this->session->isNew()); 
    183         $this->assertNotEqual($this->session->getStartTime(), 50); 
    184         $this->assertNotEqual($this->session->getCurrentToken(),'dummy'); 
     199        $this->assertNotEquals(50, $this->session->getStartTime()); 
     200        $this->assertNotEquals('dummy', $this->session->getCurrentToken()); 
    185201