diff --git a/composer.json b/composer.json index b1c417f..bf41b45 100644 --- a/composer.json +++ b/composer.json @@ -35,8 +35,7 @@ "vierbergenlars/php-semver": "^3.0" }, "require-dev": { - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^4.0|^5.0" + "phpunit/phpunit": "^4.8.36|^5.7.27" }, "bin": [ "bin/php-semver-checker-git" @@ -48,7 +47,7 @@ }, "autoload-dev": { "psr-4": { - "PHPSemVerCheckerGit\\Test\\": "tests/PHPSemVerCheckerGit" + "PHPSemVerCheckerGit\\Test\\": "test" } }, "config": { diff --git a/composer.lock b/composer.lock index d7246b5..1cbf926 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "fd8881f82ae2817293af2d6e07233276", + "content-hash": "d890a9287ae2a1670bb5a86ead2b1050", "packages": [ { "name": "hassankhan/config", @@ -113,20 +113,20 @@ "source": "https://github.com/tomzx/gitter/tree/php-semver-checker", "issues": "https://github.com/tomzx/gitter/issues" }, - "time": "2015-06-28T00:49:30+00:00" + "time": "2015-06-28 00:49:30" }, { "name": "nikic/php-parser", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "e57b3a09784f846411aa7ed664eedb73e3399078" + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/e57b3a09784f846411aa7ed664eedb73e3399078", - "reference": "e57b3a09784f846411aa7ed664eedb73e3399078", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", "shasum": "" }, "require": { @@ -164,7 +164,7 @@ "parser", "php" ], - "time": "2018-01-25T21:31:33+00:00" + "time": "2018-02-28T20:30:58+00:00" }, { "name": "psr/log", @@ -215,16 +215,16 @@ }, { "name": "symfony/console", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "26b6f419edda16c19775211987651cb27baea7f1" + "reference": "067339e9b8ec30d5f19f5950208893ff026b94f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/26b6f419edda16c19775211987651cb27baea7f1", - "reference": "26b6f419edda16c19775211987651cb27baea7f1", + "url": "https://api.github.com/repos/symfony/console/zipball/067339e9b8ec30d5f19f5950208893ff026b94f7", + "reference": "067339e9b8ec30d5f19f5950208893ff026b94f7", "shasum": "" }, "require": { @@ -280,20 +280,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2018-01-29T09:03:43+00:00" + "time": "2018-02-26T15:46:28+00:00" }, { "name": "symfony/debug", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "53f6af2805daf52a43b393b93d2f24925d35c937" + "reference": "9b1071f86e79e1999b3d3675d2e0e7684268b9bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/53f6af2805daf52a43b393b93d2f24925d35c937", - "reference": "53f6af2805daf52a43b393b93d2f24925d35c937", + "url": "https://api.github.com/repos/symfony/debug/zipball/9b1071f86e79e1999b3d3675d2e0e7684268b9bc", + "reference": "9b1071f86e79e1999b3d3675d2e0e7684268b9bc", "shasum": "" }, "require": { @@ -336,7 +336,7 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2018-01-18T22:16:57+00:00" + "time": "2018-02-28T21:49:22+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -399,16 +399,16 @@ }, { "name": "symfony/process", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "09a5172057be8fc677840e591b17f385e58c7c0d" + "reference": "cc4aea21f619116aaf1c58016a944e4821c8e8af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/09a5172057be8fc677840e591b17f385e58c7c0d", - "reference": "09a5172057be8fc677840e591b17f385e58c7c0d", + "url": "https://api.github.com/repos/symfony/process/zipball/cc4aea21f619116aaf1c58016a944e4821c8e8af", + "reference": "cc4aea21f619116aaf1c58016a944e4821c8e8af", "shasum": "" }, "require": { @@ -444,20 +444,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2018-01-29T09:03:43+00:00" + "time": "2018-02-12T17:55:00+00:00" }, { "name": "symfony/yaml", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "eab73b6c21d27ae4cd037c417618dfd4befb0bfe" + "reference": "6af42631dcf89e9c616242c900d6c52bd53bd1bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/eab73b6c21d27ae4cd037c417618dfd4befb0bfe", - "reference": "eab73b6c21d27ae4cd037c417618dfd4befb0bfe", + "url": "https://api.github.com/repos/symfony/yaml/zipball/6af42631dcf89e9c616242c900d6c52bd53bd1bb", + "reference": "6af42631dcf89e9c616242c900d6c52bd53bd1bb", "shasum": "" }, "require": { @@ -502,7 +502,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-01-21T19:05:02+00:00" + "time": "2018-02-16T09:50:28+00:00" }, { "name": "tomzx/finder", @@ -555,16 +555,16 @@ }, { "name": "tomzx/php-semver-checker", - "version": "v0.12.0", + "version": "v0.12.1", "source": { "type": "git", "url": "https://github.com/tomzx/php-semver-checker.git", - "reference": "9930230655d48c5e21afe3c7c2396115a49ae5ae" + "reference": "9e86860dfdea8ef4a69c6834665521d2ae7899e8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tomzx/php-semver-checker/zipball/9930230655d48c5e21afe3c7c2396115a49ae5ae", - "reference": "9930230655d48c5e21afe3c7c2396115a49ae5ae", + "url": "https://api.github.com/repos/tomzx/php-semver-checker/zipball/9e86860dfdea8ef4a69c6834665521d2ae7899e8", + "reference": "9e86860dfdea8ef4a69c6834665521d2ae7899e8", "shasum": "" }, "require": { @@ -585,7 +585,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "0.12-dev" + "dev-master": "0.13-dev" } }, "autoload": { @@ -611,7 +611,7 @@ "semantic versioning", "semver" ], - "time": "2018-02-08T21:36:08+00:00" + "time": "2018-02-08T22:27:57+00:00" }, { "name": "vierbergenlars/php-semver", @@ -721,119 +721,6 @@ ], "time": "2015-06-14T21:17:01+00:00" }, - { - "name": "hamcrest/hamcrest-php", - "version": "v2.0.0", - "source": { - "type": "git", - "url": "https://github.com/hamcrest/hamcrest-php.git", - "reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/776503d3a8e85d4f9a1148614f95b7a608b046ad", - "reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad", - "shasum": "" - }, - "require": { - "php": "^5.3|^7.0" - }, - "replace": { - "cordoval/hamcrest-php": "*", - "davedevelopment/hamcrest-php": "*", - "kodova/hamcrest-php": "*" - }, - "require-dev": { - "phpunit/php-file-iterator": "1.3.3", - "phpunit/phpunit": "~4.0", - "satooshi/php-coveralls": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "hamcrest" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD" - ], - "description": "This is the PHP port of Hamcrest Matchers", - "keywords": [ - "test" - ], - "time": "2016-01-20T08:20:44+00:00" - }, - { - "name": "mockery/mockery", - "version": "1.0", - "source": { - "type": "git", - "url": "https://github.com/mockery/mockery.git", - "reference": "1bac8c362b12f522fdd1f1fa3556284c91affa38" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/1bac8c362b12f522fdd1f1fa3556284c91affa38", - "reference": "1bac8c362b12f522fdd1f1fa3556284c91affa38", - "shasum": "" - }, - "require": { - "hamcrest/hamcrest-php": "~2.0", - "lib-pcre": ">=7.0", - "php": ">=5.6.0" - }, - "require-dev": { - "phpunit/phpunit": "~5.7|~6.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Mockery": "library/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Pádraic Brady", - "email": "padraic.brady@gmail.com", - "homepage": "http://blog.astrumfutura.com" - }, - { - "name": "Dave Marshall", - "email": "dave.marshall@atstsolutions.co.uk", - "homepage": "http://davedevelopment.co.uk" - } - ], - "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.", - "homepage": "http://github.com/mockery/mockery", - "keywords": [ - "BDD", - "TDD", - "library", - "mock", - "mock objects", - "mockery", - "stub", - "test", - "test double", - "testing" - ], - "time": "2017-10-06T16:20:43+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.7.0", @@ -1027,16 +914,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.7.3", + "version": "1.7.5", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf" + "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", - "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/dfd6be44111a7c41c2e884a336cc4f461b3b2401", + "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401", "shasum": "" }, "require": { @@ -1048,7 +935,7 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" }, "type": "library", "extra": { @@ -1086,7 +973,7 @@ "spy", "stub" ], - "time": "2017-11-24T13:59:53+00:00" + "time": "2018-02-19T10:16:54+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c4c78cc..4a5a39b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ - ./tests + ./test diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index eeb5478..32bb6e3 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -6,12 +6,12 @@ use Gitter\Repository; use PHPSemVerChecker\Analyzer\Analyzer; use PHPSemVerChecker\Finder\Finder; +use PHPSemVerChecker\Report\Report; use PHPSemVerChecker\Reporter\Reporter; -use PHPSemVerChecker\Scanner\Scanner; use PHPSemVerChecker\SemanticVersioning\Level; use PHPSemVerCheckerGit\Filter\SourceFilter; +use PHPSemVerCheckerGit\SourceFileProcessor; use RuntimeException; -use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -39,50 +39,47 @@ protected function configure() ]); } - /** - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Symfony\Component\Console\Output\OutputInterface $output - */ + /** + * @param string $directory + * @return \Gitter\Repository + */ + private function getRepository($directory) + { + $client = new Client(); + return $client->getRepository($directory); + } + + /** + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output) - { + { $startTime = microtime(true); $targetDirectory = getcwd(); - $tag = $this->config->get('tag'); $against = $this->config->get('against') ?: 'HEAD'; - $includeBefore = $this->config->get('include-before'); - $excludeBefore = $this->config->get('exclude-before'); - - $includeAfter = $this->config->get('include-after'); - $excludeAfter = $this->config->get('exclude-after'); - - $client = new Client(); - - $repository = $client->getRepository($targetDirectory); + $repository = $this->getRepository($targetDirectory); - if ($tag === null) { - $tag = $this->findLatestTag($repository); - } else { - $tag = $this->findTag($repository, $tag); - } + $tag = $this->getInitialTag($repository); if ($tag === null) { $output->writeln('No tags to suggest against'); - return; + return 1; } $output->writeln('Testing ' . $against . ' against tag: ' . $tag . ''); - $finder = new Finder(); - $sourceFilter = new SourceFilter(); - $beforeScanner = new Scanner(); - $afterScanner = new Scanner(); - - $modifiedFiles = $repository->getModifiedFiles($tag, $against); - $modifiedFiles = array_filter($modifiedFiles, function ($modifiedFile) { - return substr($modifiedFile, -4) === '.php'; - }); + $sourceFileProcessor = new SourceFileProcessor( + new SourceFilter(), + $repository, + $output, + new Finder(), + $targetDirectory, + $repository->getModifiedFiles($tag, $against) + ); $initialBranch = $repository->getCurrentBranch(); @@ -91,66 +88,35 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('If you still wish to run against a detached HEAD, use --allow-detached.'); return -1; } - - // Start with the against commit - $repository->checkout($against . ' --'); - - $sourceAfter = $finder->findFromString($targetDirectory, $includeAfter, $excludeAfter); - $sourceAfterMatchedCount = count($sourceAfter); - $sourceAfter = $sourceFilter->filter($sourceAfter, $modifiedFiles); - $progress = new ProgressBar($output, count($sourceAfter)); - foreach ($sourceAfter as $file) { - $afterScanner->scan($file); - $progress->advance(); - } - - $progress->clear(); - - // Finish with the tag commit - $repository->checkout($tag . ' --'); - - $sourceBefore = $finder->findFromString($targetDirectory, $includeBefore, $excludeBefore); - $sourceBeforeMatchedCount = count($sourceBefore); - $sourceBefore = $sourceFilter->filter($sourceBefore, $modifiedFiles); - $progress = new ProgressBar($output, count($sourceBefore)); - foreach ($sourceBefore as $file) { - $beforeScanner->scan($file); - $progress->advance(); - } - - $progress->clear(); - + $after = $sourceFileProcessor->processFileList( + $against, + $this->config->get('include-after'), + $this->config->get('exclude-after') + ); + $before = $sourceFileProcessor->processFileList( + $tag, + $this->config->get('include-before'), + $this->config->get('exclude-before') + ); // Reset repository to initial branch if ($initialBranch) { $repository->checkout($initialBranch); } - $registryBefore = $beforeScanner->getRegistry(); - $registryAfter = $afterScanner->getRegistry(); - $analyzer = new Analyzer(); - $report = $analyzer->analyze($registryBefore, $registryAfter); + $report = $analyzer->analyze($before->getScanner()->getRegistry(), $after->getScanner()->getRegistry()); $tag = new SemanticVersion($tag); - $newTag = new SemanticVersion($tag); - - $suggestedLevel = $report->getSuggestedLevel(); - - if ($suggestedLevel !== Level::NONE) { - if ($newTag->getPrerelease()) { - $newTag->inc('prerelease'); - } else { - if ($newTag->getMajor() < 1 && $suggestedLevel === Level::MAJOR) { - $newTag->inc('minor'); - } else { - $newTag->inc(strtolower(Level::toString($suggestedLevel))); - } - } - } + $newTag = $this->getNextTag($report, $tag); - $output->writeln(''); - $output->writeln('Initial semantic version: ' . $tag . ''); - $output->writeln('Suggested semantic version: ' . $newTag . ''); + $output->write( + array( + '', + 'Initial semantic version: ' . $tag . '', + 'Suggested semantic version: ' . $newTag . '' + ), + true + ); if ($this->config->get('details')) { $reporter = new Reporter($report); @@ -158,11 +124,54 @@ protected function execute(InputInterface $input, OutputInterface $output) } $duration = microtime(true) - $startTime; - $output->writeln(''); - $output->writeln('[Scanned files] Before: ' . count($sourceBefore) . ' (' . $sourceBeforeMatchedCount . ' unfiltered), After: ' . count($sourceAfter) . ' (' . $sourceAfterMatchedCount . ' unfiltered)'); - $output->writeln('Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB'); + $output->write( + array( + '', + '[Scanned files] Before: ' . $before->getFilteredCount() . ' (' . $before->getUnfilteredCount() . ' unfiltered), After: ' . $after->getFilteredCount() . ' (' . $after->getUnfilteredCount() . ' unfiltered)', + 'Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB' + ), + true + ); + return 0; } + /** + * @param \PHPSemVerChecker\Report\Report $report + * @param SemanticVersion $tag + * @return SemanticVersion + */ + private function getNextTag(Report $report, SemanticVersion $tag) + { + $newTag = new SemanticVersion($tag); + $suggestedLevel = $report->getSuggestedLevel(); + if ($suggestedLevel === Level::NONE) { + return $newTag; + } + if ($newTag->getPrerelease()) { + $newTag->inc('prerelease'); + return $newTag; + } + if ($newTag->getMajor() < 1 && $suggestedLevel === Level::MAJOR) { + $newTag->inc('minor'); + return $newTag; + } + $newTag->inc(strtolower(Level::toString($suggestedLevel))); + return $newTag; + } + + /** + * @param \Gitter\Repository $repository + * @return null|string + */ + private function getInitialTag(Repository $repository) + { + $tag = $this->config->get('tag'); + if ($tag === null) { + return $this->findLatestTag($repository); + } + return $this->findTag($repository, $tag); + } + /** * @param \Gitter\Repository $repository * @return string|null @@ -194,6 +203,10 @@ protected function findTag(Repository $repository, $tag) return $this->getMappedVersionTag($tags, $satisfyingTag); } + /** + * @param array $tags + * @return array + */ private function filterTags(array $tags) { $filteredTags = []; @@ -209,8 +222,8 @@ private function filterTags(array $tags) } /** - * @param string[] $tags - * @param \vierbergenlars\SemVer\version|string|null $versionTag + * @param string[] $tags + * @param SemanticVersion|string|null $versionTag * @return string|null */ private function getMappedVersionTag(array $tags, $versionTag) diff --git a/src/PHPSemVerCheckerGit/ProcessedFileList.php b/src/PHPSemVerCheckerGit/ProcessedFileList.php new file mode 100644 index 0000000..48a8172 --- /dev/null +++ b/src/PHPSemVerCheckerGit/ProcessedFileList.php @@ -0,0 +1,88 @@ +unfilteredCount = count($unfiltered); + $this->filteredCount = count($filtered); + $this->filtered = $filtered; + $this->unfiltered = $unfiltered; + $this->scanner = $scanner; + } + + /** + * @return \PHPSemVerChecker\Scanner\Scanner + */ + public function getScanner() + { + return $this->scanner; + } + + /** + * @return string[] + */ + public function getFiltered() + { + return $this->filtered; + } + + /** + * @return int + */ + public function getFilteredCount() + { + return $this->filteredCount; + } + + /** + * @return int + */ + public function getUnfilteredCount() + { + return $this->unfilteredCount; + } + + /** + * @return string[] + */ + public function getUnfiltered() + { + return $this->unfiltered; + } +} \ No newline at end of file diff --git a/src/PHPSemVerCheckerGit/SourceFileProcessor.php b/src/PHPSemVerCheckerGit/SourceFileProcessor.php new file mode 100644 index 0000000..eba3dc6 --- /dev/null +++ b/src/PHPSemVerCheckerGit/SourceFileProcessor.php @@ -0,0 +1,96 @@ +repository = $repository; + $this->output = $output; + $this->finder = $finder; + $this->filter = $filter; + $this->directory = $directory; + foreach($modifiedFiles as $file) { + if(substr($file, -4) === '.php') { + $this->modifiedFiles[] = $file; + } + } + } + + /** + * @param string $commitIdentifier + * @param $include + * @param $exclude + * @return \PHPSemVerCheckerGit\ProcessedFileList + */ + public function processFileList($commitIdentifier, $include, $exclude) + { + $scanner = new Scanner(); + $this->repository->checkout($commitIdentifier . ' --'); + $unfiltered = $this->finder->findFromString($this->directory, $include, $exclude); + $source = $this->filter->filter($unfiltered, $this->modifiedFiles); + $this->scanFileList($scanner, $source); + return new ProcessedFileList($unfiltered, $source, $scanner); + } + + /** + * @param \PHPSemVerChecker\Scanner\Scanner $scanner + * @param array $files + */ + private function scanFileList(Scanner $scanner, array $files) + { + $progress = new ProgressBar($this->output, count($files)); + foreach ($files as $file) { + $scanner->scan($file); + $progress->advance(); + } + $progress->clear(); + } +} \ No newline at end of file diff --git a/test/Console/Command/SuggestCommandTest.php b/test/Console/Command/SuggestCommandTest.php new file mode 100644 index 0000000..327135b --- /dev/null +++ b/test/Console/Command/SuggestCommandTest.php @@ -0,0 +1,83 @@ +getMethod('getNextTag'); + $method->setAccessible(true); + return $method; + } + + /** + * Provides a few test cases + * @return array + */ + public function provideGetNextTag() { + return array( + //v0.1.0 + array(Level::NONE, $this->getMockedVersion(0,1,0), '0.1.0'), + array(Level::PATCH, $this->getMockedVersion(0,1,0), '0.1.1'), + array(Level::MINOR, $this->getMockedVersion(0,1,0), '0.2.0'), + array(Level::MAJOR, $this->getMockedVersion(0,1,0), '0.2.0'), + //v1.0.0RC1 + array(Level::NONE, $this->getMockedVersion(1,0,'0-1'), '1.0.0-1'), + array(Level::PATCH, $this->getMockedVersion(1,0,'0-1'), '1.0.0-2'), + array(Level::MINOR, $this->getMockedVersion(1,0,'0-1'), '1.0.0-2'), + array(Level::MAJOR, $this->getMockedVersion(1,0,'0-1'), '1.0.0-2'), + //v1.0.0 + array(Level::NONE, $this->getMockedVersion(1,0,0), '1.0.0'), + array(Level::PATCH, $this->getMockedVersion(1,0,0), '1.0.1'), + array(Level::MINOR, $this->getMockedVersion(1,0,0), '1.1.0'), + array(Level::MAJOR, $this->getMockedVersion(1,0,0), '2.0.0'), + //v2.3.4 + array(Level::NONE, $this->getMockedVersion(2,3,4), '2.3.4'), + array(Level::PATCH, $this->getMockedVersion(2,3,4), '2.3.5'), + array(Level::MINOR, $this->getMockedVersion(2,3,4), '2.4.0'), + array(Level::MAJOR, $this->getMockedVersion(2,3,4), '3.0.0'), + ); + } + + /** + * @param $level + * @param \vierbergenlars\SemVer\version $version + * @param $expected + * @throws \ReflectionException + * @test + * @dataProvider provideGetNextTag + */ + public function testGetNextTag($level, version $version, $expected) + { + $report = $this->getMockBuilder('PHPSemVerChecker\Report\Report')->disableOriginalConstructor()->getMock(); + $report->expects($this->once())->method('getSuggestedLevel')->willReturn($level); + + $result = $this->getNextTagMethod()->invoke(new SuggestCommand(), $report, $version); + $this->assertInstanceOf('vierbergenlars\SemVer\version', $result); + $this->assertEquals($expected, $result->getVersion()); + } +} \ No newline at end of file