| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * {CLASS SUMMARY} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Date: 10/6/18 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Time: 2:34 PM | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @author Michael Munger <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | namespace HPHIO\Util; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Monolog\Logger; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use org\bovigo\vfs\vfsStream; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use League\Container\Container; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Monolog\Handler\StreamHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | class loggingConfigReaderTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     protected $container; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     protected $applicationRoot; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     public function setUp() { | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         $this->container = new Container; | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         $this->container->add(Logger::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $this->container->add(LoggingConfigurator::class)->addArgument($this->container); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         $this->container->add(LoggingConfig::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         $this->applicationRoot = vfsStream::setup("appRoot"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function testReady() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->assertContains("vfs", stream_get_wrappers()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     public function testFindService() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->assertFalse($this->applicationRoot->hasChild('config')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $LogConfigurator = $this->container->get(LoggingConfigurator::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->assertInstanceOf(LoggingConfigurator::class, $LogConfigurator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $LogConfigurator->setAppRoot(vfsStream::url("appRoot")); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $result = $LogConfigurator->setConfigDir("config"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->assertTrue($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->assertTrue($this->applicationRoot->hasChild('config')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     public function testServiceLoggingConfig() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $LogConfigurator = $this->container->get(LoggingConfigurator::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $LogConfigurator->setAppRoot(vfsStream::url("appRoot")); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $result = $LogConfigurator->setConfigDir("config"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $this->applicationRoot = vfsStream::copyFromFileSystem(__DIR__ . '/fixtures/appRoot', $this->applicationRoot); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->assertTrue($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $this->assertTrue($LogConfigurator->loadLoggingConf()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $obj = $LogConfigurator->getServiceLogConfig("auth"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $this->assertInstanceOf(LoggingConfig::class, $obj); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $this->assertNotFalse($obj); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->assertSame("auth", $obj->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $this->assertSame(true, $obj->enabled); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->assertSame("auth.log", $obj->filename); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $this->assertSame("vfs://appRoot/log/", $obj->path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $obj = $LogConfigurator->getServiceLogConfig("doesnotexist"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $this->assertFalse($obj); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     public function testGetLogger() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $LogConfigurator = $this->container->get(LoggingConfigurator::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $LogConfigurator->setAppRoot(vfsStream::url("appRoot")); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $LogConfigurator->setConfigDir("config"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $this->applicationRoot = vfsStream::copyFromFileSystem(__DIR__ . '/fixtures/appRoot', $this->applicationRoot); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $LogConfigurator->loadLoggingConf(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $config = $LogConfigurator->getServiceLogConfig("auth"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $logger = $LogConfigurator->getLogger($config); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $logger->info("Test"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $this->assertFileExists(vfsStream::url("appRoot/log/auth.log")); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $this->assertGreaterThan(0, stripos(file_get_contents(vfsStream::url("appRoot/log/auth.log")), "Test")); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 98 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 99 |  |  | } |