Changeset 1195

Show
Ignore:
Timestamp:
12/29/07 00:31:17 (9 months ago)
Author:
mikey
Message:

added vfsStream::newFile() to be able to do $file = vfsStream::newFile("foo.txt")->setContent("bar");

Files:

Legend:

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

    r1193 r1195  
    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"); 
    4647')); 
    4748 
  • trunk/src/main/php/org/stubbles/vfs/vfsStream.php

    r1189 r1195  
    4343        return $path; 
    4444    } 
     45 
     46    /** 
     47     * returns a new file with given name 
     48     * 
     49     * @param   string         $name 
     50     * @return  vfsStreamFile 
     51     */ 
     52    public static function newFile($name) 
     53    { 
     54        return new vfsStreamFile($name); 
     55    } 
    4556} 
    4657?> 
  • trunk/src/main/php/org/stubbles/vfs/vfsStreamFile.php

    r1143 r1195  
    6363     * sets the contents of the file 
    6464     * 
    65      * @param  string  $content 
     65     * @param   string  $content 
     66     * @return  vfsStreamFile 
    6667     */ 
    6768    public function setContent($content) 
    6869    { 
    6970        $this->content = $content; 
     71        return $this; 
    7072    } 
    7173 
  • trunk/src/test/php/net/stubbles/util/cache/stubFileCacheContainerTestCase.php

    r1183 r1195  
    7676    public function testHas() 
    7777    { 
    78         $foo = new vfsStreamFile('foo.cache'); 
    79         $foo->setContent('bar'); 
    80         $this->cacheDirectory->addChild($foo); 
     78        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
    8179        $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    8280        $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
     
    9290    public function testGet() 
    9391    { 
    94         $foo = new vfsStreamFile('foo.cache'); 
    95         $foo->setContent('bar'); 
    96         $this->cacheDirectory->addChild($foo); 
     92        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
    9793        $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    9894        $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
     
    108104    public function testGetSize() 
    109105    { 
    110         $foo = new vfsStreamFile('foo.cache'); 
    111         $foo->setContent('bar'); 
    112         $this->cacheDirectory->addChild($foo); 
     106        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
    113107        $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    114108        $this->mockCacheStrategy->setReturnValueAt(1, 'isExpired', true); 
     
    124118    public function testGetUsedSpace() 
    125119    { 
    126         $foo = new vfsStreamFile('foo.cache'); 
    127         $foo->setContent('bar'); 
    128         $this->cacheDirectory->addChild($foo); 
     120        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
    129121        $this->assertEqual($this->cacheContainer->getUsedSpace(), 3); 
    130122        $this->mockCacheStrategy->setReturnValueAt(0, 'isCachable', true); 
     
    138130    public function testGetKeys() 
    139131    { 
    140         $foo = new vfsStreamFile('foo.cache'); 
    141         $foo->setContent('bar'); 
    142         $this->cacheDirectory->addChild($foo); 
     132        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
    143133        $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
    144134        $this->assertEqual($this->cacheContainer->getKeys(), array('foo' => 'foo')); 
     
    158148    public function testGc() 
    159149    { 
    160         $foo = new vfsStreamFile('foo.cache'); 
    161         $foo->setContent('bar'); 
    162         $this->cacheDirectory->addChild($foo); 
     150        $this->cacheDirectory->addChild(vfsStream::newFile('foo.cache')->setContent('bar')); 
    163151        $this->mockCacheStrategy->setReturnValue('shouldRunGc', true); 
    164152        $this->mockCacheStrategy->setReturnValueAt(0, 'isExpired', false); 
     
    207195    public function testtestKeyContainingDirectorySeperatorAndExistingCacheFile() 
    208196    { 
    209         $foo = new vfsStreamFile('barfoo.cache'); 
    210         $foo->setContent('bar'); 
    211         $this->cacheDirectory->addChild($foo); 
     197        $this->cacheDirectory->addChild(vfsStream::newFile('barfoo.cache')->setContent('bar')); 
    212198        $this->assertTrue($this->cacheContainer->has('bar' . DIRECTORY_SEPARATOR . 'foo')); 
    213199        $this->assertEqual($this->cacheContainer->get('bar' . DIRECTORY_SEPARATOR . 'foo'), 'bar'); 
  • trunk/src/test/php/org/stubbles/vfs/vfsStreamTestCase.php

    r1189 r1195  
    3636        $this->assertEqual('foo/bar.baz', vfsStream::path('vfs://foo\bar.baz')); 
    3737    } 
     38 
     39    /** 
     40     * test to create a new file 
     41     */ 
     42    public function testNewFile() 
     43    { 
     44        $file = vfsStream::newFile('filename.txt'); 
     45        $this->assertIsA($file, 'vfsStreamFile'); 
     46        $this->assertEqual('filename.txt', $file->getName()); 
     47    } 
    3848} 
    3949?>