From dea1eeabd6c188b4f2effbebe21d6de1f6538ea6 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Wed, 3 Jul 2019 17:03:30 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92=E5=89=8D?= =?UTF-8?q?=E7=BD=AE=E3=81=8D=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: hina --- app/Console/Commands/UpdateFixture.php | 68 +++++++++++++------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/app/Console/Commands/UpdateFixture.php b/app/Console/Commands/UpdateFixture.php index d713c0e..21e3722 100644 --- a/app/Console/Commands/UpdateFixture.php +++ b/app/Console/Commands/UpdateFixture.php @@ -40,43 +40,43 @@ class UpdateFixture extends Command $resolver_base_path = __DIR__ . '/../../../tests/Unit/MetadataResolver/'; $test_file_path = $resolver_base_path . $this->argument('resolver') . 'ResolverTest.php'; - if (file_exists($test_file_path)) { - $this->info($this->argument('resolver') . 'ResolverTest.php is found.'); + if (!file_exists($test_file_path)) { + throw new \RuntimeException($this->argument('resolver') . 'ResolverTest.php is not found.'); + } - $test_file = file_get_contents($test_file_path); - $test_file_without_comment = ''; - // コメントを削除する - $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; - } + $this->info($this->argument('resolver') . 'ResolverTest.php is found.'); + + $test_file = file_get_contents($test_file_path); + $test_file_without_comment = ''; + // コメントを削除する + $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]); - - $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!'); } }