[TYPO3-50-general] vfsstream and braindeath

Christoph Blömer chbloemer at gmx.net
Sat Feb 14 11:08:56 CET 2009


Finally I found a solution,
if you change the test to the following (added a rewind() after the 
opendir()) it works:
    /**
     * @test
     */        
    public function vfsstream(){
       
        $dir = $this->url1;
        $list1 = array();     
        if ($handle = opendir($dir)) {
            rewind($handle);
            while (false !== ($listItem = readdir($handle))) {
                if ($listItem != "." && $listItem != "..") {
                    if(is_file($dir.'/'.$listItem)) {
                        $list1[] = "File:[".$listItem."]";
                    } else if(is_dir($dir.'/'.$listItem)) {
                        $list1[] = "Folder:[".$listItem."]";
                    }
                }
            }
            closedir($handle);
        }

        $list2 = array();       
        if ($handle = opendir($dir)) {
            rewind($handle);
            while (false !== ($listItem = readdir($handle))) {
                if ($listItem != "." && $listItem != "..") {
                    if(is_file($dir.'/'.$listItem)) {
                        $list2[] = "File:[".$listItem."]";
                    } else if(is_dir($dir.'/'.$listItem)) {
                        $list2[] = "Folder:[".$listItem."]";
                    }
                }
            }
            closedir($handle);
        }
        $this->assertEquals(count($list1), count($list2));
    }

That's a solution to to get this test work correct. But you also have to 
add the rewind to each code part in your application.

Greetings
Christoph

Christoph Blömer schrieb:
> Hello,
> last night I was writing a unit test for my Virtual File System package. 
> I wanted to navigate through the filesystem and check if the correct 
> folders and files can be retrieved.
> But the tests always failed. A little later i noticed that if files were 
> read once they a removed from the vfsstream.
> This is a test I wrote to verify the behaviour.
> $this->url1 is the root of the vfsstream root.
> If it is a normal filesystem the test works.
> count($list2) is always 0!!!
>
>     /**
>      * @test
>      */         
>     public function vfsstream(){
>         
>         $dir = $this->url1;
>         $list1 = array();      
>         if ($handle = opendir($dir)) {
>             while (false !== ($listItem = readdir($handle))) {
>                 if ($listItem != "." && $listItem != "..") {
>                     if(is_file($dir.'/'.$listItem)) {
>                         $list1[] = "File:[".$listItem."]";
>                     } else if(is_dir($dir.'/'.$listItem)) {
>                         $list1[] = "Folder:[".$listItem."]";
>                     }
>                 }
>             }
>             closedir($handle);
>         }
>
>         $list2 = array();        
>         if ($handle = opendir($dir)) {
>             while (false !== ($listItem = readdir($handle))) {
>                 if ($listItem != "." && $listItem != "..") {
>                     if(is_file($dir.'/'.$listItem)) {
>                         $list2[] = "File:[".$listItem."]";
>                     } else if(is_dir($dir.'/'.$listItem)) {
>                         $list2[] = "Folder:[".$listItem."]";
>                     }
>                 }
>             }
>             closedir($handle);
>         }
>         $this->assertEquals(count($list1), count($list2));
> }
>
> Any ideas what's wrong or how to prevent this problem?
>
> Greetings
> Christoph
> _______________________________________________
> TYPO3-project-5_0-general mailing list
> TYPO3-project-5_0-general at lists.netfielders.de
> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-project-5_0-general
>
>   



More information about the TYPO3-project-5_0-general mailing list