Changeset 1288

Show
Ignore:
Timestamp:
01/23/08 17:53:13 (10 months ago)
Author:
mikey
Message:

continued refactoring #118: transformed tests for net::stubbles::websites::util

Files:

Legend:

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

    r1272 r1288  
    2828require_once $dir . '/php/net/stubbles/ioc/IOCTestSuite.php'; 
    2929require_once $dir . '/php/net/stubbles/ipo/IPOTestSuite.php'; 
     30require_once $dir . '/php/net/stubbles/util/UtilTestSuite.php'; 
    3031require_once $dir . '/php/net/stubbles/websites/WebsitesTestSuite.php'; 
    3132require_once $dir . '/php/net/stubbles/websites/variantmanager/VariantManagerTestSuite.php'; 
     
    6061        $suite->addTestSuite('IOCTestSuite'); 
    6162        $suite->addTestSuite('IPOTestSuite'); 
     63        $suite->addTestSuite('UtilTestSuite'); 
    6264        $suite->addTestSuite('WebsitesTestSuite'); 
    6365        $suite->addTestSuite('VariantManagerTestSuite'); 
  • trunk/src/test/php/net/stubbles/util/BinfordTestCase.php

    r1230 r1288  
    1414 * @subpackage  util_test 
    1515 */ 
    16 class BinfordTestCase extends UnitTestCase 
     16class BinfordTestCase extends PHPUnit_Framework_TestCase 
    1717{ 
    1818    /** 
     
    3333    /** 
    3434     * assure that values are returned as expected 
     35     * 
     36     * @test 
    3537     */ 
    36     public function testValidate() 
     38    public function validate() 
    3739    { 
    3840        $this->assertTrue($this->binford->validate(Binford::POWER)); 
     
    4446    /** 
    4547     * assure that values are returned as expected 
     48     * 
     49     * @test 
    4650     */ 
    47     public function testGetCriteria() 
     51    public function getCriteria() 
    4852    { 
    49         $this->assertEqual($this->binford->getCriteria(), array('allowedValues' => array(Binford::POWER, 'Binford', 'Binford ' . Binford::POWER))); 
     53        $this->assertEquals(array('allowedValues' => array(Binford::POWER, 'Binford', 'Binford ' . Binford::POWER)), $this->binford->getCriteria()); 
    5054    } 
    5155 
    5256    /** 
    5357     * assure that values are returned as expected 
     58     * 
     59     * @test 
    5460     */ 
    55     public function testFilter() 
     61    public function filter() 
    5662    { 
    57         $this->assertEqual($this->binford->execute(Binford::POWER), Binford::POWER); 
    58         $this->assertEqual($this->binford->execute('Binford'), 'Binford'); 
    59         $this->assertEqual($this->binford->execute('Binford ' . Binford::POWER), 'Binford ' . Binford::POWER); 
    60         $this->assertEqual($this->binford->execute('Bob Vila'), 'Binford ' . Binford::POWER); 
     63        $this->assertEquals(Binford::POWER, $this->binford->execute(Binford::POWER)); 
     64        $this->assertEquals('Binford', $this->binford->execute('Binford')); 
     65        $this->assertEquals('Binford ' . Binford::POWER, $this->binford->execute('Binford ' . Binford::POWER)); 
     66        $this->assertEquals('Binford ' . Binford::POWER, $this->binford->execute('Bob Vila')); 
    6167    } 
    6268 
    6369    /** 
    6470     * assert that the binford hash code always equals the power of binford 
     71     * 
     72     * @test 
    6573     */ 
    66     public function testHashCode() 
     74    public function hashCode() 
    6775    { 
    68         $this->assertEqual($this->binford->hashCode(), Binford::POWER); 
     76        $this->assertEquals(Binford::POWER, $this->binford->hashCode()); 
    6977    } 
    7078 
    7179    /** 
    7280     * assure that any Binford instance is equal to any other 
     81     * 
     82     * @test 
    7383     */ 
    74     public function testEquals() 
     84    public function equals() 
    7585    { 
    7686        $this->assertTrue($this->binford->equals($this->binford)); 
  • trunk/src/test/php/net/stubbles/util/UtilTestSuite.php

    r1106 r1288  
    1313 * @subpackage  test 
    1414 */ 
    15 class UtilTestSuite extends TestSuite 
     15class UtilTestSuite 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         $this->TestSuite('All util tests'); 
    23         $dir = dirname(__FILE__); 
    24         $this->addTestFile($dir . '/BinfordTestCase.php'); 
    25         $this->addTestFile($dir . '/stubRegistryTestCase.php'); 
    26         $this->addTestFile($dir . '/stubRegistryXJConfInitializerTestCase.php'); 
     24        $suite = new self(); 
     25        $dir   = dirname(__FILE__); 
     26        $suite->addTestFile($dir . '/BinfordTestCase.php'); 
     27        $suite->addTestFile($dir . '/stubRegistryTestCase.php'); 
     28        $suite->addTestFile($dir . '/stubRegistryXJConfInitializerTestCase.php'); 
    2729 
    2830        // cache 
    29         $this->addTestFile($dir . '/cache/stubCacheTestCase.php'); 
    30         $this->addTestFile($dir . '/cache/stubDefaultCacheStrategyTestCase.php'); 
    31         $this->addTestFile($dir . '/cache/stubAbstractCacheContainerTestCase.php'); 
    32         $this->addTestFile($dir . '/cache/stubFileCacheContainerTestCase.php'); 
     31        $suite->addTestFile($dir . '/cache/stubCacheTestCase.php'); 
     32        $suite->addTestFile($dir . '/cache/stubDefaultCacheStrategyTestCase.php'); 
     33        $suite->addTestFile($dir . '/cache/stubAbstractCacheContainerTestCase.php'); 
     34        $suite->addTestFile($dir . '/cache/stubFileCacheContainerTestCase.php'); 
    3335 
    3436        // datespan 
    35         $this->addTestFile($dir . '/datespan/stubDateSpanCustomTestCase.php'); 
    36         $this->addTestFile($dir . '/datespan/stubDateSpanDayTestCase.php'); 
    37         $this->addTestFile($dir . '/datespan/stubDateSpanMonthTestCase.php'); 
    38         $this->addTestFile($dir . '/datespan/stubDateSpanWeekTestCase.php'); 
     37        $suite->addTestFile($dir . '/datespan/stubDateSpanCustomTestCase.php'); 
     38        $suite->addTestFile($dir . '/datespan/stubDateSpanDayTestCase.php'); 
     39        $suite->addTestFile($dir . '/datespan/stubDateSpanMonthTestCase.php'); 
     40        $suite->addTestFile($dir . '/datespan/stubDateSpanWeekTestCase.php'); 
    3941 
    4042        // logging api 
    41         $this->addTestFile($dir . '/log/stubLoggerTestCase.php'); 
    42         $this->addTestFile($dir . '/log/stubFileLogAppenderTestCase.php'); 
    43         $this->addTestFile($dir . '/log/stubBaseLogDataTestCase.php'); 
    44         $this->addTestFile($dir . '/log/stubLogDataFactoryTestCase.php'); 
    45         $this->addTestFile($dir . '/log/stubLoggerXJConfFactoryTestCase.php'); 
    46         $this->addTestFile($dir . '/log/stubMemoryLogAppenderTestCase.php'); 
     43        $suite->addTestFile($dir . '/log/stubLoggerTestCase.php'); 
     44        $suite->addTestFile($dir . '/log/stubFileLogAppenderTestCase.php'); 
     45        $suite->addTestFile($dir . '/log/stubBaseLogDataTestCase.php'); 
     46        $suite->addTestFile($dir . '/log/stubLogDataFactoryTestCase.php'); 
     47        $suite->addTestFile($dir . '/log/stubLoggerXJConfFactoryTestCase.php'); 
     48        $suite->addTestFile($dir . '/log/stubMemoryLogAppenderTestCase.php'); 
    4749 
    4850        // net classes 
    49         $this->addTestFile($dir . '/net/stubHeaderListTestCase.php'); 
    50         $this->addTestFile($dir . '/net/stubSocketTestCase.php'); 
    51         $this->addTestFile($dir . '/net/stubURLTestCase.php'); 
     51        #$suite->addTestFile($dir . '/net/stubHeaderListTestCase.php'); 
     52        #$suite->addTestFile($dir . '/net/stubSocketTestCase.php'); 
     53        #$suite->addTestFile($dir . '/net/stubURLTestCase.php'); 
    5254 
    5355        // net_http classes 
    54         $this->addTestFile($dir . '/net/http/stubHTTPURLTestCase.php'); 
     56        #$suite->addTestFile($dir . '/net/http/stubHTTPURLTestCase.php'); 
    5557 
    5658        // now all the validators 
    57         $this->addTestFile($dir . '/validators/stubAndValidatorTestCase.php'); 
    58         $this->addTestFile($dir . '/validators/stubContainsValidatorTestCase.php'); 
    59         $this->addTestFile($dir . '/validators/stubEqualValidatorTestCase.php'); 
    60         $this->addTestFile($dir . '/validators/stubExtFilterValidatorTestCase.php'); 
    61         $this->addTestFile($dir . '/validators/stubIpValidatorTestCase.php'); 
    62         $this->addTestFile($dir . '/validators/stubMailValidatorTestCase.php'); 
    63         $this->addTestFile($dir . '/validators/stubMaxLengthValidatorTestCase.php'); 
    64         $this->addTestFile($dir . '/validators/stubMaxNumberValidatorTestCase.php'); 
    65         $this->addTestFile($dir . '/validators/stubMinLengthValidatorTestCase.php'); 
    66         $this->addTestFile($dir . '/validators/stubMinNumberValidatorTestCase.php'); 
    67         $this->addTestFile($dir . '/validators/stubOrValidatorTestCase.php'); 
    68         $this->addTestFile($dir . '/validators/stubPreSelectValidatorTestCase.php'); 
    69         $this->addTestFile($dir . '/validators/stubRegexValidatorTestCase.php'); 
    70         $this->addTestFile($dir . '/validators/stubXorValidatorTestCase.php'); 
     59        #$suite->addTestFile($dir . '/validators/stubAndValidatorTestCase.php'); 
     60        #$suite->addTestFile($dir . '/validators/stubContainsValidatorTestCase.php'); 
     61        #$suite->addTestFile($dir . '/validators/stubEqualValidatorTestCase.php'); 
     62        #$suite->addTestFile($dir . '/validators/stubExtFilterValidatorTestCase.php'); 
     63        #$suite->addTestFile($dir . '/validators/stubIpValidatorTestCase.php'); 
     64        #$suite->addTestFile($dir . '/validators/stubMailValidatorTestCase.php'); 
     65        #$suite->addTestFile($dir . '/validators/stubMaxLengthValidatorTestCase.php'); 
     66        #$suite->addTestFile($dir . '/validators/stubMaxNumberValidatorTestCase.php'); 
     67        #$suite->addTestFile($dir . '/validators/stubMinLengthValidatorTestCase.php'); 
     68        #$suite->addTestFile($dir . '/validators/stubMinNumberValidatorTestCase.php'); 
     69        #$suite->addTestFile($dir . '/validators/stubOrValidatorTestCase.php'); 
     70        #$suite->addTestFile($dir . '/validators/stubPreSelectValidatorTestCase.php'); 
     71        #$suite->addTestFile($dir . '/validators/stubRegexValidatorTestCase.php'); 
     72        #$suite->addTestFile($dir . '/validators/stubXorValidatorTestCase.php'); 
    7173 
    7274        // xjconf 
    73         $this->addTestFile($dir . '/xjconf/stubXJConfProxyTestCase.php'); 
     75        #$suite->addTestFile($dir . '/xjconf/stubXJConfProxyTestCase.php'); 
     76        return $suite; 
    7477    } 
    7578} 
  • trunk/src/test/php/net/stubbles/util/cache/stubAbstractCacheContainerTestCase.php

    r1230 r1288  
    88 */ 
    99stubClassLoader::load('net::stubbles::util::cache::stubAbstractCacheContainer'); 
    10 Mock::generate('stubCacheStrategy'); 
    1110class TeststubAbstractCacheContainer extends stubAbstractCacheContainer implements stubCacheContainer 
    1211{ 
     
    8180} 
    8281/** 
    83  * Tests for net::stubbles::util.cache.stubAbstractCacheContainer. 
     82 * Tests for net::stubbles::util::cache::stubAbstractCacheContainer. 
    8483 * 
    8584 * @package     stubbles 
    8685 * @subpackage  util_cache_test 
    8786 */ 
    88 class stubAbstractCacheContainerTestCase extends UnitTestCase 
     87class stubAbstractCacheContainerTestCase extends PHPUnit_Framework_TestCase 
    8988{ 
    9089    /** 
     
    9796     * a mocked cache strategy 
    9897     * 
    99      * @var  SimpleMock 
     98     * @var  PHPUnit_Framework_MockObject_MockObject 
    10099     */ 
    101100    protected $mockCacheStrategy; 
     
    106105    public function setUp() 
    107106    { 
    108         $this->mockCacheStrategy = new MockstubCacheStrategy(); 
     107        $this->mockCacheStrategy = $this->getMock('stubCacheStrategy'); 
    109108        $this->cacheContainer    = new TeststubAbstractCacheContainer('foo'); 
    110109        $this->cacheContainer->setStrategy($this->mockCacheStrategy); 
     
    113112    /** 
    114113     * assure that the id is returned correct 
    115      */ 
    116     public function testId() 
    117     { 
    118         $this->assertEqual($this->cacheContainer->getId(), 'foo'); 
     114     * 
     115     * @test 
     116     */ 
     117    public function id() 
     118    { 
     119        $this->assertEquals('foo', $this->cacheContainer->getId()); 
    119120    } 
    120121 
    121122    /** 
    122123     * assert that put() works as expected 
    123      */ 
    124     public function testPut() 
    125     { 
    126         $this->mockCacheStrategy->setReturnValueAt(0, 'isCachable', true); 
    127         $this->mockCacheStrategy->setReturnValueAt(1, 'isCachable', false); 
    128          
    129         $this->assertEqual($this->cacheContainer->put('foo', 'bar'), 3); 
    130         $this->assertEqual($this->cacheContainer->put('baz', 'bar'), false); 
    131         $this->assertEqual($this->cacheContainer->data['foo']['data'], 'bar'); 
    132         $this->assertEqual($this->cacheContainer->getKeys(), array('foo')); 
     124     * 
     125     * @test 
     126     */ 
     127    public function put() 
     128    { 
     129        $this->mockCacheStrategy->expects($this->exactly(2)) 
     130                                ->method('isCachable') 
     131                                ->will($this->onConsecutiveCalls(true, false)); 
     132        $this->assertEquals(3, $this->cacheContainer->put('foo', 'bar')); 
     133        $this->assertEquals(false, $this->cacheContainer->put('baz', 'bar')); 
     134        $this->assertEquals('bar', $this->cacheContainer->data['foo']['data']); 
     135        $this->assertEquals(array('foo'), $this->cacheContainer->getKeys()); 
    133136    } 
    134137 
    135138    /** 
    136139     * assert that has() works as expected 
    137      */ 
    138     public function testHas() 
    139     { 
    140         $this->cacheContainer->data = array('foo' => array('data' => 'bar', 'time' => 10)); 
    141         $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    142         $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
    143         $this->mockCacheStrategy->setReturnValueAt(2, 'isExpired', false); 
     140     * 
     141     * @test 
     142     */ 
     143    public function has() 
     144    { 
     145        $this->cacheContainer->data = array('foo' => array('data' => 'bar', 'time' => 10)); 
     146        $this->mockCacheStrategy->expects($this->exactly(3)) 
     147                                ->method('isExpired') 
     148                                ->will($this->onConsecutiveCalls(false, true, false)); 
    144149        $this->assertTrue($this->cacheContainer->has('foo')); 
    145150        $this->assertFalse($this->cacheContainer->has('foo')); 
     
    149154    /** 
    150155     * assert that get() works as expected 
    151      */ 
    152     public function testGet() 
    153     { 
    154         $this->cacheContainer->data = array('foo' => array('data' => 'bar', 'time' => 10)); 
    155         $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    156         $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
    157         $this->mockCacheStrategy->setReturnValueAt(2, 'isExpired', false); 
    158         $this->assertEqual($this->cacheContainer->get('foo'), 'bar'); 
     156     * 
     157     * @test 
     158     */ 
     159    public function get() 
     160    { 
     161        $this->cacheContainer->data = array('foo' => array('data' => 'bar', 'time' => 10)); 
     162        $this->mockCacheStrategy->expects($this->exactly(3)) 
     163                                ->method('isExpired') 
     164                                ->will($this->onConsecutiveCalls(false, true, false)); 
     165        $this->assertEquals('bar', $this->cacheContainer->get('foo')); 
    159166        $this->assertNull($this->cacheContainer->get('foo')); 
    160167        $this->assertNull($this->cacheContainer->get('bar')); 
     
    163170    /** 
    164171     * assert that getSize() works as expected 
    165      */ 
    166     public function testGetSize() 
    167     { 
    168         $this->cacheContainer->data = array('foo' => array('data' => 'bar', 'time' => 10)); 
    169         $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    170         $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
    171         $this->mockCacheStrategy->setReturnValueAt(2, 'isExpired', false); 
    172         $this->assertEqual($this->cacheContainer->getSize('foo'), 3); 
    173         $this->assertEqual($this->cacheContainer->getSize('foo'), 0); 
    174         $this->assertEqual($this->cacheContainer->getSize('bar'), 0); 
     172     * 
     173     * @test 
     174     */ 
     175    public function getSize() 
     176    { 
     177        $this->cacheContainer->data = array('foo' => array('data' => 'bar', 'time' => 10)); 
     178        $this->mockCacheStrategy->expects($this->exactly(3)) 
     179                                ->method('isExpired') 
     180                                ->will($this->onConsecutiveCalls(false, true, false)); 
     181        $this->assertEquals(3, $this->cacheContainer->getSize('foo')); 
     182        $this->assertEquals(0, $this->cacheContainer->getSize('foo')); 
     183        $this->assertEquals(0, $this->cacheContainer->getSize('bar')); 
    175184    } 
    176185 
    177186    /** 
    178187     * test the garbage collection 
    179      */ 
    180     public function testGc() 
    181     { 
    182         $this->mockCacheStrategy->setReturnValueAt(0, 'shouldRunGc', false); 
    183         $this->mockCacheStrategy->setReturnValueAt(1, 'shouldRunGc', true); 
     188     * 
     189     * @test 
     190     */ 
     191    public function gc() 
     192    { 
     193        $this->mockCacheStrategy->expects($this->exactly(2)) 
     194                                ->method('shouldRunGc') 
     195                                ->will($this->onConsecutiveCalls(false, true)); 
    184196        $this->assertNull($this->cacheContainer->lastGcRun()); 
    185197        $this->cacheContainer->gc(); 
    186198        $this->assertNull($this->cacheContainer->lastGcRun()); 
    187199         
    188         $this->cacheContainer->data = array('foo' => array('data' => 'bar', 'time' => 10)); 
    189         $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', true); 
     200        $this->mockCacheStrategy->expects($this->once()) 
     201                                ->method('isExpired') 
     202                                ->will($this->returnValue(true)); 
     203        $this->cacheContainer->data = array('foo' => array('data' => 'bar', 'time' => 10)); 
    190204        $this->cacheContainer->gc(); 
    191         $this->assertEqual($this->cacheContainer->data, array()); 
     205        $this->assertEquals(array(), $this->cacheContainer->data); 
    192206        $this->assertNotNull($this->cacheContainer->lastGcRun()); 
    193207    } 
  • trunk/src/test/php/net/stubbles/util/cache/stubCacheTestCase.php

    r1230 r1288  
    88 */ 
    99stubClassLoader::load('net::stubbles::util::cache::stubCache'); 
    10 Mock::generate('stubCacheContainer'); 
    1110/** 
    1211 * Tests for net::stubbles::util::cache::stubCache. 
     
    1514 * @subpackage  util_cache_test 
    1615 */ 
    17 class stubCacheTestCase extends UnitTestCase 
     16class stubCacheTestCase extends PHPUnit_Framework_TestCase 
    1817{ 
    1918    /** 
    2019     * assure that retrieving a non-existing container triggers an exception 
     20     * 
     21     * @test 
     22     * @expectedException  stubRuntimeException 
    2123     */ 
    22     public function testNoContainer() 
     24    public function noContainer() 
    2325    { 
    24         $this->expectException('stubRuntimeException'); 
     26        $this->assertFalse(stubCache::has('foo')); 
    2527        stubCache::factory('foo'); 
    2628    } 
     
    2830    /** 
    2931     * assure that retrieving a container returns the correct one 
     32     * 
     33     * @test 
    3034     */ 
    31     public function testWithContainer() 
     35    public function withContainer() 
    3236    { 
    33         $mockContainer = new MockstubCacheContainer(); 
    34         $mockContainer->setReturnValue('getId', 'foo'); 
    35         $mockContainer->expectOnce('gc'); 
     37        $mockContainer = $this->getMock('stubCacheContainer'); 
     38        $mockContainer->expects($this->any())->method('getId')->will($this->returnValue('foo')); 
     39        $mockContainer->expects($this->once())->method('gc'); 
    3640        stubCache::addContainer($mockContainer); 
    3741        $this->assertTrue(stubCache::has('foo')); 
    3842        $this->assertFalse(stubCache::has('bar')); 
    3943        $fooCache = stubCache::factory('foo'); 
    40         $this->assertReference($fooCache, $mockContainer); 
    41         $this->expectException('stubRuntimeException'); 
    42         stubCache::factory('bar'); 
     44        $this->assertSame($mockContainer, $fooCache); 
    4345    } 
    4446} 
  • trunk/src/test/php/net/stubbles/util/cache/stubDefaultCacheStrategyTestCase.php

    r1230 r1288  
    88 */ 
    99stubClassLoader::load('net::stubbles::util::cache::stubDefaultCacheStrategy'); 
    10 Mock::generate('stubCacheContainer'); 
    1110/** 
    1211 * Tests for net::stubbles::util::cache::stubDefaultCacheStrategy. 
     
    1514 * @subpackage  util_cache_test 
    1615 */ 
    17 class stubDefaultCacheStrategyTestCase extends UnitTestCase 
     16class stubDefaultCacheStrategyTestCase extends PHPUnit_Framework_TestCase 
    1817{ 
    1918    /** 
    2019     * assure that retrieving a non-existing container triggers an exception 
     20     * 
     21     * @test 
    2122     */ 
    22     public function testIsCachable() 
     23    public function isCachable() 
    2324    { 
    2425        $defaultCacheStrategy = new stubDefaultCacheStrategy(10, 2, 0); 
    25         $mockContainer        = new MockstubCacheContainer(); 
    26         $mockContainer->setReturnValueAt(0, 'getUsedSpace', 1); 
    27         $mockContainer->setReturnValueAt(0, 'getSize', 0); 
     26        $mockContainer        = $this->getMock('stubCacheContainer'); 
     27        $mockContainer->expects($this->exactly(6)) 
     28                      ->method('getUsedSpace') 
     29                      ->will($this->onConsecutiveCalls(1, 1, 1, 2, 2, 0)); 
     30        $mockContainer->expects($this->exactly(6)) 
     31                      ->method('getSize') 
     32                      ->will($this->onConsecutiveCalls(0, 0, 1, 2, 0, 0)); 
    2833        $this->assertTrue($defaultCacheStrategy->isCachable($mockContainer, 'a', 'a')); 
    29          
    30         $mockContainer->setReturnValueAt(1, 'getUsedSpace', 1); 
    31         $mockContainer->setReturnValueAt(1, 'getSize', 0); 
    3234        $this->assertFalse($defaultCacheStrategy->isCachable($mockContainer, 'a', 'ab')); 
    33          
    34         $mockContainer->setReturnValueAt(2, 'getUsedSpace', 1); 
    35         $mockContainer->setReturnValueAt(2, 'getSize', 1); 
    3635        $this->assertTrue($defaultCacheStrategy->isCachable($mockContainer, 'a', 'a')); 
    37          
    38         $mockContainer->setReturnValueAt(3, 'getUsedSpace', 2); 
    39         $mockContainer->setReturnValueAt(3, 'getSize', 2); 
    4036        $this->assertTrue($defaultCacheStrategy->isCachable($mockContainer, 'a', 'a')); 
    41          
    42         $mockContainer->setReturnValueAt(4, 'getUsedSpace', 2); 
    43         $mockContainer->setReturnValueAt(4, 'getSize', 0); 
    4437        $this->assertFalse($defaultCacheStrategy->isCachable($mockContainer, 'a', 'a')); 
    45          
    46         $mockContainer->setReturnValueAt(5, 'getUsedSpace', 0); 
    47         $mockContainer->setReturnValueAt(5, 'getSize', 0); 
    4838        $this->assertTrue($defaultCacheStrategy->isCachable($mockContainer, 'a', 'ab')); 
    4939         
    5040        $defaultCacheStrategy = new stubDefaultCacheStrategy(10, -1, 0); 
    51         $mockContainer->setReturnValueAt(7, 'getUsedSpace', 6); 
    52         $mockContainer->setReturnValueAt(7, 'getSize', 0); 
    5341        $this->assertTrue($defaultCacheStrategy->isCachable($mockContainer, 'a', 'ab')); 
    5442    } 
     
    5644    /** 
    5745     * assure that retrieving a container returns the correct one 
     46     * 
     47     * @test 
    5848     */ 
    59     public function testIsExpired() 
     49    public function isExpired() 
    6050    { 
    6151        $defaultCacheStrategy = new stubDefaultCacheStrategy(10, 2, 0); 
    62         $mockContainer        = new MockstubCacheContainer(); 
    63         $mockContainer->setReturnValueAt(0, 'getLifeTime', 9); 
    64         $mockContainer->setReturnValueAt(1, 'getLifeTime', 10); 
    65         $mockContainer->setReturnValueAt(2, 'getLifeTime', 11); 
     52        $mockContainer        = $this->getMock('stubCacheContainer'); 
     53        $mockContainer->expects($this->exactly(3)) 
     54                      ->method('getLifeTime') 
     55                      ->will($this->onConsecutiveCalls(9, 10, 11)); 
    6656         
    6757        $this->assertFalse($defaultCacheStrategy->isExpired($mockContainer, 'a')); 
     
    7262    /** 
    7363     * assure that retrieving a container returns the correct one 
     64     * 
     65     * @test 
    7466     */ 
    75     public function testShouldRunGc() 
     67    public function shouldRunGc() 
    7668    { 
    7769        $defaultCacheStrategy = new stubDefaultCacheStrategy(10, 2, 0); 
    78         $mockContainer        = new MockstubCacheContainer(); 
     70        $mockContainer        = $this->getMock('stubCacheContainer'); 
    7971        $this->assertFalse($defaultCacheStrategy->shouldRunGc($mockContainer)); 
    8072        $this->assertFalse($defaultCacheStrategy->shouldRunGc($mockContainer)); 
  • trunk/src/test/php/net/stubbles/util/cache/stubFileCacheContainerTestCase.php

    r1230 r1288  
    88 */ 
    99stubClassLoader::load('net::stubbles::util::cache::stubFileCacheContainer'); 
    10 Mock::generate('stubCacheStrategy'); 
    1110@include_once 'vfsStream/vfsStream.php'; 
    1211/** 
     
    1615 * @subpackage  util_cache_test 
    1716 */ 
    18 class stubFileCacheContainerTestCase extends UnitTestCase 
     17class stubFileCacheContainerTestCase extends PHPUnit_Framework_TestCase 
    1918{ 
    2019    /** 
     
    2726     * a mocked cache strategy 
    2827     * 
    29      * @var  SimpleMock 
     28     * @var  PHPUnit_Framework_MockObject_MockObject 
    3029     */ 
    3130    protected $mockCacheStrategy; 
     
    3837 
    3938    /** 
    40      * skip the test if vfsStream is not available 
    41      */ 
    42     public function skip() 
    43     { 
    44         $this->skipUnless(class_exists('vfsStream', false), 'stubFileCacheContainerTestCase requires vfsStream, see http://code.google.com/p/bovigo/wiki/vfsStream.'); 
    45     } 
    46      
    47     /** 
    4839     * set up test environment 
    4940     */ 
    5041    public function setUp() 
    5142    { 
     43        if (class_exists('vfsStream', false) === false) { 
     44            $this->markTestSkipped('stubFileCacheContainerTestCase requires vfsStream, see http://vfs.bovigo.org/.'); 
     45        } 
     46         
    5247        vfsStreamWrapper::register(); 
    5348        vfsStreamWrapper::setRoot(new vfsStreamDirectory('cache')); 
    54         $this->mockCacheStrategy = new MockstubCacheStrategy(); 
     49        $this->mockCacheStrategy = $this->getMock('stubCacheStrategy'); 
    5550        $this->cacheContainer    = new stubFileCacheContainer('id'); 
    5651        $this->cacheContainer->setStrategy($this->mockCacheStrategy); 
     
    6156    /** 
    6257     * assert that put() works as expected 
    63      */ 
    64     public function testPut() 
    65     { 
    66         $this->mockCacheStrategy->setReturnValueAt(0, 'isCachable', true); 
    67         $this->mockCacheStrategy->setReturnValueAt(1, 'isCachable', false); 
    68         $this->mockCacheStrategy->setReturnValueAt(2, 'isCachable', true); 
     58     * 
     59     * @test 
     60     */ 
     61    public function put() 
     62    { 
     63        $this->mockCacheStrategy->expects($this->exactly(3)) 
     64                                ->method('isCachable') 
     65                                ->will($this->onConsecutiveCalls(true, false, true)); 
    6966         
    70         $this->assertEqual($this->cacheContainer->put('foo', 'bar'), 3); 
    71         $this->assertEqual($this->cacheContainer->put('baz', 'bar'), false); 
     67        $this->assertEquals(3, $this->cacheContainer->put('foo', 'bar')); 
     68        $this->assertFalse($this->cacheContainer->put('baz', 'bar')); 
    7269        $this->assertTrue($this->cacheDirectory->hasChild('foo.cache')); 
    73         $this->assertEqual($this->cacheDirectory->getChild('foo.cache')->getContent(), 'bar'); 
     70        $this->assertEquals('bar', $this->cacheDirectory->getChild('foo.cache')->getContent()); 
    7471        $this->assertFalse($this->cacheDirectory->hasChild('baz.cache')); 
    7572         
    76         $this->assertEqual($this->cacheContainer->put('foo', 'baz'), 3); 
     73        $this->assertEquals(3, $this->cacheContainer->put('foo', 'baz')); 
    7774        $this->assertTrue($this->cacheDirectory->hasChild('foo.cache')); 
    78         $this->assertEqual($this->cacheDirectory->getChild('foo.cache')->getContent(), 'baz'); 
     75        $this->assertEquals('baz', $this->cacheDirectory->getChild('foo.cache')->getContent()); 
    7976    } 
    8077 
    8178    /** 
    8279     * assert that has() works as expected 
    83      */ 
    84     public function testHas() 
    85     { 
    86         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    87         $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    88         $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
    89         $this->mockCacheStrategy->setReturnValueAt(2, 'isExpired', false); 
     80     * 
     81     * @test 
     82     */ 
     83    public function has() 
     84    { 
     85        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
     86        $this->mockCacheStrategy->expects($this->exactly(3)) 
     87                                ->method('isExpired') 
     88                                ->will($this->onConsecutiveCalls(false, true, false)); 
    9089        $this->assertTrue($this->cacheContainer->has('foo')); 
    9190        $this->assertFalse($this->cacheContainer->has('foo')); 
     
    9594    /** 
    9695     * assert that get() works as expected 
    97      */ 
    98     public function testGet() 
    99     { 
    100         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    101         $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    102         $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
    103         $this->mockCacheStrategy->setReturnValueAt(2, 'isExpired', false); 
    104         $this->assertEqual($this->cacheContainer->get('foo'), 'bar'); 
     96     * 
     97     * @test 
     98     */ 
     99    public function get() 
     100    { 
     101        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
     102        $this->mockCacheStrategy->expects($this->exactly(3)) 
     103                                ->method('isExpired') 
     104                                ->will($this->onConsecutiveCalls(false, true, false)); 
     105        $this->assertEquals('bar', $this->cacheContainer->get('foo')); 
    105106        $this->assertNull($this->cacheContainer->get('foo')); 
    106107        $this->assertNull($this->cacheContainer->get('bar')); 
     
    109110    /** 
    110111     * assert that getSize() works as expected 
    111      */ 
    112     public function testGetSize() 
    113     { 
    114         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    115         $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    116         $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
    117         $this->mockCacheStrategy->setReturnValueAt(2, 'isExpired', false); 
    118         $this->assertEqual($this->cacheContainer->getSize('foo'), 3); 
    119         $this->assertEqual($this->cacheContainer->getSize('foo'), 0); 
    120         $this->assertEqual($this->cacheContainer->getSize('bar'), 0); 
     112     * 
     113     * @test 
     114     */ 
     115    public function getSize() 
     116    { 
     117        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
     118        $this->mockCacheStrategy->expects($this->exactly(3)) 
     119                                ->method('isExpired') 
     120                                ->will($this->onConsecutiveCalls(false, true, false)); 
     121        $this->assertEquals(3, $this->cacheContainer->getSize('foo')); 
     122        $this->assertEquals(0, $this->cacheContainer->getSize('foo')); 
     123        $this->assertEquals(0, $this->cacheContainer->getSize('bar')); 
    121124    } 
    122125 
    123126    /** 
    124127     * assert that getUsedSpace() works as expected 
    125      */ 
    126     public function testGetUsedSpace() 
    127     { 
    128         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    129         $this->assertEqual($this->cacheContainer->getUsedSpace(), 3); 
    130         $this->mockCacheStrategy->setReturnValueAt(0, 'isCachable', true); 
     128     * 
     129     * @test 
     130     */ 
     131    public function getUsedSpace() 
     132    { 
     133        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
     134        $this->assertEquals(3, $this->cacheContainer->getUsedSpace()); 
     135        $this->mockCacheStrategy->expects($this->once()) 
     136                                ->method('isCachable') 
     137                                ->will($this->returnValue(true)); 
    131138        $this->cacheContainer->put('bar', 'baz'); 
    132         $this->assertEqual($this->cacheContainer->getUsedSpace(), 6); 
     139        $this->assertEquals(6, $this->cacheContainer->getUsedSpace()); 
    133140    } 
    134141 
    135142    /** 
    136143     * assert that getKeys() works as expected 
    137      */ 
    138     public function testGetKeys() 
    139     { 
    140         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    141         $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    142         $this->assertEqual($this->cacheContainer->getKeys(), array('foo' => 'foo')); 
    143         $this->mockCacheStrategy->setReturnValueAt(0, 'isCachable', true); 
     144     * 
     145     * @test 
     146     */ 
     147    public function getKeys() 
     148    { 
     149        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
     150        $this->mockCacheStrategy->expects($this->exactly(5)) 
     151                                ->method('isExpired') 
     152                                ->will($this->onConsecutiveCalls(false, false, false, true, false)); 
     153        $this->mockCacheStrategy->expects($this->once()) 
     154                                ->method('isCachable') 
     155                                ->will($this->returnValue(true)); 
     156        $this->assertEquals(array('foo' => 'foo'), $this->cacheContainer->getKeys()); 
    144157        $this->cacheContainer->put('bar', 'baz'); 
    145         $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', false); 
    146         $this->mockCacheStrategy->setReturnValueAt(2, 'isExpired', false); 
    147         $this->assertEqual($this->cacheContainer->getKeys(), array('foo' => 'foo', 'bar' => 'bar')); 
    148         $this->mockCacheStrategy->setReturnValueAt(3, 'isExpired', true); 
    149         $this->mockCacheStrategy->setReturnValueAt(4, 'isExpired', false); 
    150         $this->assertEqual($this->cacheContainer->getKeys(), array('bar' => 'bar')); 
     158        $this->assertEquals(array('foo' => 'foo', 'bar' => 'bar'), $this->cacheContainer->getKeys()); 
     159        $this->assertEquals(array('bar' => 'bar'), $this->cacheContainer->getKeys()); 
    151160    } 
    152161 
    153162    /** 
    154163     * test the garbage collection 
    155      */ 
    156     public function testGc() 
    157     { 
    158         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    159         $this->mockCacheStrategy->setReturnValue('shouldRunGc', true); 
    160         $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
     164     * 
     165     * @test 
     166     */ 
     167    public function gc() 
     168    { 
     169        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
     170        $this->mockCacheStrategy->expects($this->any()) 
     171                                ->method('shouldRunGc') 
     172                                ->will($this->returnValue(true)); 
     173        $this->mockCacheStrategy->expects($this->exactly(5)) 
     174                                ->method('isExpired') 
     175                                ->will($this->onConsecutiveCalls(false, true, false, false, false)); 
    161176        $this->cacheContainer->gc(); 
    162177        $this->assertTrue($this->cacheDirectory->hasChild('foo.cache')); 
    163          
    164         $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
    165178        $this->cacheContainer->gc(); 
    166179        $this->assertFalse($this->cacheDirectory->hasChild('foo.cache')); 
    167         $this->mockCacheStrategy->setReturnValueAt(2, 'isExpired', false); 
    168         $this->mockCacheStrategy->setReturnValueAt(3, 'isExpired', false); 
    169         $this->mockCacheStrategy->setReturnValueAt(4, 'isExpired', false); 
    170180        $this->assertFalse($this->cacheContainer->has('foo')); 
    171181        $this->assertNull($this->cacheContainer->get('foo')); 
    172         $this->assertEqual($this->cacheContainer->getSize('foo'), 0); 
     182        $this->assertEquals(0, $this->cacheContainer->getSize('foo')); 
    173183    } 
    174184 
    175185    /** 
    176186     * test a key that contains a directory seperator 
    177      */ 
    178     public function testKeyContainingDirectorySeperator() 
    179     { 
    180         $this->mockCacheStrategy->setReturnValue('isCachable', true); 
    181         $this->assertEqual($this->cacheContainer->put('bar' . DIRECTORY_SEPARATOR . 'foo', 'bar'), 3); 
     187     * 
     188     * @test 
     189     */ 
     190    public function keyContainingDirectorySeperator() 
     191    { 
     192        $this->mockCacheStrategy->expects($this->any()) 
     193                                ->method('isCachable') 
     194                                ->will($this->returnValue(true)); 
     195        $this->mockCacheStrategy->expects($this->any()) 
     196                                ->method('shouldRunGc') 
     197                                ->will($this->returnValue(true)); 
     198        $this->assertEquals(3, $this->cacheContainer->put('bar' . DIRECTORY_SEPARATOR . 'foo', 'bar')); 
    182199        $this->assertTrue($this->cacheDirectory->hasChild('barfoo.cache')); 
    183         $this->assertEqual($this->cacheDirectory->getChild('barfoo.cache')->getContent(), 'bar'); 
    184          
    185         $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    186         $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', false); 
    187         $this->mockCacheStrategy->setReturnValueAt(2, 'isExpired', false); 
    188         $this->mockCacheStrategy->setReturnValueAt(3, 'isExpired', false); 
    189         $this->mockCacheStrategy->setReturnValueAt(4, 'isExpired', true); 
     200        $this->assertEquals('bar', $this->cacheDirectory->getChild('barfoo.cache')->getContent()); 
     201        $this->mockCacheStrategy->expects($this->exactly(5)) 
     202                                ->method('isExpired') 
     203                                ->will($this->onConsecutiveCalls(false, false, false, false, true)); 
    190204        $this->assertTrue($this->cacheContainer->has('bar' . DIRECTORY_SEPARATOR . 'foo')); 
    191         $this->assertEqual($this->cacheContainer->get('bar' . DIRECTORY_SEPARATOR . 'foo'), 'bar'); 
    192         $this->assertEqual($this->cacheContainer->getKeys(), array('barfoo' => 'barfoo')); 
    193         $this->assertEqual($this->cacheContainer->getSize('bar' . DIRECTORY_SEPARATOR . 'foo'), 3); 
    194         $this->assertEqual($this->cacheContainer->getUsedSpace(), 3); 
    195         $this->mockCacheStrategy->setReturnValue('shouldRunGc', true); 
     205        $this->assertEquals('bar', $this->cacheContainer->get('bar' . DIRECTORY_SEPARATOR . 'foo')); 
     206        $this->assertEquals(array('barfoo' => 'barfoo'), $this->cacheContainer->getKeys()); 
     207        $this->assertEquals(3, $this->cacheContainer->getSize('bar' . DIRECTORY_SEPARATOR . 'foo')); 
     208        $this->assertEquals(3, $this->cacheContainer->getUsedSpace()); 
    196209        $this->cacheContainer->gc(); 
    197210        $this->assertFalse($this->cacheDirectory->hasChild('barfoo.cache')); 
     
    200213    /** 
    201214     * test a key that contains a directory seperator 
    202      */ 
    203     public function testtestKeyContainingDirectorySeperatorAndExistingCacheFile() 
     215     * 
     216     * @test 
     217     */ 
     218    public function keyContainingDirectorySeperatorAndExistingCacheFile() 
    204219    { 
    205220        $this->cacheDirectory->addChild(vfsS