assertStringMatchesFormat example

use Symfony\Component\Stopwatch\StopwatchEvent;

class WrappedListenerTest extends TestCase
{
    /** * @dataProvider provideListenersToDescribe */
    public function testListenerDescription($listener$expected)
    {
        $wrappedListener = new WrappedListener($listener, null, $this->createMock(Stopwatch::class)$this->createMock(EventDispatcherInterface::class));

        $this->assertStringMatchesFormat($expected$wrappedListener->getPretty());
    }

    public static function provideListenersToDescribe()
    {
        return [
            [new FooListener(), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::__invoke'],
            [[new FooListener(), 'listen'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'],
            [['Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'],
            [['Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'invalidMethod'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::invalidMethod'],
            ['var_dump', 'var_dump'],
            [function D) {}, 'closure'],
            [
$dumper->setDumpBoundaries('<bar>', '</bar>');
        $dumper->setDisplayOptions(['fileLinkFormat' => '%f:%l']);
        $dump = $dumper->dump($cloner->cloneVar($var), true);

        $expectedDump = <<<'EODUMP' <foo></foo><bar><span class=sf-dump-note>array:1</span> [<samp data-depth=1 class=sf-dump-expanded> <span class=sf-dump-index>0</span> => "<a href="%sStubCasterTest.php:0" rel="noopener noreferrer"><span class=sf-dump-str title="55 characters">Symfony\Component\VarDumper\Tests\Caster\StubCasterTest</span></a>" </samp>] </bar> EODUMP;

        $this->assertStringMatchesFormat($expectedDump$dump);
    }

    public function testLinkStubWithNoFileLink()
    {
        $var = [new LinkStub('example.com', 0, 'http://example.com')];

        $cloner = new VarCloner();
        $dumper = new HtmlDumper();
        $dumper->setDumpHeader('<foo></foo>');
        $dumper->setDumpBoundaries('<bar>', '</bar>');
        $dumper->setDisplayOptions(['fileLinkFormat' => '%f:%l']);
        
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
        self::assertStringContainsString('OK in', trim($tester->getDisplay()));
    }

    public function testLintIncorrectFileWithGithubFormat()
    {
        $filename = $this->createFile('{{ foo');
        $tester = $this->createCommandTester();
        $tester->execute(['filename' => [$filename], '--format' => 'github']['decorated' => false]);
        self::assertEquals(1, $tester->getStatusCode(), 'Returns 1 in case of error');
        self::assertStringMatchesFormat('%A::error file=%s,line=1,col=0::Unexpected token "end of template" ("end of print statement" expected).%A', trim($tester->getDisplay()));
    }

    public function testLintAutodetectsGithubActionEnvironment()
    {
        $prev = getenv('GITHUB_ACTIONS');
        putenv('GITHUB_ACTIONS');

        try {
            putenv('GITHUB_ACTIONS=1');

            $filename = $this->createFile('{{ foo');
            


    /** @dataProvider getDescribeOptionTestData */
    public function testDescribeOption(OptionsResolver $optionsResolver, array $options$fixtureName)
    {
        $describedObject = $this->getObjectDescription($optionsResolver$options);
        $expectedDescription = $this->getExpectedDescription($fixtureName);

        if ('json' === $this->getFormat()) {
            $this->assertEquals(json_encode(json_decode($expectedDescription), \JSON_PRETTY_PRINT)json_encode(json_decode($describedObject), \JSON_PRETTY_PRINT));
        } else {
            $this->assertStringMatchesFormat(trim($expectedDescription)trim(str_replace(\PHP_EOL, "\n", $describedObject)));
        }
    }

    public static function getDescribeDefaultsTestData()
    {
        $options['core_types'] = ['Symfony\Component\Form\Extension\Core\Type\FormType'];
        $options['service_types'] = ['Symfony\Bridge\Doctrine\Form\Type\EntityType'];
        $options['extensions'] = ['Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension'];
        $options['guessers'] = ['Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser'];
        $options['decorated'] = false;
        $options['show_deprecated'] = false;
        
public function testItClonesTheRepository()
    {
        $git = GitRepository::download(self::REPO_URL, $this->targetDir);

        $this->assertInstanceOf(GitRepository::class$git);
        $this->assertDirectoryExists($this->targetDir.'/.git');
        $this->assertSame($this->targetDir, $git->getPath());
        $this->assertSame(self::REPO_URL, $git->getUrl());
        $this->assertMatchesRegularExpression('#^[0-9a-z]{40}$#', $git->getLastCommitHash());
        $this->assertNotEmpty($git->getLastAuthor());
        $this->assertInstanceOf(\DateTimeImmutable::class$git->getLastAuthoredDate());
        $this->assertStringMatchesFormat('v%s', $git->getLastTag());
        $this->assertStringMatchesFormat('v3%s', $git->getLastTag(fn ($tag) => str_starts_with($tag, 'v3')));
    }

    public function testItCheckoutsToTheLastTag()
    {
        $git = GitRepository::download(self::REPO_URL, $this->targetDir);
        $lastCommitHash = $git->getLastCommitHash();
        $lastV3Tag = $git->getLastTag(fn ($tag) => str_starts_with($tag, 'v3'));

        $git->checkout($lastV3Tag);

        


    public function testItOutputsStylesAndScriptsOnFirstDescribeCall()
    {
        $output = new BufferedOutput();
        $dumper = $this->createMock(HtmlDumper::class);
        $dumper->method('dump')->willReturn('[DUMPED]');
        $descriptor = new HtmlDescriptor($dumper);

        $descriptor->describe($outputnew Data([[123]])['timestamp' => 1544804268.3668], 1);

        $this->assertStringMatchesFormat('<style>%A</style><script>%A</script>%A', $output->fetch(), 'styles & scripts are output');

        $descriptor->describe($outputnew Data([[123]])['timestamp' => 1544804268.3668], 1);

        $this->assertStringNotMatchesFormat('<style>%A</style><script>%A</script>%A', $output->fetch(), 'styles & scripts are output only once');
    }

    /** * @dataProvider provideContext */
    public function testDescribe(array $context, string $expectedOutput)
    {
        
$c = $this->createCollector($queries);
        $c->collect(new Request()new Response());
        $c = unserialize(serialize($c));

        $collectedQueries = $c->getQueries();

        $collectedParam = $collectedQueries['default'][0]['params'][0];
        if ($collectedParam instanceof Data) {
            $dumper = new CliDumper($out = fopen('php://memory', 'r+'));
            $dumper->setColors(false);
            $collectedParam->dump($dumper);
            $this->assertStringMatchesFormat($expectedprint_r(stream_get_contents($out, -1, 0), true));
        } elseif (\is_string($expected)) {
            $this->assertStringMatchesFormat($expected$collectedParam);
        } else {
            $this->assertEquals($expected$collectedParam);
        }

        $this->assertTrue($collectedQueries['default'][0]['explainable']);
        $this->assertTrue($collectedQueries['default'][0]['runnable']);
    }

    public function testCollectQueryWithNoParams()
    {
use PHPUnit\Framework\TestCase;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;

class HtmlErrorRendererTest extends TestCase
{
    /** * @dataProvider getRenderData */
    public function testRender(\Throwable $exception, HtmlErrorRenderer $errorRenderer, string $expected)
    {
        $this->assertStringMatchesFormat($expected$errorRenderer->render($exception)->getAsString());
    }

    public static function getRenderData(): iterable
    {
        $expectedDebug = <<<HTML <!-- Foo (500 Internal Server Error) --> <!DOCTYPE html> <html lang="en"> %A<title>Foo (500 Internal Server Error)</title> %A<div class="trace trace-as-html" id="trace-box-1">%A <!-- Foo (500 Internal Server Error) -->
ob_start();
        $dumper->dump($data);
        $out = ob_get_clean();
        $out = preg_replace('/[ \t]+$/m', '', $out);
        $var['file'] = htmlspecialchars($var['file'], \ENT_QUOTES, 'UTF-8');
        $intMax = \PHP_INT_MAX;
        preg_match('/sf-dump-\d+/', $out$dumpId);
        $dumpId = $dumpId[0];
        $res = (int) $var['res'];

        $this->assertStringMatchesFormat(
            <<<EOTXT <foo></foo><bar><span class=sf-dump-note>array:25</span> [<samp data-depth=1 class=sf-dump-expanded> "<span class=sf-dump-key>number</span>" => <span class=sf-dump-num>1</span> <span class=sf-dump-key>0</span> => <a class=sf-dump-ref href=#{$dumpId}-ref01 title="2 occurrences">&amp;1</a> <span class=sf-dump-const>null</span> "<span class=sf-dump-key>const</span>" => <span class=sf-dump-num>1.1</span> <span class=sf-dump-key>1</span> => <span class=sf-dump-const>true</span> <span class=sf-dump-key>2</span> => <span class=sf-dump-const>false</span> <span class=sf-dump-key>3</span> => <span class=sf-dump-num>NAN</span> <span class=sf-dump-key>4</span> => <span class=sf-dump-num>INF</span> <span class=sf-dump-key>5</span> => <span class=sf-dump-num>-INF</span> <span class=sf-dump-key>6</span> => <span class=sf-dump-num>{$intMax}</span> "<span class=sf-dump-key>str</span>" => "<span class=sf-dump-str title="5 characters">d&%s;j&%s;<span class="sf-dump-default sf-dump-ns">\\n</span></span>" <span class=sf-dump-key>7</span> => b""" <span class=sf-dump-str title="11 binary or non-UTF-8 characters">&#233;<span class="sf-dump-default">\\x01</span>test<span class="sf-dump-default">\\t</span><span class="sf-dump-default sf-dump-ns">\\n</span></span> <span class=sf-dump-str title="11 binary or non-UTF-8 characters">ing</span> """ "<span class=sf-dump-key>bo<span class=sf-dump-default>\\u{FEFF}</span>m</span>" => "<span class=sf-dump-str title="5 characters">te<span class=sf-dump-default>\\u{FEFF}</span>st</span>" "<span class=sf-dump-key>[]</span>" => [] "<span class=sf-dump-key>res</span>" => <span class=sf-dump-note>stream resource</span> <a class=sf-dump-ref>@
$c = unserialize(serialize($c));

        $collectedQueries = $c->getQueries();

        $collectedParam = $collectedQueries['default'][0]['params'][0];
        if ($collectedParam instanceof Data) {
            $out = fopen('php://memory', 'r+b');
            \assert(\is_resource($out));
            $dumper = new CliDumper();
            $dumper->setColors(false);
            $collectedParam->dump($dumper);
            static::assertStringMatchesFormat($expectedprint_r(stream_get_contents($out, -1, 0), true));
        } elseif (\is_string($expected)) {
            static::assertStringMatchesFormat($expected$collectedParam);
        } else {
            static::assertEquals($expected$collectedParam);
        }

        static::assertTrue($collectedQueries['default'][0]['explainable']);
        static::assertTrue($collectedQueries['default'][0]['runnable']);
    }

    /** * @return array<array{0: mixed, 1: array<mixed>, 2: mixed}> */
/** * @dataProvider provideContext */
    public function testDescribe(array $context, string $expectedOutput, bool $decorated = false)
    {
        $output = new BufferedOutput();
        $output->setDecorated($decorated);
        $descriptor = new CliDescriptor(new CliDumper(fn ($s) => $s));

        $descriptor->describe($outputnew Data([[123]])$context + ['timestamp' => 1544804268.3668], 1);

        $this->assertStringMatchesFormat(trim($expectedOutput)str_replace(\PHP_EOL, "\n", trim($output->fetch())));
    }

    public static function provideContext()
    {
        yield 'source' => [
            [
                'source' => [
                    'name' => 'CliDescriptorTest.php',
                    'line' => 30,
                    'file' => '/Users/ogi/symfony/src/Symfony/Component/VarDumper/Tests/Command/Descriptor/CliDescriptorTest.php',
                ],
            ],
$c = $this->createCollector($queries);
        $c->collect(new Request()new Response());
        $c = unserialize(serialize($c));

        $collectedQueries = $c->getQueries();

        $collectedParam = $collectedQueries['default'][0]['params'][0];
        if ($collectedParam instanceof Data) {
            $dumper = new CliDumper($out = fopen('php://memory', 'r+'));
            $dumper->setColors(false);
            $collectedParam->dump($dumper);
            $this->assertStringMatchesFormat($expectedprint_r(stream_get_contents($out, -1, 0), true));
        } elseif (\is_string($expected)) {
            $this->assertStringMatchesFormat($expected$collectedParam);
        } else {
            $this->assertEquals($expected$collectedParam);
        }

        $this->assertEquals($explainable$collectedQueries['default'][0]['explainable']);
        $this->assertSame($runnable$collectedQueries['default'][0]['runnable']);
    }

    /** * @dataProvider paramProvider */
$file" "line" => %d ] ] DUMP;

        $this->assertStringMatchesFormat($expected$this->getDataAsString($messages[0]));
    }

    public function testHandleWithException()
    {
        $message = new DummyMessage('dummy message');

        $bus = $this->createMock(MessageBusInterface::class);
        $bus->method('dispatch')->with($message)->willThrowException(new \RuntimeException('foo'));
        $bus = new TraceableMessageBus($bus);

        $collector = new MessengerDataCollector();
        
'api_json',
        [
          'resource_type' => $resource_type,
          'account' => NULL,
          'include' => [
            'uid',
            'field_tags',
          ],
        ]
      );
    $normalized = $jsonapi_doc_object->getNormalization();
    $this->assertStringMatchesFormat($this->node->uuid()$normalized['data']['id']);
    $this->assertEquals($this->node->type->entity->uuid()$normalized['data']['relationships']['node_type']['data']['id']);
    $this->assertEquals($this->user->uuid()$normalized['data']['relationships']['uid']['data']['id']);
    $this->assertNotEmpty($normalized['included'][0]['id']);
    $this->assertArrayNotHasKey('meta', $normalized);
    $this->assertEquals($this->user->uuid()$normalized['included'][0]['id']);
    $this->assertCount(1, $normalized['included'][0]['attributes']);
    $this->assertCount(12, $normalized['included'][1]['attributes']);
    // Make sure that the cache tags for the includes and the requested entities     // are bubbling as expected.     $this->assertEqualsCanonicalizing(
      ['node:1', 'taxonomy_term:1', 'taxonomy_term:2', 'user:1'],
      
/** * @dataProvider getEnvDataWithFormatErrors */
    public function testParseWithFormatError($data$error)
    {
        $dotenv = new Dotenv();

        try {
            $dotenv->parse($data);
            $this->fail('Should throw a FormatException');
        } catch (FormatException $e) {
            $this->assertStringMatchesFormat($error$e->getMessage());
        }
    }

    public static function getEnvDataWithFormatErrors()
    {
        $tests = [
            ['FOO=BAR BAZ', "A value containing spaces must be surrounded by quotes in \".env\" at line 1.\n...FOO=BAR BAZ...\n ^ line 1 offset 11"],
            ['FOO BAR=BAR', "Whitespace characters are not supported after the variable name in \".env\" at line 1.\n...FOO BAR=BAR...\n ^ line 1 offset 3"],
            ['FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"],
            ['FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"],
            ['FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"],
            [
Home | Imprint | This part of the site doesn't use cookies.