Changeset 1288
- Timestamp:
- 01/23/08 17:53:13 (10 months ago)
- Files:
-
- trunk/src/test/AllTests.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/util/BinfordTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/util/UtilTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/util/cache/stubAbstractCacheContainerTestCase.php (modified) (7 diffs)
- trunk/src/test/php/net/stubbles/util/cache/stubCacheTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/util/cache/stubDefaultCacheStrategyTestCase.php (modified) (4 diffs)
- trunk/src/test/php/net/stubbles/util/cache/stubFileCacheContainerTestCase.php (modified) (8 diffs)
- trunk/src/test/php/net/stubbles/util/datespan/stubDateSpanCustomTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/util/datespan/stubDateSpanDayTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/util/datespan/stubDateSpanMonthTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/util/datespan/stubDateSpanWeekTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/util/log/stubBaseLogDataTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/util/log/stubFileLogAppenderTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/util/log/stubLogDataFactoryTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/util/log/stubLoggerTestCase.php (modified) (17 diffs)
- trunk/src/test/php/net/stubbles/util/log/stubLoggerXJConfFactoryTestCase.php (modified) (5 diffs)
- trunk/src/test/php/net/stubbles/util/log/stubMemoryLogAppenderTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/util/stubRegistryTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/util/stubRegistryXJConfInitializerTestCase.php (modified) (3 diffs)
- trunk/src/test/run.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/test/AllTests.php
r1272 r1288 28 28 require_once $dir . '/php/net/stubbles/ioc/IOCTestSuite.php'; 29 29 require_once $dir . '/php/net/stubbles/ipo/IPOTestSuite.php'; 30 require_once $dir . '/php/net/stubbles/util/UtilTestSuite.php'; 30 31 require_once $dir . '/php/net/stubbles/websites/WebsitesTestSuite.php'; 31 32 require_once $dir . '/php/net/stubbles/websites/variantmanager/VariantManagerTestSuite.php'; … … 60 61 $suite->addTestSuite('IOCTestSuite'); 61 62 $suite->addTestSuite('IPOTestSuite'); 63 $suite->addTestSuite('UtilTestSuite'); 62 64 $suite->addTestSuite('WebsitesTestSuite'); 63 65 $suite->addTestSuite('VariantManagerTestSuite'); trunk/src/test/php/net/stubbles/util/BinfordTestCase.php
r1230 r1288 14 14 * @subpackage util_test 15 15 */ 16 class BinfordTestCase extends UnitTestCase16 class BinfordTestCase extends PHPUnit_Framework_TestCase 17 17 { 18 18 /** … … 33 33 /** 34 34 * assure that values are returned as expected 35 * 36 * @test 35 37 */ 36 public function testValidate()38 public function validate() 37 39 { 38 40 $this->assertTrue($this->binford->validate(Binford::POWER)); … … 44 46 /** 45 47 * assure that values are returned as expected 48 * 49 * @test 46 50 */ 47 public function testGetCriteria()51 public function getCriteria() 48 52 { 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()); 50 54 } 51 55 52 56 /** 53 57 * assure that values are returned as expected 58 * 59 * @test 54 60 */ 55 public function testFilter()61 public function filter() 56 62 { 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')); 61 67 } 62 68 63 69 /** 64 70 * assert that the binford hash code always equals the power of binford 71 * 72 * @test 65 73 */ 66 public function testHashCode()74 public function hashCode() 67 75 { 68 $this->assertEqual ($this->binford->hashCode(), Binford::POWER);76 $this->assertEquals(Binford::POWER, $this->binford->hashCode()); 69 77 } 70 78 71 79 /** 72 80 * assure that any Binford instance is equal to any other 81 * 82 * @test 73 83 */ 74 public function testEquals()84 public function equals() 75 85 { 76 86 $this->assertTrue($this->binford->equals($this->binford)); trunk/src/test/php/net/stubbles/util/UtilTestSuite.php
r1106 r1288 13 13 * @subpackage test 14 14 */ 15 class UtilTestSuite extends TestSuite15 class UtilTestSuite extends PHPUnit_Framework_TestSuite 16 16 { 17 17 /** 18 * constructor 18 * returns the test suite to be run 19 * 20 * @return PHPUnit_Framework_TestSuite 19 21 */ 20 public function __construct()22 public static function suite() 21 23 { 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'); 27 29 28 30 // 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'); 33 35 34 36 // 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'); 39 41 40 42 // 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'); 47 49 48 50 // 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'); 52 54 53 55 // net_http classes 54 $this->addTestFile($dir . '/net/http/stubHTTPURLTestCase.php');56 #$suite->addTestFile($dir . '/net/http/stubHTTPURLTestCase.php'); 55 57 56 58 // 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'); 71 73 72 74 // xjconf 73 $this->addTestFile($dir . '/xjconf/stubXJConfProxyTestCase.php'); 75 #$suite->addTestFile($dir . '/xjconf/stubXJConfProxyTestCase.php'); 76 return $suite; 74 77 } 75 78 } trunk/src/test/php/net/stubbles/util/cache/stubAbstractCacheContainerTestCase.php
r1230 r1288 8 8 */ 9 9 stubClassLoader::load('net::stubbles::util::cache::stubAbstractCacheContainer'); 10 Mock::generate('stubCacheStrategy');11 10 class TeststubAbstractCacheContainer extends stubAbstractCacheContainer implements stubCacheContainer 12 11 { … … 81 80 } 82 81 /** 83 * Tests for net::stubbles::util .cache.stubAbstractCacheContainer.82 * Tests for net::stubbles::util::cache::stubAbstractCacheContainer. 84 83 * 85 84 * @package stubbles 86 85 * @subpackage util_cache_test 87 86 */ 88 class stubAbstractCacheContainerTestCase extends UnitTestCase87 class stubAbstractCacheContainerTestCase extends PHPUnit_Framework_TestCase 89 88 { 90 89 /** … … 97 96 * a mocked cache strategy 98 97 * 99 * @var SimpleMock98 * @var PHPUnit_Framework_MockObject_MockObject 100 99 */ 101 100 protected $mockCacheStrategy; … … 106 105 public function setUp() 107 106 { 108 $this->mockCacheStrategy = new MockstubCacheStrategy();107 $this->mockCacheStrategy = $this->getMock('stubCacheStrategy'); 109 108 $this->cacheContainer = new TeststubAbstractCacheContainer('foo'); 110 109 $this->cacheContainer->setStrategy($this->mockCacheStrategy); … … 113 112 /** 114 113 * 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()); 119 120 } 120 121 121 122 /** 122 123 * 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()); 133 136 } 134 137 135 138 /** 136 139 * 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)); 144 149 $this->assertTrue($this->cacheContainer->has('foo')); 145 150 $this->assertFalse($this->cacheContainer->has('foo')); … … 149 154 /** 150 155 * 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')); 159 166 $this->assertNull($this->cacheContainer->get('foo')); 160 167 $this->assertNull($this->cacheContainer->get('bar')); … … 163 170 /** 164 171 * 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')); 175 184 } 176 185 177 186 /** 178 187 * 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)); 184 196 $this->assertNull($this->cacheContainer->lastGcRun()); 185 197 $this->cacheContainer->gc(); 186 198 $this->assertNull($this->cacheContainer->lastGcRun()); 187 199 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)); 190 204 $this->cacheContainer->gc(); 191 $this->assertEqual ($this->cacheContainer->data, array());205 $this->assertEquals(array(), $this->cacheContainer->data); 192 206 $this->assertNotNull($this->cacheContainer->lastGcRun()); 193 207 } trunk/src/test/php/net/stubbles/util/cache/stubCacheTestCase.php
r1230 r1288 8 8 */ 9 9 stubClassLoader::load('net::stubbles::util::cache::stubCache'); 10 Mock::generate('stubCacheContainer');11 10 /** 12 11 * Tests for net::stubbles::util::cache::stubCache. … … 15 14 * @subpackage util_cache_test 16 15 */ 17 class stubCacheTestCase extends UnitTestCase16 class stubCacheTestCase extends PHPUnit_Framework_TestCase 18 17 { 19 18 /** 20 19 * assure that retrieving a non-existing container triggers an exception 20 * 21 * @test 22 * @expectedException stubRuntimeException 21 23 */ 22 public function testNoContainer()24 public function noContainer() 23 25 { 24 $this-> expectException('stubRuntimeException');26 $this->assertFalse(stubCache::has('foo')); 25 27 stubCache::factory('foo'); 26 28 } … … 28 30 /** 29 31 * assure that retrieving a container returns the correct one 32 * 33 * @test 30 34 */ 31 public function testWithContainer()35 public function withContainer() 32 36 { 33 $mockContainer = new MockstubCacheContainer();34 $mockContainer-> setReturnValue('getId', 'foo');35 $mockContainer->expect Once('gc');37 $mockContainer = $this->getMock('stubCacheContainer'); 38 $mockContainer->expects($this->any())->method('getId')->will($this->returnValue('foo')); 39 $mockContainer->expects($this->once())->method('gc'); 36 40 stubCache::addContainer($mockContainer); 37 41 $this->assertTrue(stubCache::has('foo')); 38 42 $this->assertFalse(stubCache::has('bar')); 39 43 $fooCache = stubCache::factory('foo'); 40 $this->assertReference($fooCache, $mockContainer); 41 $this->expectException('stubRuntimeException'); 42 stubCache::factory('bar'); 44 $this->assertSame($mockContainer, $fooCache); 43 45 } 44 46 } trunk/src/test/php/net/stubbles/util/cache/stubDefaultCacheStrategyTestCase.php
r1230 r1288 8 8 */ 9 9 stubClassLoader::load('net::stubbles::util::cache::stubDefaultCacheStrategy'); 10 Mock::generate('stubCacheContainer');11 10 /** 12 11 * Tests for net::stubbles::util::cache::stubDefaultCacheStrategy. … … 15 14 * @subpackage util_cache_test 16 15 */ 17 class stubDefaultCacheStrategyTestCase extends UnitTestCase16 class stubDefaultCacheStrategyTestCase extends PHPUnit_Framework_TestCase 18 17 { 19 18 /** 20 19 * assure that retrieving a non-existing container triggers an exception 20 * 21 * @test 21 22 */ 22 public function testIsCachable()23 public function isCachable() 23 24 { 24 25 $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)); 28 33 $this->assertTrue($defaultCacheStrategy->isCachable($mockContainer, 'a', 'a')); 29 30 $mockContainer->setReturnValueAt(1, 'getUsedSpace', 1);31 $mockContainer->setReturnValueAt(1, 'getSize', 0);32 34 $this->assertFalse($defaultCacheStrategy->isCachable($mockContainer, 'a', 'ab')); 33 34 $mockContainer->setReturnValueAt(2, 'getUsedSpace', 1);35 $mockContainer->setReturnValueAt(2, 'getSize', 1);36 35 $this->assertTrue($defaultCacheStrategy->isCachable($mockContainer, 'a', 'a')); 37 38 $mockContainer->setReturnValueAt(3, 'getUsedSpace', 2);39 $mockContainer->setReturnValueAt(3, 'getSize', 2);40 36 $this->assertTrue($defaultCacheStrategy->isCachable($mockContainer, 'a', 'a')); 41 42 $mockContainer->setReturnValueAt(4, 'getUsedSpace', 2);43 $mockContainer->setReturnValueAt(4, 'getSize', 0);44 37 $this->assertFalse($defaultCacheStrategy->isCachable($mockContainer, 'a', 'a')); 45 46 $mockContainer->setReturnValueAt(5, 'getUsedSpace', 0);47 $mockContainer->setReturnValueAt(5, 'getSize', 0);48 38 $this->assertTrue($defaultCacheStrategy->isCachable($mockContainer, 'a', 'ab')); 49 39 50 40 $defaultCacheStrategy = new stubDefaultCacheStrategy(10, -1, 0); 51 $mockContainer->setReturnValueAt(7, 'getUsedSpace', 6);52 $mockContainer->setReturnValueAt(7, 'getSize', 0);53 41 $this->assertTrue($defaultCacheStrategy->isCachable($mockContainer, 'a', 'ab')); 54 42 } … … 56 44 /** 57 45 * assure that retrieving a container returns the correct one 46 * 47 * @test 58 48 */ 59 public function testIsExpired()49 public function isExpired() 60 50 { 61 51 $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)); 66 56 67 57 $this->assertFalse($defaultCacheStrategy->isExpired($mockContainer, 'a')); … … 72 62 /** 73 63 * assure that retrieving a container returns the correct one 64 * 65 * @test 74 66 */ 75 public function testShouldRunGc()67 public function shouldRunGc() 76 68 { 77 69 $defaultCacheStrategy = new stubDefaultCacheStrategy(10, 2, 0); 78 $mockContainer = new MockstubCacheContainer();70 $mockContainer = $this->getMock('stubCacheContainer'); 79 71 $this->assertFalse($defaultCacheStrategy->shouldRunGc($mockContainer)); 80 72 $this->assertFalse($defaultCacheStrategy->shouldRunGc($mockContainer)); trunk/src/test/php/net/stubbles/util/cache/stubFileCacheContainerTestCase.php
r1230 r1288 8 8 */ 9 9 stubClassLoader::load('net::stubbles::util::cache::stubFileCacheContainer'); 10 Mock::generate('stubCacheStrategy');11 10 @include_once 'vfsStream/vfsStream.php'; 12 11 /** … … 16 15 * @subpackage util_cache_test 17 16 */ 18 class stubFileCacheContainerTestCase extends UnitTestCase17 class stubFileCacheContainerTestCase extends PHPUnit_Framework_TestCase 19 18 { 20 19 /** … … 27 26 * a mocked cache strategy 28 27 * 29 * @var SimpleMock28 * @var PHPUnit_Framework_MockObject_MockObject 30 29 */ 31 30 protected $mockCacheStrategy; … … 38 37 39 38 /** 40 * skip the test if vfsStream is not available41 */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 /**48 39 * set up test environment 49 40 */ 50 41 public function setUp() 51 42 { 43 if (class_exists('vfsStream', false) === false) { 44 $this->markTestSkipped('stubFileCacheContainerTestCase requires vfsStream, see http://vfs.bovigo.org/.'); 45 } 46 52 47 vfsStreamWrapper::register(); 53 48 vfsStreamWrapper::setRoot(new vfsStreamDirectory('cache')); 54 $this->mockCacheStrategy = new MockstubCacheStrategy();49 $this->mockCacheStrategy = $this->getMock('stubCacheStrategy'); 55 50 $this->cacheContainer = new stubFileCacheContainer('id'); 56 51 $this->cacheContainer->setStrategy($this->mockCacheStrategy); … … 61 56 /** 62 57 * 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)); 69 66 70 $this->assertEqual ($this->cacheContainer->put('foo', 'bar'), 3);71 $this->assert Equal($this->cacheContainer->put('baz', 'bar'), false);67 $this->assertEquals(3, $this->cacheContainer->put('foo', 'bar')); 68 $this->assertFalse($this->cacheContainer->put('baz', 'bar')); 72 69 $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()); 74 71 $this->assertFalse($this->cacheDirectory->hasChild('baz.cache')); 75 72 76 $this->assertEqual ($this->cacheContainer->put('foo', 'baz'), 3);73 $this->assertEquals(3, $this->cacheContainer->put('foo', 'baz')); 77 74 $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()); 79 76 } 80 77 81 78 /** 82 79 * 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)); 90 89 $this->assertTrue($this->cacheContainer->has('foo')); 91 90 $this->assertFalse($this->cacheContainer->has('foo')); … … 95 94 /** 96 95 * 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')); 105 106 $this->assertNull($this->cacheContainer->get('foo')); 106 107 $this->assertNull($this->cacheContainer->get('bar')); … … 109 110 /** 110 111 * 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')); 121 124 } 122 125 123 126 /** 124 127 * 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)); 131 138 $this->cacheContainer->put('bar', 'baz'); 132 $this->assertEqual ($this->cacheContainer->getUsedSpace(), 6);139 $this->assertEquals(6, $this->cacheContainer->getUsedSpace()); 133 140 } 134 141 135 142 /** 136 143 * 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()); 144 157 $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()); 151 160 } 152 161 153 162 /** 154 163 * 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)); 161 176 $this->cacheContainer->gc(); 162 177 $this->assertTrue($this->cacheDirectory->hasChild('foo.cache')); 163 164 $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true);165 178 $this->cacheContainer->gc(); 166 179 $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);170 180 $this->assertFalse($this->cacheContainer->has('foo')); 171 181 $this->assertNull($this->cacheContainer->get('foo')); 172 $this->assertEqual ($this->cacheContainer->getSize('foo'), 0);182 $this->assertEquals(0, $this->cacheContainer->getSize('foo')); 173 183 } 174 184 175 185 /** 176 186 * 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')); 182 199 $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)); 190 204 $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()); 196 209 $this->cacheContainer->gc(); 197 210 $this->assertFalse($this->cacheDirectory->hasChild('barfoo.cache')); … … 200 213 /** 201 214 * test a key that contains a directory seperator 202 */ 203 public function testtestKeyContainingDirectorySeperatorAndExistingCacheFile() 215 * 216 * @test 217 */ 218 public function keyContainingDirectorySeperatorAndExistingCacheFile() 204 219 { 205 220 $this->cacheDirectory->addChild(vfsS
