| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * This software consists of voluntary contributions made by many individuals | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * and is licensed under the LGPL. For more information please see | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * <http://phing.info>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | namespace Phing\Test\Task\System; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Phing\Test\Support\BuildFileTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * Tests the Copy Task. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * @author  Michiel Rook <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * @internal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | class CopyTaskTest extends BuildFileTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function setUp(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->configureProject( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             PHING_TEST_BASE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             . '/etc/tasks/system/CopyTask/CopyTaskTest.xml' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->executeTarget('setup'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function tearDown(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->executeTarget('clean'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     public function testCopyDanglingSymlink(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->executeTarget('testCopyDanglingSymlink'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->assertInLogs('Copying 1 file to'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * Test for {@link http://www.phing.info/trac/ticket/981} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * FileUtil::copyFile(): preserveLastModified causes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * empty symlink target file. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     public function testCopySymlinkPreserveLastModifiedShouldCopyTarget(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $this->executeTarget(__FUNCTION__); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $this->assertInLogs('Copying 2 files to'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $this->assertGreaterThan(0, $this->project->getProperty('test.filesize')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * Regression test for ticket {@link http://www.phing.info/trac/ticket/229} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * - CopyTask should accept filelist subelement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     public function testCopyFileList(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $this->executeTarget(__FUNCTION__); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $this->assertInLogs('Copying 2 files to'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * - CopyTask should accept dirset subelement. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     public function testCopyDirSet(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |         $this->executeTarget(__FUNCTION__); | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |         $this->assertInLogs('Copying 2 files to'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * Regression test for ticket {@link https://github.com/phingofficial/phing/issues/562} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * - Error overwriting symlinks on copy or move. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     public function testOverwriteExistingSymlink(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $this->executeTarget(__FUNCTION__); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $this->assertInLogs('Copying 1 file to'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $this->assertEquals('tmp/target-a', readlink(PHING_TEST_BASE . '/etc/tasks/system/CopyTask/tmp/link-b')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     public function testGranularity(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $this->expectLogContaining(__FUNCTION__, 'Test omitted, Test is up to date'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     public function testFilesetFiles(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $destinationDir = PHING_TEST_BASE . '/etc/tasks/system/CopyTask/tmp/destination'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $this->assertDirectoryDoesNotExist($destinationDir); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $this->executeTarget(__FUNCTION__); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $this->assertFileExists("$destinationDir/Foo/Foo.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $this->assertFileExists("$destinationDir/Bar/Bar.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $this->assertFileExists("$destinationDir/Baz/Baz.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $this->assertFileExists("$destinationDir/Qux/Qux.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $this->assertFileDoesNotExist("$destinationDir/Foo/FooTest.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $this->assertFileDoesNotExist("$destinationDir/Bar/BarTest.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         $this->assertFileDoesNotExist("$destinationDir/Baz/BazTest.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $this->assertFileDoesNotExist("$destinationDir/Qux/QuxTest.php"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 115 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |  |