Changeset 1235

Show
Ignore:
Timestamp:
01/13/08 22:42:50 (8 months ago)
Author:
mikey
Message:

started refactoring #118: switch unit tests from SimpleTest? to PHPUnit
This adds a new target to out build file, test-new, which will run all converted tests. Converted tests include until now net::stubbles::auth, net::stubbles::events and net::stubbles:ioc. The test-new target will be replace the old test target when the conversion of all tests is finished.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build.xml

    r1152 r1235  
    3737      <else> 
    3838        <phing phingfile="${build.base.dir}/stubbles/build.xml" target="test" /> 
     39      </else> 
     40    </if> 
     41  </target> 
     42 
     43  <target name="test-new" description="run test suite"> 
     44    <if> 
     45      <isset property="package" /> 
     46      <then> 
     47        <phing phingfile="${build.base.dir}/${package}/build.xml" target="test-new" /> 
     48      </then> 
     49      <else> 
     50        <phing phingfile="${build.base.dir}/stubbles/build.xml" target="test-new" /> 
    3951      </else> 
    4052    </if> 
  • trunk/build/stubbles/build.xml

    r1218 r1235  
    22<project name="stubbles" default="main"> 
    33  <property name="build.base.dir" value="${stubbles.base.dir}/build/stubbles/build" override="true"/> 
     4  <property name="build.report.dir" value="${stubbles.base.dir}/build/stubbles/reports" override="true"/> 
    45  <property name="pkg.dir" value="${stubbles.base.dir}/src/main/php/net/stubbles" /> 
    56  <property name="pkg.name" value="stubbles-${version}"/> 
     
    217218  </target> 
    218219 
     220  <target name="test-new" description="run test suite"> 
     221    <delete> 
     222      <fileset dir="${build.report.dir}"> 
     223        <include name="**"/> 
     224      </fileset> 
     225    </delete> 
     226    <phingcall target="test-preparation" /> 
     227    <exec passthru="true" command="phpunit --log-metrics ${build.report.dir}/metrics.xml --log-pmd ${build.report.dir}/pmd.xml --coverage-html ${build.report.dir}/coverage src_test_AllTests"/> 
     228  </target> 
     229 
    219230  <target name="test-integration"> 
    220231    <phingcall target="test-preparation" /> 
  • trunk/src/main/php/net/stubbles/auth/strategy/stubAuthFailOverStrategy.php

    r1209 r1235  
    3636            $result = $authenticator->authenticate($credentials); 
    3737            if ($result->getStatus() != stubAuthResult::STATUS_AUTHENTICATOR_FAILURE) { 
    38                 break
     38                return $result
    3939            } 
    4040        } 
  • trunk/src/main/php/net/stubbles/auth/strategy/stubAuthOrStrategy.php

    r1209 r1235  
    3232            $result = $authenticator->authenticate($credentials); 
    3333            if ($result->getStatus() == stubAuthResult::STATUS_SUCCESS) { 
    34                 break
     34                return $result
    3535            } 
    3636        } 
  • trunk/src/main/php/net/stubbles/stubClassLoader.php

    r1214 r1235  
    212212            } 
    213213 
    214             if ((include_once $uri) === false) { 
     214            if ((@include_once $uri) === false) { 
    215215                throw new stubClassNotFoundException($fqClassName); 
    216216            } 
  • trunk/src/test/php/net/stubbles/auth/AuthTestSuite.php

    r756 r1235  
    1313 * @subpackage  test 
    1414 */ 
    15 class AuthTestSuite extends TestSuite 
     15class AuthTestSuite 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 auth tests'); 
    24         $this->addTestFile($dir . '/stubAuthTestCase.php'); 
    25         $this->addTestFile($dir . '/storage/stubAuthSessionStorageTestCase.php'); 
    26         $this->addTestFile($dir . '/strategy/stubAuthFailOverStrategyTestCase.php'); 
    27         $this->addTestFile($dir . '/strategy/stubAuthOrStrategyTestCase.php'); 
     24        $suite = new self(); 
     25        $dir   = dirname(__FILE__); 
     26        $suite->addTestFile($dir . '/stubAuthTestCase.php'); 
     27        $suite->addTestFile($dir . '/storage/stubAuthSessionStorageTestCase.php'); 
     28        $suite->addTestFile($dir . '/strategy/stubAuthFailOverStrategyTestCase.php'); 
     29        $suite->addTestFile($dir . '/strategy/stubAuthOrStrategyTestCase.php'); 
     30        return $suite; 
    2831    } 
    2932} 
  • trunk/src/test/php/net/stubbles/auth/storage/stubAuthSessionStorageTestCase.php

    r1209 r1235  
    88 */ 
    99stubClassLoader::load('net::stubbles::auth::storage::stubAuthSessionStorage'); 
    10 Mock::generate('stubSession'); 
    1110/** 
    1211 * Tests for net::stubbles::auth::storage::stubAuthSessionStorage. 
     
    1514 * @subpackage  auth_storage_test 
    1615 */ 
    17 class stubAuthSessionStorageTestCase extends UnitTestCase 
     16class stubAuthSessionStorageTestCase extends PHPUnit_Framework_TestCase 
    1817{ 
    1918    /** 
     
    2625     * a mocked session 
    2726     * 
    28      * @var  SimpleMock 
     27     * @var  PHPUnit_Framework_MockObject_MockObject 
    2928     */ 
    3029    protected $session; 
     
    3534    public function setup() 
    3635    { 
    37         $this->session = new MockstubSession(); 
     36        $this->session = $this->getMock('stubSession'); 
    3837        $this->storage = new stubAuthSessionStorage($this->session); 
    3938    } 
     
    4140    /** 
    4241     * assure that validity of storage works as expected 
     42     * 
     43     * @test 
    4344     */ 
    44     public function testIsValid() 
     45    public function isValidWhenAuthResultIsSuccessAndTimeoutNotReached() 
    4546    { 
    4647        $authResult1 = new stubAuthResult(stubAuthResult::STATUS_CREDENTIALS_INVALID, 'foo'); 
    4748        $authResult2 = new stubAuthResult(stubAuthResult::STATUS_SUCCESS, 'foo'); 
    48         $this->session->setReturnValueAt(0, 'getValue', null); 
    49         $this->session->setReturnValueAt(1, 'getValue', $authResult1); 
    50         $this->session->setReturnValueAt(2, 'getValue', $authResult2); 
    51         $this->session->setReturnValueAt(3, 'getValue', (time() - 3601)); 
    52         $this->session->setReturnValueAt(4, 'getValue', $authResult2); 
    53         $this->session->setReturnValueAt(5, 'getValue', (time() - 3600)); 
    54         $this->session->setReturnValueAt(6, 'getValue', $authResult2); 
    55         $this->session->setReturnValueAt(7, 'getValue', (time() - 3599)); 
     49        $this->session->expects($this->exactly(10)) 
     50                      ->method('getValue') 
     51                      ->will($this->onConsecutiveCalls(null, 
     52                                                       $authResult1, 
     53                                                       $authResult2, 
     54                                                       (time() - 3601), 
     55                                                       $authResult2, 
     56                                                       (time() - 3600), 
     57                                                       $authResult2, 
     58                                                       (time() - 3599), 
     59                                                       $authResult2, 
     60                                                       (time() - 3599) 
     61                             ) 
     62        ); 
    5663        $this->assertFalse($this->storage->isValid()); 
    5764        $this->assertFalse($this->storage->isValid()); 
     
    5966        $this->assertTrue($this->storage->isValid()); 
    6067        $this->assertTrue($this->storage->isValid()); 
     68        $this->storage->setTimeout(3598); 
     69        $this->assertFalse($this->storage->isValid()); 
    6170    } 
    6271 
    6372    /** 
    6473     * assure that session id is regenerated when setting new result 
     74     * 
     75     * @test 
    6576     */ 
    66     public function testSetResult() 
     77    public function setResult() 
    6778    { 
    68         $this->session->expectOnce('regenerateId'); 
     79        $this->session->expects($this->once())->method('regenerateId'); 
    6980        $authResult = new stubAuthResult(stubAuthResult::STATUS_CREDENTIALS_INVALID, 'foo'); 
    7081        $this->storage->setResult($authResult); 
     
    7384    /** 
    7485     * assure that session id is regenerated when clearing authentication result 
     86     * 
     87     * @test 
    7588     */ 
    76     public function testClear() 
     89    public function clear() 
    7790    { 
    78         $this->session->expectOnce('regenerateId'); 
     91        $this->session->expects($this->once())->method('regenerateId'); 
    7992        $this->storage->clear(); 
    8093    } 
     
    8295    /** 
    8396     * assure that retrieving the auth data works as expected 
     97     * 
     98     * @test 
    8499     */ 
    85     public function testGetAuthData() 
     100    public function getAuthData() 
    86101    { 
    87         $this->session->setReturnValueAt(0, 'getValue', null); 
    88102        $authResult = new stubAuthResult(stubAuthResult::STATUS_SUCCESS, 'foo', 'authData'); 
    89         $this->session->setReturnValueAt(1, 'getValue', $authResult); 
     103        $this->session->expects($this->exactly(2)) 
     104                      ->method('getValue') 
     105                      ->will($this->onConsecutiveCalls(null, $authResult)); 
    90106        $this->assertNull($this->storage->getAuthData()); 
    91         $this->assertEqual($this->storage->getAuthData(), 'authData'); 
     107        $this->assertEquals('authData', $this->storage->getAuthData()); 
    92108    } 
    93109} 
  • trunk/src/test/php/net/stubbles/auth/strategy/stubAuthFailOverStrategyTestCase.php

    r1209 r1235  
    2727    /** 
    2828     * assure that strategy works as expected 
     29     * 
     30     * @test 
    2931     */ 
    30     public function testSuccess() 
     32    public function success() 
    3133    { 
    3234        $authenticators = array($this->authenticatorSuccess, $this->authenticatorInvalid, $this->authenticatorFailure); 
    33         $this->authenticatorInvalid->expectNever('authenticate'); 
    34         $this->authenticatorFailure->expectNever('authenticate'); 
     35        $this->authenticatorInvalid->expects($this->never())->method('authenticate'); 
     36        $this->authenticatorFailure->expects($this->never())->method('authenticate'); 
    3537        $result = $this->strategy->authenticate($authenticators, 'foo'); 
    36         $this->assertReference($this->resultSuccess, $result); 
     38        $this->assertSame($this->resultSuccess, $result); 
    3739    } 
    3840 
    3941    /** 
    4042     * assure that strategy works as expected 
     43     * 
     44     * @test 
    4145     */ 
    42     public function testNoSuccess() 
     46    public function noSuccess() 
    4347    { 
    4448        $authenticators = array($this->authenticatorInvalid, $this->authenticatorSuccess, $this->authenticatorFailure); 
    45         $this->authenticatorSuccess->expectNever('authenticate'); 
    46         $this->authenticatorFailure->expectNever('authenticate'); 
     49        $this->authenticatorSuccess->expects($this->never())->method('authenticate'); 
     50        $this->authenticatorFailure->expects($this->never())->method('authenticate'); 
    4751        $result = $this->strategy->authenticate($authenticators, 'foo'); 
    48         $this->assertReference($this->resultInvalid, $result); 
     52        $this->assertSame($this->resultInvalid, $result); 
    4953    } 
    5054 
    5155    /** 
    5256     * assure that strategy works as expected 
     57     * 
     58     * @test 
    5359     */ 
    54     public function testFailoverWithSuccess() 
     60    public function failoverWithSuccess() 
    5561    { 
    5662        $authenticators = array($this->authenticatorFailure, $this->authenticatorSuccess, $this->authenticatorInvalid); 
    57         $this->authenticatorSuccess->expectOnce('authenticate'); 
    58         $this->authenticatorInvalid->expectNever('authenticate'); 
     63        $this->authenticatorSuccess->expects($this->once())->method('authenticate')->will($this->returnValue($this->resultSuccess)); 
     64        $this->authenticatorInvalid->expects($this->never())->method('authenticate'); 
    5965        $result = $this->strategy->authenticate($authenticators, 'foo'); 
    60         $this->assertReference($this->resultSuccess, $result); 
     66        $this->assertSame($this->resultSuccess, $result); 
    6167    } 
    6268 
    6369    /** 
    6470     * assure that strategy works as expected 
     71     * 
     72     * @test 
    6573     */ 
    66     public function testFailoverWithoutSuccess() 
     74    public function failoverWithoutSuccess() 
    6775    { 
    6876        $authenticators = array($this->authenticatorFailure, $this->authenticatorInvalid, $this->authenticatorSuccess); 
    69         $this->authenticatorInvalid->expectOnce('authenticate'); 
    70         $this->authenticatorSuccess->expectNever('authenticate'); 
     77        $this->authenticatorInvalid->expects($this->once())->method('authenticate')->will($this->returnValue($this->resultInvalid)); 
     78        $this->authenticatorSuccess->expects($this->never())->method('authenticate'); 
    7179        $result = $this->strategy->authenticate($authenticators, 'foo'); 
    72         $this->assertReference($this->resultInvalid, $result); 
     80        $this->assertSame($this->resultInvalid, $result); 
    7381    } 
    7482 
    7583    /** 
    7684     * assure that strategy works as expected 
     85     * 
     86     * @test 
    7787     */ 
    78     public function testFailoverOnly() 
     88    public function failoverOnly() 
    7989    { 
    8090        $authenticators = array($this->authenticatorFailure); 
    8191        $result = $this->strategy->authenticate($authenticators, 'foo'); 
    82         $this->assertReference($this->resultFailure, $result); 
     92        $this->assertSame($this->resultFailure, $result); 
    8393    } 
    8494} 
  • trunk/src/test/php/net/stubbles/auth/strategy/stubAuthOrStrategyTestCase.php

    r1209 r1235  
    2727    /** 
    2828     * assure that strategy works as expected 
     29     * 
     30     * @test 
    2931     */ 
    30     public function testSuccess() 
     32    public function success() 
    3133    { 
    3234        $authenticators = array($this->authenticatorSuccess, $this->authenticatorInvalid, $this->authenticatorFailure); 
    33         $this->authenticatorInvalid->expectNever('authenticate'); 
    34         $this->authenticatorFailure->expectNever('authenticate'); 
     35        $this->authenticatorInvalid->expects($this->never())->method('authenticate'); 
     36        $this->authenticatorFailure->expects($this->never())->method('authenticate'); 
    3537        $result = $this->strategy->authenticate($authenticators, 'foo'); 
    36         $this->assertReference($this->resultSuccess, $result); 
     38        $this->assertSame($this->resultSuccess, $result); 
    3739    } 
    3840 
    3941    /** 
    4042     * assure that strategy works as expected 
     43     * 
     44     * @test 
    4145     */ 
    42     public function testNoSuccess() 
     46    public function noSuccess() 
    4347    { 
    4448        $authenticators = array($this->authenticatorInvalid, $this->authenticatorFailure); 
    45         $this->authenticatorInvalid->expectOnce('authenticate'); 
    46         $this->authenticatorFailure->expectOnce('authenticate'); 
     49        $this->authenticatorInvalid->expects($this->once())->method('authenticate')->will($this->returnValue($this->resultInvalid)); 
     50        $this->authenticatorFailure->expects($this->once())->method('authenticate')->will($this->returnValue($this->resultFailure)); 
    4751        $result = $this->strategy->authenticate($authenticators, 'foo'); 
    48         $this->assertReference($this->resultFailure, $result); 
     52        $this->assertSame($this->resultFailure, $result); 
    4953    } 
    5054} 
  • trunk/src/test/php/net/stubbles/auth/strategy/stubAuthStrategyBaseTestCase.php

    r1209 r1235  
    88 */ 
    99stubClassLoader::load('net::stubbles::auth::strategy::stubAuthOrStrategy'); 
    10 Mock::generate('stubAuthenticator'); 
    1110/** 
    1211 * Base test case for net::stubbles::auth::strategy::stubAuth*Strategy. 
     
    1514 * @subpackage  auth_strategy_test 
    1615 */ 
    17 abstract class stubAuthStrategyBaseTestCase extends UnitTestCase 
     16abstract class stubAuthStrategyBaseTestCase extends PHPUnit_Framework_TestCase 
    1817{ 
    1918    /** 
     
    4443     * mocked authenticator who succeeds 
    4544     * 
    46      * @var  SimpleMock 
     45     * @var  PHPUnit_Framework_MockObject_MockObject 
    4746     */ 
    4847    protected $authenticatorSuccess; 
     
    5049     * mocked authenticator who stumbles accross invalid credentials 
    5150     * 
    52      * @var  SimpleMock 
     51     * @var  PHPUnit_Framework_MockObject_MockObject 
    5352     */ 
    5453    protected $authenticatorInvalid; 
     
    5655     * mocked authenticator who fails 
    5756     * 
    58      * @var  SimpleMock 
     57     * @var  PHPUnit_Framework_MockObject_MockObject 
    5958     */ 
    6059    protected $authenticatorFailure; 
     
    6968        $this->resultInvalid        = new stubAuthResult(stubAuthResult::STATUS_CREDENTIALS_INVALID, 'foo'); 
    7069        $this->resultFailure        = new stubAuthResult(stubAuthResult::STATUS_AUTHENTICATOR_FAILURE, 'foo'); 
    71         $this->authenticatorSuccess = new MockstubAuthenticator(); 
    72         $this->authenticatorSuccess->setReturnValue('authenticate', $this->resultSuccess); 
    73         $this->authenticatorInvalid = new MockstubAuthenticator(); 
    74         $this->authenticatorInvalid->setReturnValue('authenticate', $this->resultInvalid); 
    75         $this->authenticatorFailure = new MockstubAuthenticator(); 
    76         $this->authenticatorFailure->setReturnValue('authenticate', $this->resultFailure); 
     70        $this->authenticatorSuccess = $this->getMock('stubAuthenticator'); 
     71        $this->authenticatorSuccess->expects($this->any()) 
     72                                   ->method('authenticate') 
     73                                   ->will($this->returnValue($this->resultSuccess)); 
     74        $this->authenticatorInvalid = $this->getMock('stubAuthenticator'); 
     75        $this->authenticatorInvalid->expects($this->any()) 
     76                                   ->method('authenticate') 
     77                                   ->will($this->returnValue($this->resultInvalid)); 
     78        $this->authenticatorFailure = $this->getMock('stubAuthenticator'); 
     79        $this->authenticatorFailure->expects($this->any()) 
     80                                   ->method('authenticate') 
     81                                   ->will($this->returnValue($this->resultFailure)); 
    7782    } 
    7883     
  • trunk/src/test/php/net/stubbles/auth/stubAuthTestCase.php

    r1209 r1235  
    88 */ 
    99stubClassLoader::load('net::stubbles::auth::stubAuth'); 
    10 Mock::generate('stubAuthStrategy'); 
    11 Mock::generate('stubAuthStorage'); 
    12 Mock::generate('stubAuthenticator'); 
    1310/** 
    1411 * Tests for net::stubbles::auth::stubAuth. 
     
    1714 * @subpackage  auth_test 
    1815 */ 
    19 class stubAuthTestCase extends UnitTestCase 
     16class stubAuthTestCase extends PHPUnit_Framework_TestCase 
    2017{ 
    2118    /** 
     
    2825     * a mocked strategy 
    2926     * 
    30      * @var  SimpleMock 
     27     * @var  PHPUnit_Framework_MockObject_MockObject 
    3128     */ 
    3229    protected $strategy; 
     
    3431     * a mocked storage 
    3532     * 
    36      * @var  SimpleMock 
     33     * @var  PHPUnit_Framework_MockObject_MockObject 
    3734     */ 
    3835    protected $storage; 
    3936 
    4037    /** 
    41      * set up the test environment 
     38     * set up test environment 
    4239     */ 
    43     public function setup() 
     40    public function setUp() 
    4441    { 
    45         $this->strategy = new MockstubAuthStrategy(); 
    46         $this->storage  = new MockstubAuthStorage(); 
     42        $this->strategy = $this->getMock('stubAuthStrategy'); 
     43        $this->storage  = $this->getMock('stubAuthStorage'); 
    4744        $this->auth = stubAuth::createInstance($this->strategy, $this->storage, '__test'); 
    4845    } 
    4946 
    5047    /** 
    51      * restore environment 
     48     * clean up environment 
    5249     */ 
    5350    public function tearDown() 
     
    5855    /** 
    5956     * assure that always the same instance is returned 
     57     * 
     58     * @test 
    6059     */ 
    61     public function testReference() 
     60    public function equalInstanceNamesReferSameInstance() 
    6261    { 
    6362        $auth = stubAuth::getInstance('__test'); 
    64         $this->assertReference($this->auth, $auth); 
    65          
    66         $this->expectException('stubAuthException'); 
     63        $this->assertSame($this->auth, $auth); 
     64        $auth = stubAuth::createInstance($this->strategy, $this->storage, '__test'); 
     65        $this->assertSame($this->auth, $auth); 
     66    } 
     67 
     68    /** 
     69     * assure that always the same instance is returned 
     70     * 
     71     * @test 
     72     * @expectedException  stubAuthException 
     73     */ 
     74    public function invalidInstanceNameThrowsAuthException() 
     75    { 
    6776        stubAuth::getInstance('foo'); 
    6877    } 
     
    7079    /** 
    7180     * assure that checking validity of an auth instance works as expected 
     81     * 
     82     * @test 
    7283     */ 
    73     public function testValid() 
     84    public function shortcutForValidityCheckCallsStorage() 
    7485    { 
    75         $this->storage->setReturnValueAt(0, 'isValid', true); 
    76         $this->storage->setReturnValueAt(1, 'isValid', false); 
     86        $this->storage->expects($this->exactly(2)) 
     87                      ->method('isValid') 
     88                      ->will($this->onConsecutiveCalls(true, false)); 
    7789        $this->assertTrue(stubAuth::isValid('__test')); 
    7890        $this->assertFalse(stubAuth::isValid('__test')); 
     
    8294    /** 
    8395     * assure correct storage handling 
     96     * 
     97     * @test 
    8498     */ 
    85     public function testStorage() 
     99    public function returnedStorageIsReferenceToGivenStorage() 
    86100    { 
    87101        $storage = $this->auth->getStorage(); 
    88         $this->assertReference($this->storage, $storage); 
     102        $this->assertSame($this->storage, $storage); 
    89103    } 
    90104 
    91105    /** 
    92106     * assure that trying to authenticate without authenticators throws an exception 
     107     * 
     108     * @test 
     109     * @expectedException  stubAuthException 
    93110     */ 
    94     public function testAuthenticateWithoutAuthenticators() 
     111    public function authenticateWithoutAuthenticatorsThrowsAuthException() 
    95112    { 
    96         $this->expectException('stubAuthException'); 
    97113        $this->auth->authenticate('foo'); 
    98114    } 
     
    100116    /** 
    101117     * assure that trying to authenticate with authenticators works as expexcted 
     118     * 
     119     * @test 
    102120     */ 
    103     public function testAuthenticateWithAuthenticators() 
     121    public function authenticateWithAuthenticators() 
    104122    { 
    105         $authenticator = new MockstubAuthenticator(); 
     123        $authenticator = $this->getMock('stubAuthenticator'); 
    106124        $this->auth->addAuthenticator($authenticator); 
    107125        $authResult = new stubAuthResult(stubAuthResult::STATUS_SUCCESS, 'foo'); 
    108         $this->strategy->expectOnce('authenticate', array(array($authenticator), 'foo')); 
    109         $this->strategy->setReturnValue('authenticate', $authResult); 
    110         $this->storage->expectOnce('setResult',array($authResult)); 
     126        $this->assertEquals('foo', $authResult->getCredentials()); 
     127        $this->strategy->expects($this->once()) 
     128                       ->method('authenticate') 
     129                       ->with($this->equalTo(array($authenticator)), $this->equalTo('foo')) 
     130                       ->will($this->returnValue($authResult)); 
     131        $this->storage->expects($this->once()) 
     132                      ->method('setResult') 
     133                      ->with($this->equalTo($authResult)); 
    111134        $storage = $this->auth->authenticate('foo'); 
    112         $this->assertReference($this->storage, $storage); 
     135        $this->assertSame($this->storage, $storage); 
    113136    } 
    114137} 
  • trunk/src/test/php/net/stubbles/events/EventTestSuite.php

    r768 r1235  
    1313 * @subpackage  test 
    1414 */ 
    15 class EventTestSuite extends TestSuite 
     15class EventTestSuite 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 events tests'); 
    24         $this->addTestFile($dir . '/stubCallbackListenerTestCase.php'); 
    25         $this->addTestFile($dir . '/stubEventTestCase.php'); 
    26         $this->addTestFile($dir . '/stubLazyEventListenerTestCase.php'); 
    27         $this->addTestFile($dir . '/stubEventDispatcherTestCase.php'); 
    28         $this->addTestFile($dir . '/stubNonCancelableEventTestCase.php'); 
     24        $suite = new self(); 
     25        $dir   = dirname(__FILE__); 
     26        $suite->addTestFile($dir . '/stubCallbackListenerTestCase.php'); 
     27        $suite->addTestFile($dir . '/stubEventTestCase.php'); 
     28        $suite->addTestFile($dir . '/stubLazyEventListenerTestCase.php'); 
     29        $suite->addTestFile($dir . '/stubEventDispatcherTestCase.php'); 
     30        $suite->addTestFile($dir . '/stubNonCancelableEventTestCase.php'); 
     31        return $suite; 
    2932    } 
    3033} 
  • trunk/src/test/php/net/stubbles/events/stubCallbackListenerTestCase.php

    r1209 r1235  
    1515 * @subpackage  events_test 
    1616 */ 
    17 class stubCallbackListenerTestCase extends UnitTestCase 
     17class stubCallbackListenerTestCase extends PHPUnit_Framework_TestCase 
    1818{ 
    1919    /** 
    2020     * assure that a lazy initialization with the callback listener works correct 
    21      */ 
    22     public function testLazyInitialization() 
     21     * 
     22     * @test 
     23     */ 
     24    public function lazyInitialization() 
    2325    { 
    2426        $callbacklistener = new stubCallbackListener('TestStubCallback', 'doSomething'); 
     
    2628        $this->assertFalse($callbacklistener->isNotified()); 
    2729        $this->assertFalse($callbacklistener->autoremove()); 
     30        $this->assertEquals('TestStubCallback', $callbacklistener->getCallbackClassName()); 
     31        $this->assertEquals('doSomething', $callbacklistener->getCallbackMethodName()); 
    2832        $event = new stubEvent('eventName'); 
    2933        $callbacklistener->handleEvent($event); 
    3034        $testEvent = $callbacklistener->getEvent(); 
    31         $this->assertReference($event, $testEvent); 
     35        $this->assertSame($event, $testEvent); 
    3236        $instance = $callbacklistener->getInstance(); 
    33         $this->assertIsA($instance, 'TestStubCallback'); 
    34         $this->assertEqual($instance->getInvocations(), 1); 
     37        $this->assertType('TestStubCallback', $instance); 
     38        $this->assertEquals(1, $instance->getInvocations()); 
    3539        $this->assertTrue($callbacklistener->isNotified()); 
    3640    } 
     
    3842    /** 
    3943     * assure that a normal initialization with the callback listener works correct 
    40      */ 
    41     public function testNonLazyInitialization() 
     44     * 
     45     * @test 
     46     */ 
     47    public function nonLazyInitialization() 
    4248    { 
    4349        $callback         = new TestStubCallback(); 
     
    4652        $this->assertFalse($callbacklistener->isNotified()); 
    4753        $this->assertTrue($callbacklistener->autoremove()); 
     54        $this->assertEquals('TestStubCallback', $callbacklistener->getCallbackClassName()); 
     55        $this->assertEquals('doSomething', $callbacklistener->getCallbackMethodName()); 
    4856        $event = new stubEvent('eventName'); 
    4957        $callbacklistener->handleEvent($event); 
    5058        $testEvent = $callbacklistener->getEvent(); 
    51         $this->assertReference($event, $testEvent); 
     59        $this->assertSame($event, $testEvent); 
    5260        $instance = $callbacklistener->getInstance(); 
    53         $this->assertReference($instance, $callback); 
    54         $this->assertEqual($instance->getInvocations(), 1); 
     61        $this->assertSame($instance, $callback); 
     62        $this->assertEquals(1, $instance->getInvocations()); 
    5563        $this->assertTrue($callbacklistener->isNotified()); 
    5664    } 
     
    5866    /** 
    5967     * assure that a static callback works correct 
    60      */ 
    61     public function testStaticCallback() 
     68     * 
     69     * @test 
     70     */ 
     71    public function staticCallback() 
    6272    { 
    6373        $callbacklistener = new stubCallbackListener('TestStubCallback', 'doSomethingStatic', false); 
     
    6878        $callbacklistener->handleEvent($event); 
    6979        $testEvent = $callbacklistener->getEvent(); 
    70         $this->assertReference($event, $testEvent); 
     80        $this->assertSame($event, $testEvent); 
    7181        $instance = $callbacklistener->getInstance(); 
    7282        $this->assertNull($instance); 
    73         $this->assertEqual(TestStubCallback::$staticInvocations, 1); 
     83        $this->assertEquals(1, TestStubCallback::$staticInvocations); 
    7484        $this->assertTrue($callbacklistener->isNotified()); 
    7585    } 
     
    7787    /** 
    7888     * assure that calling a non-public callback throws a stubCallbackException 
    79      */ 
    80     public function testNonPublicCallback() 
     89     * 
     90     * @test 
     91     * @expectedException  stubCallbackException 
     92     */ 
     93    public function nonPublicCallback() 
    8194    { 
    8295        $callbacklistener = new stubCallbackListener('TestStubCallback', 'forceException'); 
    8396        $event            = new stubEvent('eventName'); 
    84         $this->expectException('stubCallbackException'); 
    8597        $callbacklistener->handleEvent($event); 
    8698    } 
     
    88100    /** 
    89101     * assure that calling a non-existing callback method throws a stubCallbackException 
    90      */ 
    91     public function testNonExistingCallbackMethod() 
     102     * 
     103     * @test 
     104     * @expectedException  stubCallbackException 
     105     */ 
     106    public function nonExistingCallbackMethod() 
    92107    { 
    93108        $callbacklistener = new stubCallbackListener('TestStubCallback', 'notExisting'); 
    94109        $event            = new stubEvent('eventName'); 
    95         $this->expectException('stubCallbackException'); 
    96110        $callbacklistener->handleEvent($event); 
    97111    } 
     
    99113    /** 
    100114     * assure that calling a non-existing callback class throws a stubCallbackException 
    101      */ 
    102     public function testNonExistingCallbackClass() 
     115     * 
     116     * @test 
     117     * @expectedException  stubClassNotFoundException 
     118     */ 
     119    public function nonExistingCallbackClass() 
    103120    { 
    104121        $callbacklistener = new stubCallbackListener('NotExisting', 'notExisting'); 
    105122        $event            = new stubEvent('eventName'); 
    106         $this->expectException('stubClassNotFoundException'); 
    107123        $callbacklistener->handleEvent($event); 
    108124    } 
     
    110126    /** 
    111127     * assure that a failed instantiation of the callback class throws a stubCallbackException 
    112      */ 
    113     public function testFailingInvocationWrongMethod() 
     128     * 
     129     * @test 
     130     * @expectedException  stubCallbackException 
     131     */ 
     132    public function failingInvocationWrongMethod() 
    114133    { 
    115134        $callbacklistener = new stubCallbackListener('TestStubCallback2', 'notExisting'); 
    116135        $event            = new stubEvent('eventName'); 
    117         $this->expectException('stubCallbackException'); 
    118136        $callbacklistener->handleEvent($event); 
    119137    } 
     
    121139    /** 
    122140     * assure that a failed invocation of the callback method throws a stubCallbackException 
    123      */ 
    124     public function testFailingInvocation() 
     141     * 
     142     * @test 
     143     * @expectedException  stubCallbackException 
     144     */ 
     145    public function failingInvocation() 
    125146    { 
    126147        $callbacklistener = new stubCallbackListener('TestStubCallback', 'failsInvocation'); 
    127148        $event            = new stubEvent('eventName'); 
    128         $this->expectException('stubCallbackException'); 
    129149        $callbacklistener->handleEvent($event); 
    130150    } 
     
    132152    /** 
    133153     * assure that creating a stubCallbackListener with an illegal argument throws a stubCallbackException 
    134      */ 
    135     public function testIllegalConstructorArgumentInstance() 
    136     { 
    137         $this->expectException('stubIllegalArgumentException'); 
     154     * 
     155     * @test 
     156     * @expectedException  stubIllegalArgumentException 
     157     */ 
     158    public function illegalConstructorArgumentInstance() 
     159    { 
    138160        $callbacklistener = new stubCallbackListener(6100, 'pimp'); 
    139161    } 
     
    141163    /** 
    142164     * assure that creating a stubCallbackListener with an illegal argument throws a stubCallbackException 
    143      */ 
    144     public function testIllegalConstructorArgumentMethod() 
    145     { 
    146         $this->expectException('stubIllegalArgumentException'); 
     165     * 
     166     * @test 
     167     * @expectedException  stubIlleg