From 1601d6e954fd9cdde369081f836f6b078657880a Mon Sep 17 00:00:00 2001 From: Niels Nijens Date: Sun, 15 May 2016 00:23:56 +0200 Subject: [PATCH 1/3] Remove PHP 5.4 from Travis CI configuration --- .travis.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 615d802..c9f21ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ sudo: false matrix: include: - - php: 5.4 - php: 5.5 - php: 5.6 - php: 7.0 @@ -13,14 +12,11 @@ matrix: - php: nightly fast_finish: true -before_install: - - composer self-update - - if [[ $TRAVIS_PHP_VERSION = 5.4 ]]; then composer update; fi; +before_install: composer self-update install: composer install -before_script: - - mkdir -p build/logs +before_script: mkdir -p build/logs script: vendor/bin/phpunit --coverage-clover build/logs/clover.xml From b0045dda1c848b1f95e20ca7e9aa6b8e2706276b Mon Sep 17 00:00:00 2001 From: Niels Nijens Date: Sun, 15 May 2016 00:24:49 +0200 Subject: [PATCH 2/3] Change PHP requirement to 5.5 in Composer configuration --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1482d5b..bcd0ec1 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php": "^5.4 || ^7.0", + "php": "^5.5 || ^7.0", "symfony/process": "^2.7 || ^3.0" }, "require-dev": { From 0583c20eabb56c0ea06bf01a90b3d4e320cb99b2 Mon Sep 17 00:00:00 2001 From: Niels Nijens Date: Sun, 15 May 2016 00:33:04 +0200 Subject: [PATCH 3/3] Replace class strings with class name constants --- src/Repository.php | 6 +- tests/Adapter/AbstractAdapterTest.php | 7 +- tests/Adapter/GitAdapterTest.php | 26 +-- tests/Adapter/SubversionAdapterTest.php | 214 +++++++++++++----------- tests/Process/ProcessExecutorTest.php | 3 +- tests/RepositoryTest.php | 87 ++++++---- 6 files changed, 196 insertions(+), 147 deletions(-) diff --git a/src/Repository.php b/src/Repository.php index 09236af..2231e89 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -3,6 +3,8 @@ namespace Accompli\Chrono; use Accompli\Chrono\Adapter\AdapterInterface; +use Accompli\Chrono\Adapter\GitAdapter; +use Accompli\Chrono\Adapter\SubversionAdapter; use Accompli\Chrono\Process\ProcessExecutorInterface; use InvalidArgumentException; @@ -40,8 +42,8 @@ class Repository implements RepositoryInterface * @var array */ private $adapters = array( - 'Accompli\Chrono\Adapter\GitAdapter', - 'Accompli\Chrono\Adapter\SubversionAdapter', + GitAdapter::class, + SubversionAdapter::class, ); /** diff --git a/tests/Adapter/AbstractAdapterTest.php b/tests/Adapter/AbstractAdapterTest.php index b542dcb..3e26d51 100644 --- a/tests/Adapter/AbstractAdapterTest.php +++ b/tests/Adapter/AbstractAdapterTest.php @@ -2,6 +2,8 @@ namespace Accompli\Chrono\Test; +use Accompli\Chrono\Adapter\AbstractAdapter; +use Accompli\Chrono\Process\ProcessExecutorInterface; use PHPUnit_Framework_TestCase; /** @@ -18,9 +20,10 @@ public function testConstruct() { $repositoryUrl = 'https://github.com/accompli/chrono.git'; $repositoryDirectory = __DIR__; - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); - $abstractAdapter = $this->getMockBuilder('Accompli\Chrono\Adapter\AbstractAdapter') + $abstractAdapter = $this->getMockBuilder(AbstractAdapter::class) ->setConstructorArgs(array($repositoryUrl, $repositoryDirectory, $processExecutorMock)) ->getMockForAbstractClass(); diff --git a/tests/Adapter/GitAdapterTest.php b/tests/Adapter/GitAdapterTest.php index c9c06c9..948fc76 100644 --- a/tests/Adapter/GitAdapterTest.php +++ b/tests/Adapter/GitAdapterTest.php @@ -85,7 +85,7 @@ public function provideTestSupportsRepository() { $provideTest = array(); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->once()) ->method('execute') @@ -93,7 +93,7 @@ public function provideTestSupportsRepository() ->willReturn(new ProcessExecutionResult(1, '', '')); $provideTest[] = array('https://github.com/accompli/chrono.git', $processExecutorMock, false); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->once()) ->method('execute') @@ -101,7 +101,7 @@ public function provideTestSupportsRepository() ->willReturn(new ProcessExecutionResult(0, '', '')); $provideTest[] = array('https://github.com/accompli/chrono.git', $processExecutorMock, true); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->once()) ->method('execute') @@ -109,7 +109,7 @@ public function provideTestSupportsRepository() ->willReturn(new ProcessExecutionResult(0, '', '')); $provideTest[] = array('git@github.com:accompli/chrono.git', $processExecutorMock, true); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->exactly(2)) ->method('execute') @@ -123,7 +123,7 @@ public function provideTestSupportsRepository() ); $provideTest[] = array('user@example.com:accompli/chrono', $processExecutorMock, true); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->exactly(2)) ->method('execute') @@ -151,7 +151,7 @@ public function provideTestGetBranches() $provideTest = array(); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->once()) ->method('execute') @@ -159,7 +159,7 @@ public function provideTestGetBranches() ->willReturn(new ProcessExecutionResult(1, '', '')); $provideTest[] = array($processExecutorMock, array()); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->once()) ->method('execute') @@ -181,7 +181,7 @@ public function provideTestGetTags() $provideTest = array(); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->once()) ->method('execute') @@ -189,7 +189,7 @@ public function provideTestGetTags() ->willReturn(new ProcessExecutionResult(1, '', '')); $provideTest[] = array($processExecutorMock, array()); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->once()) ->method('execute') @@ -212,7 +212,7 @@ public function provideTestCheckout() $provideTest = array(); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') @@ -223,7 +223,7 @@ public function provideTestCheckout() ->willReturn(new ProcessExecutionResult(1, '', '')); $provideTest[] = array($processExecutorMock, false); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') @@ -242,7 +242,7 @@ public function provideTestCheckout() ); $provideTest[] = array($processExecutorMock, false); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') @@ -253,7 +253,7 @@ public function provideTestCheckout() ->willReturn(new ProcessExecutionResult(0, '', '')); $provideTest[] = array($processExecutorMock, true); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface') + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') diff --git a/tests/Adapter/SubversionAdapterTest.php b/tests/Adapter/SubversionAdapterTest.php index 52a5132..ef3448e 100644 --- a/tests/Adapter/SubversionAdapterTest.php +++ b/tests/Adapter/SubversionAdapterTest.php @@ -88,50 +88,55 @@ public function provideTestSupportsRepository() $provideTest = array(); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('execute') ->with($this->equalTo('svn --version')) ->willReturn(new ProcessExecutionResult(1, '', '')); $provideTest[] = array('https://github.com/accompli/chrono.git', $processExecutorMock, false); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->exactly(2)) ->method('execute') ->withConsecutive( - array($this->equalTo('svn --version')), - array($this->equalTo(sprintf($infoCommand, ProcessUtils::escapeArgument('https://github.com/accompli/chrono.git')))) + array($this->equalTo('svn --version')), + array($this->equalTo(sprintf($infoCommand, ProcessUtils::escapeArgument('https://github.com/accompli/chrono.git')))) ) ->willReturn(new ProcessExecutionResult(0, '', '')); $provideTest[] = array('https://github.com/accompli/chrono.git', $processExecutorMock, true); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->exactly(2)) ->method('execute') ->withConsecutive( - array($this->equalTo('svn --version')), - array($this->equalTo(sprintf($infoCommand, ProcessUtils::escapeArgument('git@github.com:accompli/chrono.git')))) + array($this->equalTo('svn --version')), + array($this->equalTo(sprintf($infoCommand, ProcessUtils::escapeArgument('git@github.com:accompli/chrono.git')))) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(0, '', ''), - new ProcessExecutionResult(1, '', '') + new ProcessExecutionResult(0, '', ''), + new ProcessExecutionResult(1, '', '') ); $provideTest[] = array('git@github.com:accompli/chrono.git', $processExecutorMock, false); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->exactly(2)) ->method('execute') ->withConsecutive( - array($this->equalTo('svn --version')), - array($this->equalTo(sprintf($infoCommand, ProcessUtils::escapeArgument('user@example.com:accompli/chrono')))) + array($this->equalTo('svn --version')), + array($this->equalTo(sprintf($infoCommand, ProcessUtils::escapeArgument('user@example.com:accompli/chrono')))) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(0, '', ''), - new ProcessExecutionResult(1, '', '') + new ProcessExecutionResult(0, '', ''), + new ProcessExecutionResult(1, '', '') ); $provideTest[] = array('user@example.com:accompli/chrono', $processExecutorMock, false); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('execute') ->with($this->equalTo('svn --version')) @@ -153,39 +158,42 @@ public function provideTestGetBranches() $provideTest = array(); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->exactly(2)) ->method('execute') ->withConsecutive( - array($this->equalTo($trunkCommand)), - array($this->equalTo($branchesCommand)) + array($this->equalTo($trunkCommand)), + array($this->equalTo($branchesCommand)) ) ->willReturn(new ProcessExecutionResult(1, '', '')); $provideTest[] = array($processExecutorMock, array()); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->exactly(2)) ->method('execute') ->withConsecutive( - array($this->equalTo($trunkCommand)), - array($this->equalTo($branchesCommand)) + array($this->equalTo($trunkCommand)), + array($this->equalTo($branchesCommand)) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(1, '', ''), - new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", '') + new ProcessExecutionResult(1, '', ''), + new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", '') ); $provideTest[] = array($processExecutorMock, array('35' => '1.0')); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->exactly(2)) ->method('execute') ->withConsecutive( - array($this->equalTo($trunkCommand)), - array($this->equalTo($branchesCommand)) + array($this->equalTo($trunkCommand)), + array($this->equalTo($branchesCommand)) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), - new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", '') + new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), + new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", '') ); $provideTest[] = array($processExecutorMock, array('34' => 'master', '35' => '1.0')); @@ -203,14 +211,16 @@ public function provideTestGetTags() $provideTest = array(); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('execute') ->with($this->equalTo($tagsCommand)) ->willReturn(new ProcessExecutionResult(1, '', '')); $provideTest[] = array($processExecutorMock, array()); - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('execute') ->with($this->equalTo($tagsCommand)) @@ -239,166 +249,174 @@ public function provideTestCheckout() $provideTest = array(); // directory false, no branches, no tags - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') ->willReturn(false); $processExecutorMock->expects($this->exactly(3)) ->method('execute') ->withConsecutive( - array($this->equalTo($getTrunkCommand)), - array($this->equalTo($getBranchesCommand)), - array($this->equalTo($getTagsCommand)) + array($this->equalTo($getTrunkCommand)), + array($this->equalTo($getBranchesCommand)), + array($this->equalTo($getTagsCommand)) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(1, '', ''), - new ProcessExecutionResult(1, '', ''), - new ProcessExecutionResult(1, '', '') + new ProcessExecutionResult(1, '', ''), + new ProcessExecutionResult(1, '', ''), + new ProcessExecutionResult(1, '', '') ); $provideTest[] = array($processExecutorMock, false); // directory false, branches, tags, checkout failed - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') ->willReturn(false); $processExecutorMock->expects($this->exactly(4)) ->method('execute') ->withConsecutive( - array($this->equalTo($getTrunkCommand)), - array($this->equalTo($getBranchesCommand)), - array($this->equalTo($getTagsCommand)), - array($this->equalTo($checkoutCommand)) + array($this->equalTo($getTrunkCommand)), + array($this->equalTo($getBranchesCommand)), + array($this->equalTo($getTagsCommand)), + array($this->equalTo($checkoutCommand)) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), - new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''), - new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''), - new ProcessExecutionResult(1, '', '') + new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), + new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''), + new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''), + new ProcessExecutionResult(1, '', '') ); $provideTest[] = array($processExecutorMock, false); // directory false, branches, tags, checkout success - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') ->willReturn(false); $processExecutorMock->expects($this->exactly(4)) ->method('execute') ->withConsecutive( - array($this->equalTo($getTrunkCommand)), - array($this->equalTo($getBranchesCommand)), - array($this->equalTo($getTagsCommand)), - array($this->equalTo($checkoutCommand)) + array($this->equalTo($getTrunkCommand)), + array($this->equalTo($getBranchesCommand)), + array($this->equalTo($getTagsCommand)), + array($this->equalTo($checkoutCommand)) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), - new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''), - new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''), - new ProcessExecutionResult(0, '', '') + new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), + new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''), + new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''), + new ProcessExecutionResult(0, '', '') ); $provideTest[] = array($processExecutorMock, true); // directory true, no branches, no tags - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') ->willReturn(true); $processExecutorMock->expects($this->exactly(3)) ->method('execute') ->withConsecutive( - array($this->equalTo($getTrunkCommand)), - array($this->equalTo($getBranchesCommand)), - array($this->equalTo($getTagsCommand)) + array($this->equalTo($getTrunkCommand)), + array($this->equalTo($getBranchesCommand)), + array($this->equalTo($getTagsCommand)) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(1, '', ''), - new ProcessExecutionResult(1, '', ''), - new ProcessExecutionResult(1, '', '') + new ProcessExecutionResult(1, '', ''), + new ProcessExecutionResult(1, '', ''), + new ProcessExecutionResult(1, '', '') ); $provideTest[] = array($processExecutorMock, false); // directory true, branches, tags, switch failed - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') ->willReturn(true); $processExecutorMock->expects($this->exactly(5)) ->method('execute') ->withConsecutive( - array($this->equalTo($getTrunkCommand)), - array($this->equalTo($getBranchesCommand)), - array($this->equalTo($getTagsCommand)), - array($this->equalTo($infoCommand)), - array($this->equalTo($tagSwitchCommand)) + array($this->equalTo($getTrunkCommand)), + array($this->equalTo($getBranchesCommand)), + array($this->equalTo($getTagsCommand)), + array($this->equalTo($infoCommand)), + array($this->equalTo($tagSwitchCommand)) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), - new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''), - new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''), - new ProcessExecutionResult(0, '', ''), - new ProcessExecutionResult(1, '', '') + new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), + new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''), + new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''), + new ProcessExecutionResult(0, '', ''), + new ProcessExecutionResult(1, '', '') ); $provideTest[] = array($processExecutorMock, false); // directory true, branches, tags, switch success - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') ->willReturn(true); $processExecutorMock->expects($this->exactly(5)) ->method('execute') ->withConsecutive( - array($this->equalTo($getTrunkCommand)), - array($this->equalTo($getBranchesCommand)), - array($this->equalTo($getTagsCommand)), - array($this->equalTo($infoCommand)), - array($this->equalTo($tagSwitchCommand)) + array($this->equalTo($getTrunkCommand)), + array($this->equalTo($getBranchesCommand)), + array($this->equalTo($getTagsCommand)), + array($this->equalTo($infoCommand)), + array($this->equalTo($tagSwitchCommand)) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), - new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''), - new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''), - new ProcessExecutionResult(0, '', ''), - new ProcessExecutionResult(0, '', '') + new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), + new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''), + new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 0.1.0\n", ''), + new ProcessExecutionResult(0, '', ''), + new ProcessExecutionResult(0, '', '') ); $provideTest[] = array($processExecutorMock, true); // directory true, branches, tags, switch to 'master' - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') ->willReturn(true); $processExecutorMock->expects($this->exactly(3)) ->method('execute') ->withConsecutive( - array($this->equalTo($infoCommand)), - array($this->equalTo($trunkSwitchCommand)) + array($this->equalTo($infoCommand)), + array($this->equalTo($trunkSwitchCommand)) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(0, '', ''), - new ProcessExecutionResult(0, '', '') + new ProcessExecutionResult(0, '', ''), + new ProcessExecutionResult(0, '', '') ); $provideTest[] = array($processExecutorMock, true, 'master'); // directory true, branches, switch to '1.0' - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $processExecutorMock->expects($this->once()) ->method('isDirectory') ->willReturn(true); $processExecutorMock->expects($this->exactly(4)) ->method('execute') ->withConsecutive( - array($this->equalTo($getTrunkCommand)), - array($this->equalTo($getBranchesCommand)), - array($this->equalTo($infoCommand)), - array($this->equalTo($branchSwitchCommand)) + array($this->equalTo($getTrunkCommand)), + array($this->equalTo($getBranchesCommand)), + array($this->equalTo($infoCommand)), + array($this->equalTo($branchSwitchCommand)) ) ->willReturnOnConsecutiveCalls( - new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), - new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''), - new ProcessExecutionResult(0, '', ''), - new ProcessExecutionResult(0, '', '') + new ProcessExecutionResult(0, " 34 niels.ni nov 22 22:10 ./\n 34 niels.ni nov 22 22:10 file\n", ''), + new ProcessExecutionResult(0, " 35 niels.ni nov 22 22:10 ./\n 35 niels.ni nov 22 22:10 1.0\n", ''), + new ProcessExecutionResult(0, '', ''), + new ProcessExecutionResult(0, '', '') ); $provideTest[] = array($processExecutorMock, true, '1.0'); diff --git a/tests/Process/ProcessExecutorTest.php b/tests/Process/ProcessExecutorTest.php index 401ab62..91f9999 100644 --- a/tests/Process/ProcessExecutorTest.php +++ b/tests/Process/ProcessExecutorTest.php @@ -2,6 +2,7 @@ namespace Accompli\Chrono\Test; +use Accompli\Chrono\Process\ProcessExecutionResult; use Accompli\Chrono\Process\ProcessExecutor; use PHPUnit_Framework_TestCase; @@ -60,7 +61,7 @@ public function testExecute() $processExecutor = new ProcessExecutor(); $processExecutionResult = $processExecutor->execute('echo test'); - $this->assertInstanceOf('Accompli\Chrono\Process\ProcessExecutionResult', $processExecutionResult); + $this->assertInstanceOf(ProcessExecutionResult::class, $processExecutionResult); $this->assertSame(0, $processExecutionResult->getExitCode()); $this->assertSame('test'.PHP_EOL, $processExecutionResult->getOutput()); $this->assertEquals('', $processExecutionResult->getErrorOutput()); diff --git a/tests/RepositoryTest.php b/tests/RepositoryTest.php index 61bb24c..d6d4ef3 100644 --- a/tests/RepositoryTest.php +++ b/tests/RepositoryTest.php @@ -2,7 +2,12 @@ namespace Accompli\Chrono\Test; +use Accompli\Chrono\Adapter\AdapterInterface; +use Accompli\Chrono\Process\ProcessExecutor; +use Accompli\Chrono\Process\ProcessExecutorInterface; use Accompli\Chrono\Repository; +use Accompli\Chrono\Test\Adapter\AdapterMock; +use InvalidArgumentException; use PHPUnit_Framework_TestCase; /** @@ -19,7 +24,7 @@ public function testConstruct() { $repositoryUrl = 'https://github.com/accompli/chrono.git'; $repositoryDirectory = __DIR__; - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class)->getMock(); $repository = new Repository($repositoryUrl, $repositoryDirectory, $processExecutorMock); @@ -35,12 +40,12 @@ public function testSetAdapters() { $repositoryUrl = 'https://github.com/accompli/chrono.git'; $repositoryDirectory = __DIR__; - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class)->getMock(); $repository = new Repository($repositoryUrl, $repositoryDirectory, $processExecutorMock); - $repository->setAdapters(array('Accompli\Chrono\Test\Adapter\AdapterMock')); + $repository->setAdapters(array(AdapterMock::class)); - $this->assertAttributeSame(array('Accompli\Chrono\Test\Adapter\AdapterMock'), 'adapters', $repository); + $this->assertAttributeSame(array(AdapterMock::class), 'adapters', $repository); } /** @@ -50,12 +55,12 @@ public function testGetAdapter() { $repositoryUrl = 'https://github.com/accompli/chrono.git'; $repositoryDirectory = __DIR__; - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class)->getMock(); $repository = new Repository($repositoryUrl, $repositoryDirectory, $processExecutorMock); - $repository->setAdapters(array('Accompli\Chrono\Test\Adapter\AdapterMock')); + $repository->setAdapters(array(AdapterMock::class)); - $this->assertInstanceOf('Accompli\Chrono\Test\Adapter\AdapterMock', $repository->getAdapter()); + $this->assertInstanceOf(AdapterMock::class, $repository->getAdapter()); } /** @@ -65,7 +70,7 @@ public function testGetAdapterReturnsNullWhenClassDoesNotExist() { $repositoryUrl = 'https://github.com/accompli/chrono.git'; $repositoryDirectory = __DIR__; - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class)->getMock(); $repository = new Repository($repositoryUrl, $repositoryDirectory, $processExecutorMock); $repository->setAdapters(array('DoesNotExistAdapter')); @@ -80,10 +85,10 @@ public function testGetAdapterReturnsNullWhenClassIsNoAdapter() { $repositoryUrl = 'https://github.com/accompli/chrono.git'; $repositoryDirectory = __DIR__; - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class)->getMock(); $repository = new Repository($repositoryUrl, $repositoryDirectory, $processExecutorMock); - $repository->setAdapters(array('Accompli\Chrono\Process\ProcessExecutor')); + $repository->setAdapters(array(ProcessExecutor::class)); $this->assertNull($repository->getAdapter()); } @@ -95,17 +100,23 @@ public function testGetBranches() { $repositoryUrl = 'https://github.com/accompli/chrono.git'; $repositoryDirectory = __DIR__; - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); - $adapterMock = $this->getMockBuilder('Accompli\Chrono\Adapter\AdapterInterface')->getMock(); - $adapterMock->expects($this->once())->method('getBranches')->willReturn(array()); + $adapterMock = $this->getMockBuilder(AdapterInterface::class) + ->getMock(); + $adapterMock->expects($this->once()) + ->method('getBranches') + ->willReturn(array()); - $repository = $this->getMockBuilder('Accompli\Chrono\Repository') + $repository = $this->getMockBuilder(Repository::class) ->setConstructorArgs(array($repositoryUrl, $repositoryDirectory, $processExecutorMock)) ->setMethods(array('getAdapter')) ->getMock(); - $repository->expects($this->once())->method('getAdapter')->willReturn($adapterMock); + $repository->expects($this->once()) + ->method('getAdapter') + ->willReturn($adapterMock); $this->assertInternalType('array', $repository->getBranches()); } @@ -117,17 +128,23 @@ public function testGetTags() { $repositoryUrl = 'https://github.com/accompli/chrono.git'; $repositoryDirectory = __DIR__; - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); - $adapterMock = $this->getMockBuilder('Accompli\Chrono\Adapter\AdapterInterface')->getMock(); - $adapterMock->expects($this->once())->method('getTags')->willReturn(array()); + $adapterMock = $this->getMockBuilder(AdapterInterface::class) + ->getMock(); + $adapterMock->expects($this->once()) + ->method('getTags') + ->willReturn(array()); - $repository = $this->getMockBuilder('Accompli\Chrono\Repository') + $repository = $this->getMockBuilder(Repository::class) ->setConstructorArgs(array($repositoryUrl, $repositoryDirectory, $processExecutorMock)) ->setMethods(array('getAdapter')) ->getMock(); - $repository->expects($this->once())->method('getAdapter')->willReturn($adapterMock); + $repository->expects($this->once()) + ->method('getAdapter') + ->willReturn($adapterMock); $this->assertInternalType('array', $repository->getTags()); } @@ -139,17 +156,24 @@ public function testCheckout() { $repositoryUrl = 'https://github.com/accompli/chrono.git'; $repositoryDirectory = __DIR__; - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); - $adapterMock = $this->getMockBuilder('Accompli\Chrono\Adapter\AdapterInterface')->getMock(); - $adapterMock->expects($this->once())->method('checkout')->with($this->equalTo('1.0.0'))->willReturn(array()); + $adapterMock = $this->getMockBuilder(AdapterInterface::class) + ->getMock(); + $adapterMock->expects($this->once()) + ->method('checkout') + ->with($this->equalTo('1.0.0')) + ->willReturn(array()); - $repository = $this->getMockBuilder('Accompli\Chrono\Repository') + $repository = $this->getMockBuilder(Repository::class) ->setConstructorArgs(array($repositoryUrl, $repositoryDirectory, $processExecutorMock)) ->setMethods(array('getAdapter')) ->getMock(); - $repository->expects($this->once())->method('getAdapter')->willReturn($adapterMock); + $repository->expects($this->once()) + ->method('getAdapter') + ->willReturn($adapterMock); $repository->checkout('1.0.0'); } @@ -161,10 +185,11 @@ public function testGetAdapterAlwaysReturnsSameInstanceAfterInitialize() { $repositoryUrl = 'https://github.com/accompli/chrono.git'; $repositoryDirectory = __DIR__; - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $repository = new Repository($repositoryUrl, $repositoryDirectory, $processExecutorMock); - $repository->setAdapters(array('Accompli\Chrono\Test\Adapter\AdapterMock')); + $repository->setAdapters(array(AdapterMock::class)); $repository->getTags(); $adapter = $repository->getAdapter(); @@ -173,19 +198,19 @@ public function testGetAdapterAlwaysReturnsSameInstanceAfterInitialize() /** * Tests if Repository::initialize throws an InvalidArgumentException when no supported adapter is available. - * - * @expectedException InvalidArgumentException - * @expectedExceptionMessage No adapter found to handle VCS repository "https://github.com/accompli/chrono.git". */ public function testInitializeThrowsInvalidArgumentExceptionWhenNoSupportedAdapterAvailable() { $repositoryUrl = 'https://github.com/accompli/chrono.git'; $repositoryDirectory = __DIR__; - $processExecutorMock = $this->getMockBuilder('Accompli\Chrono\Process\ProcessExecutorInterface')->getMock(); + $processExecutorMock = $this->getMockBuilder(ProcessExecutorInterface::class) + ->getMock(); $repository = new Repository($repositoryUrl, $repositoryDirectory, $processExecutorMock); $repository->setAdapters(array()); + $this->setExpectedException(InvalidArgumentException::class, 'No adapter found to handle VCS repository "https://github.com/accompli/chrono.git".'); + $repository->getTags(); } }