コメントを検索対象に含まれないようにする

This commit is contained in:
eai04191 2019-07-03 16:29:38 +09:00
parent 23f9d1a220
commit d7ffcfcf7b

View File

@ -44,8 +44,21 @@ class UpdateFixture extends Command
$this->info($this->argument('resolver') . 'ResolverTest.php is found.'); $this->info($this->argument('resolver') . 'ResolverTest.php is found.');
$test_file = file_get_contents($test_file_path); $test_file = file_get_contents($test_file_path);
preg_match_all('~file_get_contents\(__DIR__ . \'/(.+)\'\);~', $test_file, $fixtures); $test_file_without_comment = '';
preg_match_all('~\$this->assertSame\(\'(.+)\', \(string\) \$this->handler->getLastRequest\(\)->getUri\(\)\);~', $test_file, $urls); // コメントを削除する
$tokens = token_get_all($test_file);
foreach ($tokens as $token) {
if (is_string($token)) {
$test_file_without_comment .= $token;
} else {
list($id, $text) = $token;
if (token_name($id) != 'T_COMMENT') {
$test_file_without_comment .= $text;
}
}
}
preg_match_all('~file_get_contents\(__DIR__ . \'/(.+)\'\);~', $test_file_without_comment, $fixtures);
preg_match_all('~\$this->assertSame\(\'(.+)\', \(string\) \$this->handler->getLastRequest\(\)->getUri\(\)\);~m', $test_file_without_comment, $urls);
$update_list = array_combine($fixtures[1], $urls[1]); $update_list = array_combine($fixtures[1], $urls[1]);
$progress = $this->output->createProgressBar(count($update_list)); $progress = $this->output->createProgressBar(count($update_list));