Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /** * This file is part of the Phalcon Framework. * * (c) Phalcon Team <team@pha..

Decoded Output download

<?php

/**
 * This file is part of the Phalcon Framework.
 *
 * (c) Phalcon Team <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE.txt
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Phalcon\Tests\Unit\Logger\Logger;

use Phalcon\Logger\Adapter\Stream;
use Phalcon\Logger\Exception;
use Phalcon\Logger\Logger;
use UnitTester;

class RemoveAdapterCest
{
    /**
     * Tests Phalcon\Logger :: removeAdapter()
     *
     * @param UnitTester $I
     *
     * @author Phalcon Team <[email protected]>
     * @since  2020-09-09
     */
    public function loggerRemoveAdapter(UnitTester $I)
    {
        $I->wantToTest('Logger - removeAdapter()');

        $fileName1  = $I->getNewFileName('log', 'log');
        $fileName2  = $I->getNewFileName('log', 'log');
        $outputPath = logsDir();
        $adapter1   = new Stream($outputPath . $fileName1);
        $adapter2   = new Stream($outputPath . $fileName2);

        $logger = new Logger(
            'my-logger',
            [
                'one' => $adapter1,
                'two' => $adapter2,
            ]
        );

        $expected = 2;
        $adapters = $logger->getAdapters();
        $I->assertCount($expected, $adapters);

        $logger->removeAdapter('one');
        $expected = 1;
        $adapters = $logger->getAdapters();
        $I->assertCount($expected, $adapters);

        $I->safeDeleteFile($outputPath . $fileName1);
        $I->safeDeleteFile($outputPath . $fileName2);
    }

    /**
     * Tests Phalcon\Logger :: removeAdapter() - unknown
     *
     * @param UnitTester $I
     *
     * @author Phalcon Team <[email protected]>
     * @since  2020-09-09
     */
    public function loggerRemoveAdapterUnknown(UnitTester $I)
    {
        $I->wantToTest('Logger - removeAdapter() - unknown');

        $fileName1  = $I->getNewFileName('log', 'log');
        $outputPath = logsDir();

        try {
            $adapter1 = new Stream($outputPath . $fileName1);

            $logger = new Logger(
                'my-logger',
                [
                    'one' => $adapter1,
                ]
            );

            $expected = 1;
            $adapters = $logger->getAdapters();
            $I->assertCount($expected, $adapters);

            $logger->removeAdapter('unknown');
        } catch (Exception $ex) {
            $expected = 'Adapter does not exist for this logger';
            $actual   = $ex->getMessage();
            $I->assertSame($expected, $actual);
        }

        $I->safeDeleteFile($outputPath . $fileName1);
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

/**
 * This file is part of the Phalcon Framework.
 *
 * (c) Phalcon Team <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE.txt
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Phalcon\Tests\Unit\Logger\Logger;

use Phalcon\Logger\Adapter\Stream;
use Phalcon\Logger\Exception;
use Phalcon\Logger\Logger;
use UnitTester;

class RemoveAdapterCest
{
    /**
     * Tests Phalcon\Logger :: removeAdapter()
     *
     * @param UnitTester $I
     *
     * @author Phalcon Team <[email protected]>
     * @since  2020-09-09
     */
    public function loggerRemoveAdapter(UnitTester $I)
    {
        $I->wantToTest('Logger - removeAdapter()');

        $fileName1  = $I->getNewFileName('log', 'log');
        $fileName2  = $I->getNewFileName('log', 'log');
        $outputPath = logsDir();
        $adapter1   = new Stream($outputPath . $fileName1);
        $adapter2   = new Stream($outputPath . $fileName2);

        $logger = new Logger(
            'my-logger',
            [
                'one' => $adapter1,
                'two' => $adapter2,
            ]
        );

        $expected = 2;
        $adapters = $logger->getAdapters();
        $I->assertCount($expected, $adapters);

        $logger->removeAdapter('one');
        $expected = 1;
        $adapters = $logger->getAdapters();
        $I->assertCount($expected, $adapters);

        $I->safeDeleteFile($outputPath . $fileName1);
        $I->safeDeleteFile($outputPath . $fileName2);
    }

    /**
     * Tests Phalcon\Logger :: removeAdapter() - unknown
     *
     * @param UnitTester $I
     *
     * @author Phalcon Team <[email protected]>
     * @since  2020-09-09
     */
    public function loggerRemoveAdapterUnknown(UnitTester $I)
    {
        $I->wantToTest('Logger - removeAdapter() - unknown');

        $fileName1  = $I->getNewFileName('log', 'log');
        $outputPath = logsDir();

        try {
            $adapter1 = new Stream($outputPath . $fileName1);

            $logger = new Logger(
                'my-logger',
                [
                    'one' => $adapter1,
                ]
            );

            $expected = 1;
            $adapters = $logger->getAdapters();
            $I->assertCount($expected, $adapters);

            $logger->removeAdapter('unknown');
        } catch (Exception $ex) {
            $expected = 'Adapter does not exist for this logger';
            $actual   = $ex->getMessage();
            $I->assertSame($expected, $actual);
        }

        $I->safeDeleteFile($outputPath . $fileName1);
    }
}

Function Calls

None

Variables

None

Stats

MD5 2cc2d7a07096df6e1686dd5c588548bc
Eval Count 0
Decode Time 106 ms