public function KernelTest::testStripComments

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/KernelTest.php, line 265

Class

KernelTest

Namespace

Symfony\Component\HttpKernel\Tests

Code

public function testStripComments() {
  if (!function_exists('token_get_all')) {
    $this
      ->markTestSkipped('The function token_get_all() is not available.');
    return;
  }
  $source = <<<'EOF'
<?php

$string = 'string should not be   modified';


$heredoc = <<<HD


Heredoc should not be   modified


HD;

$nowdoc = <<<'ND'


Nowdoc should not be   modified


ND;

/**
 * some class comments to strip
 */
class TestClass
{
    /**
     * some method comments to strip
     */
    public function doStuff()
    {
        // inline comment
    }
}
EOF;
  $expected = <<<'EOF'
<?php
$string = 'string should not be   modified';
$heredoc =
<<<HD


Heredoc should not be   modified


HD;
$nowdoc =
<<<'ND'


Nowdoc should not be   modified


ND;
class TestClass
{
    public function doStuff()
    {
            }
}
EOF;
  $output = Kernel::stripComments($source);

  // Heredocs are preserved, making the output mixing unix and windows line
  // endings, switching to "\n" everywhere on windows to avoid failure.
  if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
    $expected = str_replace("\r\n", "\n", $expected);
    $output = str_replace("\r\n", "\n", $output);
  }
  $this
    ->assertEquals($expected, $output);
}