From ab4dc5f39661a93af7a2aa408916f62d9492b49a Mon Sep 17 00:00:00 2001 From: Adam Malone Date: Sat, 4 Apr 2020 11:14:35 +1100 Subject: [PATCH] Adds a test for a missing VERSION file. --- src/Cli/AcquiaCli.php | 2 +- tests/AcquiaCliApplicationTest.php | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Cli/AcquiaCli.php b/src/Cli/AcquiaCli.php index 0c0bc99..1c7555c 100644 --- a/src/Cli/AcquiaCli.php +++ b/src/Cli/AcquiaCli.php @@ -43,7 +43,7 @@ public function __construct( InputInterface $input = null, OutputInterface $output = null ) { - if ($file = file_get_contents(dirname(dirname(__DIR__)) . '/VERSION')) { + if ($file = @file_get_contents(dirname(dirname(__DIR__)) . '/VERSION')) { $version = trim($file); } else { throw new \Exception('No VERSION file'); diff --git a/tests/AcquiaCliApplicationTest.php b/tests/AcquiaCliApplicationTest.php index 48d0afb..ef5de13 100644 --- a/tests/AcquiaCliApplicationTest.php +++ b/tests/AcquiaCliApplicationTest.php @@ -45,11 +45,29 @@ public function testConfig() public function testVersion() { - $command = ['--version']; + $versionFile = sprintf('%s/VERSION', $this->root); + $version = file_get_contents($versionFile); + $command = ['--version']; $actualValue = $this->execute($command); - $this->assertContains('AcquiaCli 2', $actualValue); + $this->assertEquals(sprintf('AcquiaCli %s', $version), $actualValue); + } + + public function testMissingVersion() + { + $versionFile = sprintf('%s/VERSION', $this->root); + $versionFileBak = sprintf('%s.bak', $versionFile); + $fileMoved = rename($versionFile, $versionFileBak); + + try { + $command = ['--version']; + $this->execute($command); + } catch (\Exception $e) { + $this->assertEquals('Exception', get_class($e)); + $this->assertEquals('No VERSION file', $e->getMessage()); + } + rename($versionFileBak, $versionFile); } public function testLock()