| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * This software consists of voluntary contributions made by many individuals | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * and is licensed under the LGPL. For more information please see | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * <http://phing.info>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | namespace Phing; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Phing\Io\OutputStream; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Phing\Util\Timer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * Core Phing class test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * Do not know why there was no test at all | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * // TODO implement all methods | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * @author Kirill chEbba Chebunin <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | class PhingTest extends \PHPUnit\Framework\TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     private const NAMESPACED_CLASS = 'Vendor\\Package\\FullSeparatedClass'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     private const SEPARATED_CLASS = 'Vendor_Package_SeparatedClass'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     protected $classpath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * Test a PSR-0 support of class loading | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @link http://groups.google.com/group/php-standards/web/psr-0-final-proposal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public function testImportPSR0() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         // Test the namespace support | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $className = Phing::import(self::NAMESPACED_CLASS, self::getClassPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         self::assertEquals(self::NAMESPACED_CLASS, $className); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         self::assertTrue(class_exists(self::NAMESPACED_CLASS)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     public function testImportPEAR() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         // Test PEAR standard | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $className = Phing::import(self::SEPARATED_CLASS, self::getClassPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         self::assertEquals(self::SEPARATED_CLASS, $className); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         self::assertTrue(class_exists(self::SEPARATED_CLASS)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public function testTimer() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $this->assertInstanceOf(Timer::class, Phing::getTimer()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function testGetPhingVersion() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $this->assertStringStartsWith('Phing ', Phing::getPhingVersion()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @requires PHP >= 7.2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     public function testPrintTargets() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $target = $this->getMockBuilder(Target::class)->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $target->method('getDependencies')->willReturn([]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $project = $this->getMockBuilder(Project::class)->disableOriginalConstructor()->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $project->method('getTargets')->willReturn([$target]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $phing = new Phing(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $phing::setOutputStream($this->getMockBuilder(OutputStream::class)->disableOriginalConstructor()->getMock()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $project->expects($this->atLeastOnce()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             ->method('log'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $phing->printTargets($project); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @requires PHP >= 7.2 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |     public function testPrintUsage(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |         $phing = new Phing(); | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |         $stream = $this->getMockBuilder(OutputStream::class)->disableOriginalConstructor()->getMock(); | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |         $phing::setErrorStream($stream); | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |         $stream->expects($this->once()) | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |             ->method('write'); | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |         $phing::printUsage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     public function testCallStartupShutdown() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         Phing::startup(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         self::assertTrue(Phing::getTimer()->isRunning()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         Phing::shutdown(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         self::assertFalse(Phing::getTimer()->isRunning()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     public function testCurrentProject() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $project = new Project(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $currProj = Phing::getCurrentProject(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $this->assertNotSame($project, $currProj); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         Phing::setCurrentProject($project); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         $this->assertSame($project, Phing::getCurrentProject()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         Phing::unsetCurrentProject(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $this->assertNull(Phing::getCurrentProject()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      * Get fixtures classpath | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * @return string Classpath | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     protected static function getClassPath() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         return __DIR__ . '/../etc/importclasses'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 133 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 134 |  |  |  |