エラーを前置きにした

Co-authored-by: hina <hina@hinaloe.net>
This commit is contained in:
eai04191 2019-07-03 17:03:30 +09:00
parent 0284827fcf
commit dea1eeabd6

View File

@ -40,43 +40,43 @@ class UpdateFixture extends Command
$resolver_base_path = __DIR__ . '/../../../tests/Unit/MetadataResolver/'; $resolver_base_path = __DIR__ . '/../../../tests/Unit/MetadataResolver/';
$test_file_path = $resolver_base_path . $this->argument('resolver') . 'ResolverTest.php'; $test_file_path = $resolver_base_path . $this->argument('resolver') . 'ResolverTest.php';
if (file_exists($test_file_path)) { if (!file_exists($test_file_path)) {
$this->info($this->argument('resolver') . 'ResolverTest.php is found.'); throw new \RuntimeException($this->argument('resolver') . 'ResolverTest.php is not found.');
}
$test_file = file_get_contents($test_file_path); $this->info($this->argument('resolver') . 'ResolverTest.php is found.');
$test_file_without_comment = '';
// コメントを削除する $test_file = file_get_contents($test_file_path);
$tokens = token_get_all($test_file); $test_file_without_comment = '';
foreach ($tokens as $token) { // コメントを削除する
if (is_string($token)) { $tokens = token_get_all($test_file);
$test_file_without_comment .= $token; foreach ($tokens as $token) {
} else { if (is_string($token)) {
list($id, $text) = $token; $test_file_without_comment .= $token;
if (token_name($id) !== 'T_COMMENT') { } else {
$test_file_without_comment .= $text; 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]);
$progress = $this->output->createProgressBar(count($update_list));
$progress->setFormat('Updating %path% from %url%' . PHP_EOL . '%current%/%max% [%bar%] %percent:3s%%');
foreach ($update_list as $path => $url) {
sleep(1);
$progress->setMessage($path, 'path');
$progress->setMessage($url, 'url');
file_put_contents($resolver_base_path . $path, file_get_contents($url));
$progress->advance();
}
$progress->finish();
$this->output->newLine();
$this->info('Update Complete!');
} else {
$this->error($this->argument('resolver') . 'ResolverTest.php is not found.');
} }
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]);
$progress = $this->output->createProgressBar(count($update_list));
$progress->setFormat('Updating %path% from %url%' . PHP_EOL . '%current%/%max% [%bar%] %percent:3s%%');
foreach ($update_list as $path => $url) {
sleep(1);
$progress->setMessage($path, 'path');
$progress->setMessage($url, 'url');
file_put_contents($resolver_base_path . $path, file_get_contents($url));
$progress->advance();
}
$progress->finish();
$this->output->newLine();
$this->info('Update Complete!');
} }
} }