| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace MapperNoRootTests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use kalanis\kw_files\FilesException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use kalanis\kw_mapper\MapperException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use kalanis\kw_paths\PathsException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class StreamTest extends AStorageTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * @throws FilesException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * @throws MapperException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @throws PathsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     public function testRead(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         if ($this->skipIt) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |             $this->markTestSkipped('Skipped by config'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->dataRefill(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $lib = $this->getStreamLib(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $this->assertEquals('qwertzuiopasdfghjklyxcvbnm0123456789', $this->streamToString($lib->readFileStream(['dummy2.txt']))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @throws FilesException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @throws MapperException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @throws PathsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public function testReadNonExist(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         if ($this->skipIt) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             $this->markTestSkipped('Skipped by config'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->dataRefill(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $lib = $this->getStreamLib(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->expectException(FilesException::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $lib->readFileStream(['unknown']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @throws FilesException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @throws MapperException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @throws PathsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     public function testReadFalse(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         if ($this->skipIt) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             $this->markTestSkipped('Skipped by config'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $this->dataRefill(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $lib = $this->getStreamLib(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $this->expectException(FilesException::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $lib->readFileStream(['sub', 'dummy_nope.txt']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @throws FilesException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @throws MapperException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @throws PathsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     public function testSave(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         if ($this->skipIt) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             $this->markTestSkipped('Skipped by config'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->dataRefill(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $lib = $this->getStreamLib(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $this->assertTrue($lib->saveFileStream(['extra.txt'], $this->stringToStream('qwertzuiopasdfghjklyxcvbnm0123456789'))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $this->assertEquals('qwertzuiopasdfghjklyxcvbnm0123456789', $this->streamToString($lib->readFileStream(['extra.txt']))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @throws FilesException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @throws MapperException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @throws PathsException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 92 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |     public function testSave2(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |         if ($this->skipIt) { | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |             $this->markTestSkipped('Skipped by config'); | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |             return; | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |         $this->dataRefill(); | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |         $lib = $this->getStreamLib(); | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |         $this->assertTrue($lib->saveFileStream(['sub', 'foul.txt'], $this->stringToStream('qwertzuiopasdfghjklyxcvbnm0123456789'))); | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |         $this->assertEquals('qwertzuiopasdfghjklyxcvbnm0123456789', $this->streamToString($lib->readFileStream(['sub', 'foul.txt']))); | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |         $this->assertTrue($lib->saveFileStream(['sub', 'foul.txt'], $this->stringToStream('qwertzuiopasdfghjklyxcvbnm0123456789'), FILE_APPEND)); | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |         $this->assertEquals('qwertzuiopasdfghjklyxcvbnm0123456789qwertzuiopasdfghjklyxcvbnm0123456789', $this->streamToString($lib->readFileStream(['sub', 'foul.txt']))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @throws FilesException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @throws MapperException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * @throws PathsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     public function testCopyMoveDelete(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         if ($this->skipIt) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             $this->markTestSkipped('Skipped by config'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $this->dataRefill(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         $lib = $this->getStreamLib(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $this->assertTrue($lib->copyFileStream(['dummy2.txt'], ['extra1.txt'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $this->assertTrue($lib->moveFileStream(['extra1.txt'], ['extra2.txt'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $lib2 = $this->getFileLib(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         $this->assertTrue($lib2->deleteFile(['extra2.txt'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $this->assertTrue($lib2->deleteFile(['extra3.txt'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 130 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 131 |  |  |  |