!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache/2.2.22 (Debian). PHP/5.6.36 

uname -a: Linux h05.hvosting.ua 4.9.110-amd64 #3 SMP Sun Nov 4 16:27:09 UTC 2018 x86_64 

uid=1389(h33678) gid=1099(h33678) groups=1099(h33678),502(mgrsecure) 

Safe-mode: OFF (not secure)

/home/h33678/data/www/it-man.ztu.edu.ua/src/vendor/monolog/monolog/tests/Monolog/Handler/   drwxr-xr-x
Free 116.59 GB of 200.55 GB (58.14%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     RotatingFileHandlerTest.php (7.57 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php

/*
 * This file is part of the Monolog package.
 *
 * (c) Jordi Boggiano <j.boggiano@seld.be>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Monolog\Handler;

use 
Monolog\TestCase;
use 
PHPUnit_Framework_Error_Deprecated;

/**
 * @covers Monolog\Handler\RotatingFileHandler
 */
class RotatingFileHandlerTest extends TestCase
{
    
/**
     * This var should be private but then the anonymous function
     * in the `setUp` method won't be able to set it. `$this` cant't
     * be used in the anonymous function in `setUp` because PHP 5.3
     * does not support it.
     */
    
public $lastError;

    public function 
setUp()
    {
        
$dir __DIR__.'/Fixtures';
        
chmod($dir0777);
        if (!
is_writable($dir)) {
            
$this->markTestSkipped($dir.' must be writable to test the RotatingFileHandler.');
        }
        
$this->lastError null;
        
$self $this;
        
// workaround with &$self used for PHP 5.3
        
set_error_handler(function($code$message) use (&$self) {
            
$self->lastError = array(
                
'code' => $code,
                
'message' => $message,
            );
        });
    }

    private function 
assertErrorWasTriggered($code$message)
    {
        if (empty(
$this->lastError)) {
            
$this->fail(
                
sprintf(
                    
'Failed asserting that error with code `%d` and message `%s` was triggered',
                    
$code,
                    
$message
                
)
            );
        }
        
$this->assertEquals($code$this->lastError['code'], sprintf('Expected an error with code %d to be triggered, got `%s` instead'$code$this->lastError['code']));
        
$this->assertEquals($message$this->lastError['message'], sprintf('Expected an error with message `%d` to be triggered, got `%s` instead'$message$this->lastError['message']));
    }

    public function 
testRotationCreatesNewFile()
    {
        
touch(__DIR__.'/Fixtures/foo-'.date('Y-m-d'time() - 86400).'.rot');

        
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot');
        
$handler->setFormatter($this->getIdentityFormatter());
        
$handler->handle($this->getRecord());

        
$log __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot';
        
$this->assertTrue(file_exists($log));
        
$this->assertEquals('test'file_get_contents($log));
    }

    
/**
     * @dataProvider rotationTests
     */
    
public function testRotation($createFile$dateFormat$timeCallback)
    {
        
touch($old1 __DIR__.'/Fixtures/foo-'.date($dateFormat$timeCallback(-1)).'.rot');
        
touch($old2 __DIR__.'/Fixtures/foo-'.date($dateFormat$timeCallback(-2)).'.rot');
        
touch($old3 __DIR__.'/Fixtures/foo-'.date($dateFormat$timeCallback(-3)).'.rot');
        
touch($old4 __DIR__.'/Fixtures/foo-'.date($dateFormat$timeCallback(-4)).'.rot');

        
$log __DIR__.'/Fixtures/foo-'.date($dateFormat).'.rot';

        if (
$createFile) {
            
touch($log);
        }

        
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot'2);
        
$handler->setFormatter($this->getIdentityFormatter());
        
$handler->setFilenameFormat('{filename}-{date}'$dateFormat);
        
$handler->handle($this->getRecord());

        
$handler->close();

        
$this->assertTrue(file_exists($log));
        
$this->assertTrue(file_exists($old1));
        
$this->assertEquals($createFilefile_exists($old2));
        
$this->assertEquals($createFilefile_exists($old3));
        
$this->assertEquals($createFilefile_exists($old4));
        
$this->assertEquals('test'file_get_contents($log));
    }

    public function 
rotationTests()
    {
        
$now time();
        
$dayCallback = function($ago) use ($now) {
            return 
$now 86400 $ago;
        };
        
$monthCallback = function($ago) {
            return 
gmmktime(000date('n') + $agodate('d'), date('Y'));
        };
        
$yearCallback = function($ago) {
            return 
gmmktime(000date('n'), date('d'), date('Y') + $ago);
        };

        return array(
            
'Rotation is triggered when the file of the current day is not present'
                
=> array(trueRotatingFileHandler::FILE_PER_DAY$dayCallback),
            
'Rotation is not triggered when the file of the current day is already present'
                
=> array(falseRotatingFileHandler::FILE_PER_DAY$dayCallback),

            
'Rotation is triggered when the file of the current month is not present'
                
=> array(trueRotatingFileHandler::FILE_PER_MONTH$monthCallback),
            
'Rotation is not triggered when the file of the current month is already present'
                
=> array(falseRotatingFileHandler::FILE_PER_MONTH$monthCallback),

            
'Rotation is triggered when the file of the current year is not present'
                
=> array(trueRotatingFileHandler::FILE_PER_YEAR$yearCallback),
            
'Rotation is not triggered when the file of the current year is already present'
                
=> array(falseRotatingFileHandler::FILE_PER_YEAR$yearCallback),
        );
    }

    
/**
     * @dataProvider dateFormatProvider
     */
    
public function testAllowOnlyFixedDefinedDateFormats($dateFormat$valid)
    {
        
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot'2);
        
$handler->setFilenameFormat('{filename}-{date}'$dateFormat);
        if (!
$valid) {
            
$this->assertErrorWasTriggered(
                
E_USER_DEPRECATED,
                
'Invalid date format - format should be one of '.
                
'RotatingFileHandler::FILE_PER_DAY, RotatingFileHandler::FILE_PER_MONTH '.
                
'or RotatingFileHandler::FILE_PER_YEAR.'
            
);
        }
    }

    public function 
dateFormatProvider()
    {
        return array(
            array(
RotatingFileHandler::FILE_PER_DAYtrue),
            array(
RotatingFileHandler::FILE_PER_MONTHtrue),
            array(
RotatingFileHandler::FILE_PER_YEARtrue),
            array(
'm-d-Y'false),
            array(
'Y-m-d-h-i'false)
        );
    }

    
/**
     * @dataProvider filenameFormatProvider
     */
    
public function testDisallowFilenameFormatsWithoutDate($filenameFormat$valid)
    {
        
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot'2);
        
$handler->setFilenameFormat($filenameFormatRotatingFileHandler::FILE_PER_DAY);
        if (!
$valid) {
            
$this->assertErrorWasTriggered(
                
E_USER_DEPRECATED,
                
'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.'
            
);
        }
    }

    public function 
filenameFormatProvider()
    {
        return array(
            array(
'{filename}'false),
            array(
'{filename}-{date}'true),
            array(
'{date}'true),
            array(
'foobar-{date}'true),
            array(
'foo-{date}-bar'true),
            array(
'{date}-foobar'true),
            array(
'foobar'false),
        );
    }

    public function 
testReuseCurrentFile()
    {
        
$log __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot';
        
file_put_contents($log"foo");
        
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot');
        
$handler->setFormatter($this->getIdentityFormatter());
        
$handler->handle($this->getRecord());
        
$this->assertEquals('footest'file_get_contents($log));
    }

    public function 
tearDown()
    {
        foreach (
glob(__DIR__.'/Fixtures/*.rot') as $file) {
            
unlink($file);
        }
        
restore_error_handler();
    }
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ ok ]

:: Make Dir ::
 
[ ok ]
:: Make File ::
 
[ ok ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by PinoyWH1Z | C99Shell Github | Generation time: 0.0392 ]--