From d6d1697a01ebc62aabcbdd55ae0853496fe5530f Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 23 Mar 2024 13:29:01 +0200 Subject: [PATCH] Use `::class` in test suite --- src/SVNBuddy/Updater/UpdateManager.php | 4 +- .../Config/ArrayConfigSettingTest.php | 3 +- .../Config/ChoiceConfigSettingTest.php | 3 +- .../Config/IntegerConfigSettingTest.php | 3 +- .../Config/PathsConfigSettingTest.php | 3 +- .../Config/RegExpsConfigSettingTest.php | 3 +- .../Config/StringConfigSettingTest.php | 3 +- tests/SVNBuddy/ContainerTest.php | 66 ++++++++++++------- .../MergeSourceDetectorAggregatorTest.php | 9 +-- tests/SVNBuddy/Process/ProcessFactoryTest.php | 6 +- .../Connector/CommandFactoryTest.php | 15 +++-- .../Repository/Connector/CommandTest.php | 17 +++-- .../Repository/Connector/ConnectorTest.php | 19 ++++-- .../RevisionLog/Plugin/BugsPluginTest.php | 6 +- .../RevisionLog/RevisionLogFactoryTest.php | 15 +++-- .../RevisionLog/RevisionLogTest.php | 22 ++++--- 16 files changed, 126 insertions(+), 71 deletions(-) diff --git a/src/SVNBuddy/Updater/UpdateManager.php b/src/SVNBuddy/Updater/UpdateManager.php index dcbdd44..744fb2e 100644 --- a/src/SVNBuddy/Updater/UpdateManager.php +++ b/src/SVNBuddy/Updater/UpdateManager.php @@ -77,9 +77,9 @@ public function __construct( */ public function setUpdateChannel($update_channel) { - $stability_constant = 'ConsoleHelpers\\SVNBuddy\\Updater\\Stability::' . strtoupper($update_channel); + $valid_channels = array(Stability::STABLE, Stability::SNAPSHOT, Stability::PREVIEW); - if ( !defined($stability_constant) ) { + if ( !in_array($update_channel, $valid_channels) ) { throw new \InvalidArgumentException('Update channel "' . $update_channel . '" not found.'); } diff --git a/tests/SVNBuddy/Config/ArrayConfigSettingTest.php b/tests/SVNBuddy/Config/ArrayConfigSettingTest.php index 05a223f..d04642e 100644 --- a/tests/SVNBuddy/Config/ArrayConfigSettingTest.php +++ b/tests/SVNBuddy/Config/ArrayConfigSettingTest.php @@ -12,6 +12,7 @@ use ConsoleHelpers\SVNBuddy\Config\AbstractConfigSetting; +use ConsoleHelpers\SVNBuddy\Config\ArrayConfigSetting; class ArrayConfigSettingTest extends AbstractConfigSettingTest { @@ -23,7 +24,7 @@ class ArrayConfigSettingTest extends AbstractConfigSettingTest protected function setupTest() { if ( !isset($this->className) ) { - $this->className = 'ConsoleHelpers\\SVNBuddy\\Config\\ArrayConfigSetting'; + $this->className = ArrayConfigSetting::class; } if ( !isset($this->defaultValue) ) { diff --git a/tests/SVNBuddy/Config/ChoiceConfigSettingTest.php b/tests/SVNBuddy/Config/ChoiceConfigSettingTest.php index 2dc59ca..864a75d 100644 --- a/tests/SVNBuddy/Config/ChoiceConfigSettingTest.php +++ b/tests/SVNBuddy/Config/ChoiceConfigSettingTest.php @@ -12,6 +12,7 @@ use ConsoleHelpers\SVNBuddy\Config\AbstractConfigSetting; +use ConsoleHelpers\SVNBuddy\Config\ChoiceConfigSetting; class ChoiceConfigSettingTest extends AbstractConfigSettingTest { @@ -23,7 +24,7 @@ class ChoiceConfigSettingTest extends AbstractConfigSettingTest protected function setupTest() { if ( !isset($this->className) ) { - $this->className = 'ConsoleHelpers\\SVNBuddy\\Config\\ChoiceConfigSetting'; + $this->className = ChoiceConfigSetting::class; } if ( !isset($this->defaultValue) ) { diff --git a/tests/SVNBuddy/Config/IntegerConfigSettingTest.php b/tests/SVNBuddy/Config/IntegerConfigSettingTest.php index be809fa..5f375da 100644 --- a/tests/SVNBuddy/Config/IntegerConfigSettingTest.php +++ b/tests/SVNBuddy/Config/IntegerConfigSettingTest.php @@ -13,6 +13,7 @@ use ConsoleHelpers\SVNBuddy\Config\AbstractConfigSetting; use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use ConsoleHelpers\SVNBuddy\Config\IntegerConfigSetting; class IntegerConfigSettingTest extends AbstractConfigSettingTest { @@ -26,7 +27,7 @@ class IntegerConfigSettingTest extends AbstractConfigSettingTest protected function setupTest() { if ( !isset($this->className) ) { - $this->className = 'ConsoleHelpers\\SVNBuddy\\Config\\IntegerConfigSetting'; + $this->className = IntegerConfigSetting::class; } if ( !isset($this->defaultValue) ) { diff --git a/tests/SVNBuddy/Config/PathsConfigSettingTest.php b/tests/SVNBuddy/Config/PathsConfigSettingTest.php index 1624db4..84ae08d 100644 --- a/tests/SVNBuddy/Config/PathsConfigSettingTest.php +++ b/tests/SVNBuddy/Config/PathsConfigSettingTest.php @@ -13,6 +13,7 @@ use ConsoleHelpers\SVNBuddy\Config\AbstractConfigSetting; use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use ConsoleHelpers\SVNBuddy\Config\PathsConfigSetting; class PathsConfigSettingTest extends ArrayConfigSettingTest { @@ -32,7 +33,7 @@ class PathsConfigSettingTest extends ArrayConfigSettingTest */ protected function setupTest() { - $this->className = 'ConsoleHelpers\\SVNBuddy\\Config\\PathsConfigSetting'; + $this->className = PathsConfigSetting::class; $this->defaultValue = array('default'); parent::setupTest(); diff --git a/tests/SVNBuddy/Config/RegExpsConfigSettingTest.php b/tests/SVNBuddy/Config/RegExpsConfigSettingTest.php index 6c43b57..862c695 100644 --- a/tests/SVNBuddy/Config/RegExpsConfigSettingTest.php +++ b/tests/SVNBuddy/Config/RegExpsConfigSettingTest.php @@ -13,6 +13,7 @@ use ConsoleHelpers\SVNBuddy\Config\AbstractConfigSetting; use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use ConsoleHelpers\SVNBuddy\Config\RegExpsConfigSetting; class RegExpsConfigSettingTest extends ArrayConfigSettingTest { @@ -25,7 +26,7 @@ class RegExpsConfigSettingTest extends ArrayConfigSettingTest */ protected function setupTest() { - $this->className = 'ConsoleHelpers\\SVNBuddy\\Config\\RegExpsConfigSetting'; + $this->className = RegExpsConfigSetting::class; $this->defaultValue = array('default'); parent::setupTest(); diff --git a/tests/SVNBuddy/Config/StringConfigSettingTest.php b/tests/SVNBuddy/Config/StringConfigSettingTest.php index ba5a4f8..f1d31ba 100644 --- a/tests/SVNBuddy/Config/StringConfigSettingTest.php +++ b/tests/SVNBuddy/Config/StringConfigSettingTest.php @@ -12,6 +12,7 @@ use ConsoleHelpers\SVNBuddy\Config\AbstractConfigSetting; +use ConsoleHelpers\SVNBuddy\Config\StringConfigSetting; class StringConfigSettingTest extends AbstractConfigSettingTest { @@ -23,7 +24,7 @@ class StringConfigSettingTest extends AbstractConfigSettingTest protected function setupTest() { if ( !isset($this->className) ) { - $this->className = 'ConsoleHelpers\\SVNBuddy\\Config\\StringConfigSetting'; + $this->className = StringConfigSetting::class; } if ( !isset($this->defaultValue) ) { diff --git a/tests/SVNBuddy/ContainerTest.php b/tests/SVNBuddy/ContainerTest.php index 689d7c9..d111724 100644 --- a/tests/SVNBuddy/ContainerTest.php +++ b/tests/SVNBuddy/ContainerTest.php @@ -13,6 +13,28 @@ use ConsoleHelpers\SVNBuddy\Container; use Tests\ConsoleHelpers\ConsoleKit\ContainerTest as BaseContainerTest; +use ConsoleHelpers\SVNBuddy\Process\ProcessFactory; +use ConsoleHelpers\SVNBuddy\MergeSourceDetector\MergeSourceDetectorAggregator; +use ConsoleHelpers\SVNBuddy\Repository\Connector\UrlResolver; +use ConsoleHelpers\SVNBuddy\Cache\CacheManager; +use ConsoleHelpers\SVNBuddy\Database\StatementProfiler; +use ConsoleHelpers\DatabaseMigration\MigrationManager; +use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLogFactory; +use ConsoleHelpers\SVNBuddy\Repository\Parser\LogMessageParserFactory; +use ConsoleHelpers\SVNBuddy\Repository\Parser\RevisionListParser; +use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionPrinter; +use ConsoleHelpers\SVNBuddy\Repository\Connector\CommandFactory; +use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; +use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\CommitMessageBuilder; +use ConsoleHelpers\SVNBuddy\Repository\WorkingCopyResolver; +use ConsoleHelpers\SVNBuddy\Repository\WorkingCopyConflictTracker; +use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\MergeTemplateFactory; +use ConsoleHelpers\SVNBuddy\Config\CommandConfig; +use ConsoleHelpers\SVNBuddy\Helper\DateHelper; +use ConsoleHelpers\SVNBuddy\Helper\SizeHelper; +use ConsoleHelpers\SVNBuddy\Helper\OutputHelper; +use ConsoleHelpers\SVNBuddy\InteractiveEditor; +use ConsoleHelpers\SVNBuddy\Updater\Updater; class ContainerTest extends BaseContainerTest { @@ -34,34 +56,34 @@ public function instanceDataProvider() 'config_defaults', ), 'working_directory_sub_folder' => array('.svn-buddy', 'working_directory_sub_folder'), - 'process_factory' => array('ConsoleHelpers\\SVNBuddy\\Process\\ProcessFactory', 'process_factory'), - 'merge_source_detector' => array('ConsoleHelpers\\SVNBuddy\\MergeSourceDetector\\MergeSourceDetectorAggregator', 'merge_source_detector'), - 'repository_url_resolver' => array('ConsoleHelpers\SVNBuddy\Repository\Connector\UrlResolver', 'repository_url_resolver'), - 'cache_manager' => array('ConsoleHelpers\\SVNBuddy\\Cache\\CacheManager', 'cache_manager'), - 'statement_profiler' => array('ConsoleHelpers\SVNBuddy\Database\StatementProfiler', 'statement_profiler'), - 'migration_manager' => array('ConsoleHelpers\DatabaseMigration\MigrationManager', 'migration_manager'), - 'revision_log_factory' => array('ConsoleHelpers\\SVNBuddy\\Repository\\RevisionLog\\RevisionLogFactory', 'revision_log_factory'), - 'log_message_parser_factory' => array('ConsoleHelpers\SVNBuddy\Repository\Parser\LogMessageParserFactory', 'log_message_parser_factory'), - 'revision_list_parser' => array('ConsoleHelpers\\SVNBuddy\\Repository\\Parser\\RevisionListParser', 'revision_list_parser'), - 'revision_printer' => array('ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionPrinter', 'revision_printer'), - 'command_factory' => array('ConsoleHelpers\\SVNBuddy\\Repository\\Connector\\CommandFactory', 'command_factory'), - 'repository_connector' => array('ConsoleHelpers\\SVNBuddy\\Repository\\Connector\\Connector', 'repository_connector'), - 'commit_message_builder' => array('ConsoleHelpers\\SVNBuddy\\Repository\\CommitMessage\\CommitMessageBuilder', 'commit_message_builder'), - 'working_copy_resolver' => array('ConsoleHelpers\\SVNBuddy\\Repository\\WorkingCopyResolver', 'working_copy_resolver'), - 'working_copy_conflict_tracker' => array('ConsoleHelpers\\SVNBuddy\\Repository\\WorkingCopyConflictTracker', 'working_copy_conflict_tracker'), - 'merge_template_factory' => array('ConsoleHelpers\SVNBuddy\Repository\CommitMessage\MergeTemplateFactory', 'merge_template_factory'), - 'command_config' => array('ConsoleHelpers\\SVNBuddy\\Config\\CommandConfig', 'command_config'), - 'date_helper' => array('ConsoleHelpers\\SVNBuddy\\Helper\\DateHelper', 'date_helper'), - 'size_helper' => array('ConsoleHelpers\SVNBuddy\Helper\SizeHelper', 'size_helper'), - 'output_helper' => array('ConsoleHelpers\SVNBuddy\Helper\OutputHelper', 'output_helper'), - 'editor' => array('ConsoleHelpers\\SVNBuddy\\InteractiveEditor', 'editor'), + 'process_factory' => array(ProcessFactory::class, 'process_factory'), + 'merge_source_detector' => array(MergeSourceDetectorAggregator::class, 'merge_source_detector'), + 'repository_url_resolver' => array(UrlResolver::class, 'repository_url_resolver'), + 'cache_manager' => array(CacheManager::class, 'cache_manager'), + 'statement_profiler' => array(StatementProfiler::class, 'statement_profiler'), + 'migration_manager' => array(MigrationManager::class, 'migration_manager'), + 'revision_log_factory' => array(RevisionLogFactory::class, 'revision_log_factory'), + 'log_message_parser_factory' => array(LogMessageParserFactory::class, 'log_message_parser_factory'), + 'revision_list_parser' => array(RevisionListParser::class, 'revision_list_parser'), + 'revision_printer' => array(RevisionPrinter::class, 'revision_printer'), + 'command_factory' => array(CommandFactory::class, 'command_factory'), + 'repository_connector' => array(Connector::class, 'repository_connector'), + 'commit_message_builder' => array(CommitMessageBuilder::class, 'commit_message_builder'), + 'working_copy_resolver' => array(WorkingCopyResolver::class, 'working_copy_resolver'), + 'working_copy_conflict_tracker' => array(WorkingCopyConflictTracker::class, 'working_copy_conflict_tracker'), + 'merge_template_factory' => array(MergeTemplateFactory::class, 'merge_template_factory'), + 'command_config' => array(CommandConfig::class, 'command_config'), + 'date_helper' => array(DateHelper::class, 'date_helper'), + 'size_helper' => array(SizeHelper::class, 'size_helper'), + 'output_helper' => array(OutputHelper::class, 'output_helper'), + 'editor' => array(InteractiveEditor::class, 'editor'), ); // The "updater" service requires executable to be writable (assuming it's PHAR file all the time). $local_phar_file = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0]; if ( is_writable($local_phar_file) ) { - $new_instance_data['updater'] = array('ConsoleHelpers\\SVNBuddy\\Updater\\Updater', 'updater'); + $new_instance_data['updater'] = array(Updater::class, 'updater'); } return array_merge($instance_data, $new_instance_data); diff --git a/tests/SVNBuddy/MergeSourceDetector/MergeSourceDetectorAggregatorTest.php b/tests/SVNBuddy/MergeSourceDetector/MergeSourceDetectorAggregatorTest.php index 13adcc8..0f1972c 100644 --- a/tests/SVNBuddy/MergeSourceDetector/MergeSourceDetectorAggregatorTest.php +++ b/tests/SVNBuddy/MergeSourceDetector/MergeSourceDetectorAggregatorTest.php @@ -14,6 +14,7 @@ use ConsoleHelpers\SVNBuddy\MergeSourceDetector\MergeSourceDetectorAggregator; use Prophecy\Prophecy\ObjectProphecy; use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use ConsoleHelpers\SVNBuddy\MergeSourceDetector\AbstractMergeSourceDetector; class MergeSourceDetectorAggregatorTest extends AbstractMergeSourceDetectorTestCase { @@ -33,15 +34,15 @@ class MergeSourceDetectorAggregatorTest extends AbstractMergeSourceDetectorTestC */ protected function setupTest() { - $sub_detector1 = $this->prophesize('ConsoleHelpers\\SVNBuddy\\MergeSourceDetector\\AbstractMergeSourceDetector'); + $sub_detector1 = $this->prophesize(AbstractMergeSourceDetector::class); $sub_detector1->getWeight()->willReturn(2)->shouldBeCalled(); $this->detectors[] = $sub_detector1; - $sub_detector2 = $this->prophesize('ConsoleHelpers\\SVNBuddy\\MergeSourceDetector\\AbstractMergeSourceDetector'); + $sub_detector2 = $this->prophesize(AbstractMergeSourceDetector::class); $sub_detector2->getWeight()->willReturn(1)->shouldBeCalled(); $this->detectors[] = $sub_detector2; - $sub_detector2 = $this->prophesize('ConsoleHelpers\\SVNBuddy\\MergeSourceDetector\\AbstractMergeSourceDetector'); + $sub_detector2 = $this->prophesize(AbstractMergeSourceDetector::class); $sub_detector2->getWeight()->willReturn(3)->shouldBeCalled(); $this->detectors[] = $sub_detector2; } @@ -81,7 +82,7 @@ public function testAddingDetectorWithDuplicateWeight() $this->expectException('\InvalidArgumentException'); $this->expectExceptionMessage('Another detector with same weight is already added.'); - $sub_detector = $this->prophesize('ConsoleHelpers\\SVNBuddy\\MergeSourceDetector\\AbstractMergeSourceDetector'); + $sub_detector = $this->prophesize(AbstractMergeSourceDetector::class); $sub_detector->getWeight()->willReturn(1)->shouldBeCalled(); $detector = $this->createDetector(); diff --git a/tests/SVNBuddy/Process/ProcessFactoryTest.php b/tests/SVNBuddy/Process/ProcessFactoryTest.php index 4e1d950..446db73 100644 --- a/tests/SVNBuddy/Process/ProcessFactoryTest.php +++ b/tests/SVNBuddy/Process/ProcessFactoryTest.php @@ -13,13 +13,15 @@ use ConsoleHelpers\SVNBuddy\Process\ProcessFactory; use PHPUnit\Framework\TestCase; +use ConsoleHelpers\SVNBuddy\Process\IProcessFactory; +use Symfony\Component\Process\Process; class ProcessFactoryTest extends TestCase { public function testImplementsCorrectInterface() { - $this->assertInstanceOf('ConsoleHelpers\\SVNBuddy\\Process\\IProcessFactory', new ProcessFactory()); + $this->assertInstanceOf(IProcessFactory::class, new ProcessFactory()); } public function testProcessCanBeCreated() @@ -28,7 +30,7 @@ public function testProcessCanBeCreated() $process = $factory->createProcess('command', 10); - $this->assertInstanceOf('Symfony\\Component\\Process\\Process', $process); + $this->assertInstanceOf(Process::class, $process); $this->assertEquals('command', $process->getCommandLine()); $this->assertEquals(10, $process->getIdleTimeout()); $this->assertNull($process->getTimeout()); diff --git a/tests/SVNBuddy/Repository/Connector/CommandFactoryTest.php b/tests/SVNBuddy/Repository/Connector/CommandFactoryTest.php index 14a9215..ee196f1 100644 --- a/tests/SVNBuddy/Repository/Connector/CommandFactoryTest.php +++ b/tests/SVNBuddy/Repository/Connector/CommandFactoryTest.php @@ -17,6 +17,11 @@ use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use ConsoleHelpers\ConsoleKit\Config\ConfigEditor; +use ConsoleHelpers\ConsoleKit\ConsoleIO; +use ConsoleHelpers\SVNBuddy\Process\IProcessFactory; +use ConsoleHelpers\SVNBuddy\Cache\CacheManager; +use Symfony\Component\Process\Process; class CommandFactoryTest extends TestCase { @@ -64,10 +69,10 @@ class CommandFactoryTest extends TestCase */ protected function setupTest() { - $this->_configEditor = $this->prophesize('ConsoleHelpers\\ConsoleKit\\Config\\ConfigEditor'); - $this->_io = $this->prophesize('ConsoleHelpers\\ConsoleKit\\ConsoleIO'); - $this->_processFactory = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Process\\IProcessFactory'); - $this->_cacheManager = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Cache\\CacheManager'); + $this->_configEditor = $this->prophesize(ConfigEditor::class); + $this->_io = $this->prophesize(ConsoleIO::class); + $this->_processFactory = $this->prophesize(IProcessFactory::class); + $this->_cacheManager = $this->prophesize(CacheManager::class); // To get nice exception back when unexpected command is executed. $this->_processFactory @@ -155,7 +160,7 @@ public function commandWithParamsDataProvider() */ private function _expectCommand($command, $output, $error_msg = null, $error_code = 0) { - $process = $this->prophesize('Symfony\\Component\\Process\\Process'); + $process = $this->prophesize(Process::class); $expectation = $process ->mustRun(strpos($command, 'upgrade') !== false ? Argument::type('callable') : null) diff --git a/tests/SVNBuddy/Repository/Connector/CommandTest.php b/tests/SVNBuddy/Repository/Connector/CommandTest.php index 4b88afb..d8cd08d 100644 --- a/tests/SVNBuddy/Repository/Connector/CommandTest.php +++ b/tests/SVNBuddy/Repository/Connector/CommandTest.php @@ -18,6 +18,10 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Process; +use ConsoleHelpers\SVNBuddy\Process\IProcessFactory; +use ConsoleHelpers\ConsoleKit\ConsoleIO; +use ConsoleHelpers\SVNBuddy\Cache\CacheManager; +use ConsoleHelpers\SVNBuddy\Exception\RepositoryCommandException; class CommandTest extends TestCase { @@ -63,10 +67,10 @@ class CommandTest extends TestCase */ protected function setupTest() { - $this->_processFactory = $this->prophesize('ConsoleHelpers\SVNBuddy\Process\IProcessFactory'); - $this->_process = $this->prophesize('Symfony\\Component\\Process\\Process'); - $this->_io = $this->prophesize('ConsoleHelpers\\ConsoleKit\\ConsoleIO'); - $this->_cacheManager = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Cache\\CacheManager'); + $this->_processFactory = $this->prophesize(IProcessFactory::class); + $this->_process = $this->prophesize(Process::class); + $this->_io = $this->prophesize(ConsoleIO::class); + $this->_cacheManager = $this->prophesize(CacheManager::class); } /** @@ -406,8 +410,7 @@ public function testRunError() { $this->_command = $this->_createCommand('svn log'); - /** @var ProcessFailedException $exception */ - $exception = $this->prophesize('Symfony\\Component\\Process\\Exception\\ProcessFailedException'); + $exception = $this->prophesize(ProcessFailedException::class); $this->_process->mustRun(null)->willThrow($exception->reveal())->shouldBeCalled(); $this->_process->getErrorOutput()->willReturn('error output')->shouldBeCalled(); @@ -425,7 +428,7 @@ public function testRunError() } catch ( \Exception $thrown_exception ) { $this->assertInstanceOf( - 'ConsoleHelpers\\SVNBuddy\\Exception\\RepositoryCommandException', + RepositoryCommandException::class, $thrown_exception, sprintf( 'Exception of correct class was thrown' . PHP_EOL . 'Message:' . PHP_EOL . '%s', diff --git a/tests/SVNBuddy/Repository/Connector/ConnectorTest.php b/tests/SVNBuddy/Repository/Connector/ConnectorTest.php index a418a81..a6ae2e3 100644 --- a/tests/SVNBuddy/Repository/Connector/ConnectorTest.php +++ b/tests/SVNBuddy/Repository/Connector/ConnectorTest.php @@ -17,6 +17,11 @@ use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use ConsoleHelpers\ConsoleKit\Config\ConfigEditor; +use ConsoleHelpers\ConsoleKit\ConsoleIO; +use ConsoleHelpers\SVNBuddy\Repository\Connector\CommandFactory; +use ConsoleHelpers\SVNBuddy\Repository\Parser\RevisionListParser; +use ConsoleHelpers\SVNBuddy\Repository\Connector\Command; class ConnectorTest extends TestCase { @@ -66,10 +71,10 @@ class ConnectorTest extends TestCase */ protected function setupTest() { - $this->_configEditor = $this->prophesize('ConsoleHelpers\\ConsoleKit\\Config\\ConfigEditor'); - $this->_io = $this->prophesize('ConsoleHelpers\\ConsoleKit\\ConsoleIO'); - $this->_commandFactory = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\Connector\\CommandFactory'); - $this->_revisionListParser = $this->prophesize('ConsoleHelpers\SVNBuddy\Repository\Parser\RevisionListParser'); + $this->_configEditor = $this->prophesize(ConfigEditor::class); + $this->_io = $this->prophesize(ConsoleIO::class); + $this->_commandFactory = $this->prophesize(CommandFactory::class); + $this->_revisionListParser = $this->prophesize(RevisionListParser::class); // To get nice exception back when unexpected command is executed. $this->_commandFactory @@ -277,7 +282,7 @@ public function testGetWorkingCopyUrlWithUnknownError() Error #555: error message MESSAGE; - $this->expectException('ConsoleHelpers\\SVNBuddy\\Exception\\RepositoryCommandException'); + $this->expectException(RepositoryCommandException::class); $this->expectExceptionMessage($exception_msg); $this->_repositoryConnector->getWorkingCopyUrl('/path/to/working-copy'); @@ -307,7 +312,7 @@ public function testGetWorkingCopyUrlOnOldFormatWorkingCopyAndUpgradeRejected() error message MESSAGE; - $this->expectException('ConsoleHelpers\\SVNBuddy\\Exception\\RepositoryCommandException'); + $this->expectException(RepositoryCommandException::class); $this->expectExceptionMessage(sprintf( $exception_msg, RepositoryCommandException::SVN_ERR_WC_UPGRADE_REQUIRED @@ -856,7 +861,7 @@ public function testGetFileContent() */ private function _expectCommand($sub_command, $param_string, $output, $error_msg = null, $error_code = 0) { - $command = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\Connector\\Command'); + $command = $this->prophesize(Command::class); if ( $sub_command === 'upgrade' ) { $run_expectation = $command->runLive()->shouldBeCalled(); diff --git a/tests/SVNBuddy/Repository/RevisionLog/Plugin/BugsPluginTest.php b/tests/SVNBuddy/Repository/RevisionLog/Plugin/BugsPluginTest.php index 687f3dd..c30a5f9 100644 --- a/tests/SVNBuddy/Repository/RevisionLog/Plugin/BugsPluginTest.php +++ b/tests/SVNBuddy/Repository/RevisionLog/Plugin/BugsPluginTest.php @@ -15,6 +15,8 @@ use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\IPlugin; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; +use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; +use ConsoleHelpers\SVNBuddy\Repository\Parser\LogMessageParserFactory; class BugsPluginTest extends AbstractPluginTestCase { @@ -39,8 +41,8 @@ class BugsPluginTest extends AbstractPluginTestCase */ protected function setupTest() { - $this->repositoryConnector = $this->prophesize('ConsoleHelpers\SVNBuddy\Repository\Connector\Connector'); - $this->logMessageParserFactory = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\Parser\\LogMessageParserFactory'); + $this->repositoryConnector = $this->prophesize(Connector::class); + $this->logMessageParserFactory = $this->prophesize(LogMessageParserFactory::class); parent::setupTest(); } diff --git a/tests/SVNBuddy/Repository/RevisionLog/RevisionLogFactoryTest.php b/tests/SVNBuddy/Repository/RevisionLog/RevisionLogFactoryTest.php index fa6b72d..748d70f 100644 --- a/tests/SVNBuddy/Repository/RevisionLog/RevisionLogFactoryTest.php +++ b/tests/SVNBuddy/Repository/RevisionLog/RevisionLogFactoryTest.php @@ -13,13 +13,18 @@ use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLogFactory; use Prophecy\Argument; +use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; +use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\DatabaseManager; +use ConsoleHelpers\SVNBuddy\Repository\Parser\LogMessageParserFactory; +use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\MigrationContext; +use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLog; class RevisionLogFactoryTest extends AbstractDatabaseAwareTestCase { public function testGetRevisionLog() { - $repository_connector = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\Connector\\Connector'); + $repository_connector = $this->prophesize(Connector::class); $repository_connector->removeCredentials('svn://localhost/projects/project-name/trunk')->willReturnArgument(0)->shouldBeCalled(); $repository_connector->getLastRevision('svn://localhost')->willReturn(0)->shouldBeCalled(); @@ -29,11 +34,11 @@ public function testGetRevisionLog() $repository_connector->getProjectUrl('/projects/project-name/trunk')->willReturn('/projects/project-name')->shouldBeCalled(); $repository_connector->getRefByPath('/projects/project-name/trunk')->willReturn('trunk')->shouldBeCalled(); - $database_manager = $this->prophesize('ConsoleHelpers\SVNBuddy\Repository\RevisionLog\DatabaseManager'); + $database_manager = $this->prophesize(DatabaseManager::class); $database_manager->getDatabase('svn://localhost', null)->willReturn($this->database); - $database_manager->runMigrations(Argument::type('ConsoleHelpers\\SVNBuddy\\Repository\\RevisionLog\\MigrationContext'))->shouldBeCalled(); + $database_manager->runMigrations(Argument::type(MigrationContext::class))->shouldBeCalled(); - $log_message_parser_factory = $this->prophesize('ConsoleHelpers\SVNBuddy\Repository\Parser\LogMessageParserFactory'); + $log_message_parser_factory = $this->prophesize(LogMessageParserFactory::class); $factory = new RevisionLogFactory( $repository_connector->reveal(), @@ -41,7 +46,7 @@ public function testGetRevisionLog() $log_message_parser_factory->reveal() ); $this->assertInstanceOf( - 'ConsoleHelpers\\SVNBuddy\\Repository\\RevisionLog\\RevisionLog', + RevisionLog::class, $factory->getRevisionLog('svn://localhost/projects/project-name/trunk') ); } diff --git a/tests/SVNBuddy/Repository/RevisionLog/RevisionLogTest.php b/tests/SVNBuddy/Repository/RevisionLog/RevisionLogTest.php index 596a1af..ec2a5e3 100644 --- a/tests/SVNBuddy/Repository/RevisionLog/RevisionLogTest.php +++ b/tests/SVNBuddy/Repository/RevisionLog/RevisionLogTest.php @@ -24,6 +24,10 @@ use Tests\ConsoleHelpers\SVNBuddy\ProphecyToken\ProgressBarOutputToken; use Tests\ConsoleHelpers\SVNBuddy\ProphecyToken\SimpleXMLElementToken; use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; +use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\IRepositoryCollectorPlugin; +use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\Plugin\IDatabaseCollectorPlugin; +use ConsoleHelpers\SVNBuddy\Repository\Connector\Command; class RevisionLogTest extends TestCase { @@ -57,8 +61,8 @@ class RevisionLogTest extends TestCase */ protected function setupTest() { - $this->repositoryConnector = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\Connector\\Connector'); - $this->io = $this->prophesize('ConsoleHelpers\\ConsoleKit\\ConsoleIO'); + $this->repositoryConnector = $this->prophesize(Connector::class); + $this->io = $this->prophesize(ConsoleIO::class); $this->revisionUrlBuilder = $this->prophesize(RevisionUrlBuilder::class); } @@ -170,7 +174,7 @@ public function testGetBugsFromRevisions() { $revision_log = $this->createRevisionLog('svn://localhost/projects/project-name/trunk'); - $plugin = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\RevisionLog\\Plugin\\IPlugin'); + $plugin = $this->prophesize(IPlugin::class); $plugin->getName()->willReturn('bugs')->shouldBeCalled(); $plugin->setRevisionLog($revision_log)->shouldBeCalled(); $plugin->getRevisionsData(array(1, 2)) @@ -267,7 +271,7 @@ public function testRefreshWithoutCacheWithoutOutput(ConsoleIO $io = null, Progr $revision_log = $this->createRevisionLog('svn://localhost/projects/project-name/trunk', $io); // Add repository collector plugin. - $repository_collector_plugin = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\RevisionLog\\Plugin\\IRepositoryCollectorPlugin'); + $repository_collector_plugin = $this->prophesize(IRepositoryCollectorPlugin::class); $repository_collector_plugin->getName()->willReturn('mocked_repo')->shouldBeCalled(); $repository_collector_plugin->setRevisionLog($revision_log)->shouldBeCalled(); $repository_collector_plugin->whenDatabaseReady()->shouldBeCalled(); @@ -288,7 +292,7 @@ public function testRefreshWithoutCacheWithoutOutput(ConsoleIO $io = null, Progr } // Add database collector plugin. - $database_collector_plugin = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\RevisionLog\\Plugin\\IDatabaseCollectorPlugin'); + $database_collector_plugin = $this->prophesize(IDatabaseCollectorPlugin::class); $database_collector_plugin->getName()->willReturn('mocked_db')->shouldBeCalled(); $database_collector_plugin->setRevisionLog($revision_log)->shouldBeCalled(); $database_collector_plugin->whenDatabaseReady()->shouldBeCalled(); @@ -321,14 +325,14 @@ public function testRefreshWithCache() $revision_log = $this->createRevisionLog('svn://localhost/projects/project-name/trunk'); // Add repository collector plugin. - $repository_collector_plugin = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\RevisionLog\\Plugin\\IRepositoryCollectorPlugin'); + $repository_collector_plugin = $this->prophesize(IRepositoryCollectorPlugin::class); $repository_collector_plugin->getName()->willReturn('mocked_repo')->shouldBeCalled(); $repository_collector_plugin->setRevisionLog($revision_log)->shouldBeCalled(); $repository_collector_plugin->whenDatabaseReady()->shouldBeCalled(); $repository_collector_plugin->getLastRevision()->willReturn(1000)->shouldBeCalled(); // Add database collector plugin. - $database_collector_plugin = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\RevisionLog\\Plugin\\IDatabaseCollectorPlugin'); + $database_collector_plugin = $this->prophesize(IDatabaseCollectorPlugin::class); $database_collector_plugin->getName()->willReturn('mocked_db')->shouldBeCalled(); $database_collector_plugin->setRevisionLog($revision_log)->shouldBeCalled(); $database_collector_plugin->whenDatabaseReady()->shouldBeCalled(); @@ -427,7 +431,7 @@ protected function expectRepositoryCommand($command_name, $param_string, $result $result = simplexml_load_string($result); } - $command = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\Connector\\Command'); + $command = $this->prophesize(Command::class); $command->run()->willReturn($result)->shouldBeCalled(); $command->setCacheDuration('10 years')->shouldBeCalled(); @@ -468,7 +472,7 @@ protected function createRevisionLog($repository_url, ConsoleIO $io = null) */ protected function createPluginMock(RevisionLog $revision_log) { - $plugin = $this->prophesize('ConsoleHelpers\\SVNBuddy\\Repository\\RevisionLog\\Plugin\\IPlugin'); + $plugin = $this->prophesize(IPlugin::class); $plugin->getName()->willReturn('mocked')->shouldBeCalled(); $plugin->setRevisionLog($revision_log)->shouldBeCalled();