Changeset 1196

Show
Ignore:
Timestamp:
12/29/07 00:40:53 (6 months ago)
Author:
mikey
Message:

added vfsStreamFile::withContent(), made vfsStreamFile::setContent() an alias of this (more fluent api)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/vfs/package.php

    r1195 r1196  
    4444- a call to vfsStreamWrapper::register() will now reset the root to null (implemented because of a hint by David Zülke) 
    4545- added support for is_readable(), is_dir(), is_file() 
    46 - added vfsStream::newFile() to be able to do $file = vfsStream::newFile("foo.txt")->setContent("bar"); 
     46- added vfsStream::newFile() to be able to do $file = vfsStream::newFile("foo.txt")->withContent("bar"); 
    4747')); 
    4848 
  • trunk/src/main/php/org/stubbles/vfs/vfsStreamFile.php

    r1195 r1196  
    6161 
    6262    /** 
     63     * alias for withContent() 
     64     * 
     65     * @param   string  $content 
     66     * @return  vfsStreamFile 
     67     * @see     withContent() 
     68     */ 
     69    public function setContent($content) 
     70    { 
     71        return $this->withContent($content); 
     72    } 
     73 
     74    /** 
    6375     * sets the contents of the file 
    6476     * 
    6577     * @param   string  $content 
    6678     * @return  vfsStreamFile 
     79     * @see     setContent() 
    6780     */ 
    68     public function setContent($content) 
     81    public function withContent($content) 
    6982    { 
    7083        $this->content = $content; 
  • trunk/src/test/php/net/stubbles/util/cache/stubFileCacheContainerTestCase.php

    r1195 r1196  
    7676    public function testHas() 
    7777    { 
    78         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
     78        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    7979        $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    8080        $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
     
    9090    public function testGet() 
    9191    { 
    92         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
     92        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    9393        $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    9494        $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
     
    104104    public function testGetSize() 
    105105    { 
    106         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
     106        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    107107        $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    108108        $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
     
    118118    public function testGetUsedSpace() 
    119119    { 
    120         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
     120        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    121121        $this->assertEqual($this->cacheContainer->getUsedSpace(), 3); 
    122122        $this->mockCacheStrategy->setReturnValueAt(0, 'isCachable', true); 
     
    130130    public function testGetKeys() 
    131131    { 
    132         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
     132        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    133133        $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    134134        $this->assertEqual($this->cacheContainer->getKeys(), array('foo' => 'foo')); 
     
    148148    public function testGc() 
    149149    { 
    150         $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
     150        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->withContent('bar')); 
    151151        $this->mockCacheStrategy->setReturnValue('shouldRunGc', true); 
    152152        $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
     
    195195    public function testtestKeyContainingDirectorySeperatorAndExistingCacheFile() 
    196196    { 
    197         $this->cacheDirectory->addChild(vfsStream::newFile('barfoo.cache')->setContent('bar')); 
     197        $this->cacheDirectory->addChild(vfsStream::newFile('barfoo.cache')->withContent('bar')); 
    198198        $this->assertTrue($this->cacheContainer->has('bar' . DIRECTORY_SEPARATOR . 'foo')); 
    199199        $this->assertEqual($this->cacheContainer->get('bar' . DIRECTORY_SEPARATOR . 'foo'), 'bar'); 
  • trunk/src/test/php/org/stubbles/vfs/vfsStreamFileTestCase.php

    r1143 r1196  
    4242        $this->assertFalse($this->file->appliesTo('bar')); 
    4343        $this->assertFalse($this->file->hasChild('bar')); 
     44    } 
     45 
     46    /** 
     47     * test setting and getting the content of a file 
     48     */ 
     49    public function testContent() 
     50    { 
     51        $this->assertNull($this->file->getContent()); 
     52        $this->assertReference($this->file, $this->file->setContent('bar')); 
     53        $this->assertEqual('bar', $this->file->getContent()); 
     54        $this->assertReference($this->file, $this->file->withContent('baz')); 
     55        $this->assertEqual('baz', $this->file->getContent()); 
    4456    } 
    4557