Skip to content

Commit

Permalink
Merge pull request #154 from matteosister/march-2019-patch
Browse files Browse the repository at this point in the history
March 2019 patch
  • Loading branch information
imunhatep authored Mar 25, 2019
2 parents 8353f84 + 1789eea commit 8ab2ebb
Show file tree
Hide file tree
Showing 37 changed files with 88 additions and 80 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ build/
cache/
deploy_docs.sh
.vscode/
composer.lock
composer.lock
.phpunit.result.cache
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: php

php:
- 7.1
- 7.2
- 7.3

before_script:
- curl -s https://getcomposer.org/installer | php
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"require-dev": {
"php": ">=7.1.0",
"phpunit/phpunit": "~7.0",
"phpunit/phpunit": "~8.0",
"mockery/mockery": "~1.1",
"symfony/var-dumper": "3.*|4.*"
},
Expand Down
4 changes: 2 additions & 2 deletions src/GitElephant/Command/Caller/AbstractCaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public function getBinaryVersion()
{
if (is_null($this->binaryVersion)) {
$version = $this->execute('--version')->getOutput();
if (!preg_match('/^git version [0-9\.]+$/', $version)) {
if (!preg_match('/^git version [0-9\.]+/', $version)) {
throw new \RuntimeException('Could not parse git version. Unexpected format "' . $version . '".');
}
$this->binaryVersion = preg_replace('/^git version ([0-9\.]+)$/', '$1', $version);
$this->binaryVersion = preg_replace('/^git version ([0-9\.]+)/', '$1', $version);
}

return $this->binaryVersion;
Expand Down
2 changes: 2 additions & 0 deletions src/GitElephant/Status/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Status
protected $files;

/**
* Private constructor in order to follow the singleton pattern
*
* @param Repository $repository
*
* @throws \RuntimeException
Expand Down
4 changes: 3 additions & 1 deletion src/GitElephant/Status/StatusFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ private function __construct(string $x, string $y, string $name, string $renamed
$this->y = ' ' === $y ? null : $y;
$this->name = $name;
$this->renamed = $renamed;
$this->calculateDescription();
}

/**
Expand Down Expand Up @@ -187,6 +186,9 @@ public function setDescription(string $description)
*/
public function getDescription()
{
if ($this->description === null) {
$this->calculateDescription();
}
return $this->description;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/BaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,6 @@ public function testGetBinaryVersion()
{
$repo = $this->getRepository();
$bc = BaseCommand::getInstance($repo);
$this->assertInternalType('string', $bc->getBinaryVersion());
$this->assertIsString($bc->getBinaryVersion());
}
}
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/BranchCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BranchCommandTest extends TestCase
/**
* setUp, called on every method
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$this->getRepository()->init();
Expand Down
10 changes: 6 additions & 4 deletions tests/GitElephant/Command/CallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CallerTest extends TestCase
/**
* setUp
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
}
Expand Down Expand Up @@ -56,14 +56,15 @@ public function testGetBinaryPath()
public function testGetBinaryVersion()
{
$c = new Caller(null, $this->repository->getPath());
$this->assertInternalType('string', $c->getBinaryVersion());
$this->assertIsString($c->getBinaryVersion());
}

/**
* @expectedException \RuntimeException
* testGetError
*/
public function testGetError()
{
$this->expectException(\RuntimeException::class);
$binary = null;
$caller = new Caller(null, $this->getRepository()->getPath());
$mainCommand = new MainCommand();
Expand Down Expand Up @@ -113,10 +114,11 @@ public function testGetRawOutput()
}

/**
* @expectedException \GitElephant\Exception\InvalidRepositoryPathException
* testRepositoryValidation
*/
public function testRepositoryValidation()
{
$this->expectException(\GitElephant\Exception\InvalidRepositoryPathException::class);
$caller = new Caller(null, 'someinvalidpath');
}
}
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/CatFileCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CatFileCommandTest extends TestCase
/**
* setUp, called on every method
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$this->getRepository()->init();
Expand Down
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/CloneCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CloneCommandTest extends TestCase
/**
* set up
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$this->binaryVersion = exec('git --version | cut -d " " -f 3');
Expand Down
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/DiffCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DiffCommandTest extends TestCase
/**
* set up
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$this->getRepository()->init();
Expand Down
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/DiffTreeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DiffTreeCommandTest extends TestCase
/**
* set up
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$this->getRepository()->init();
Expand Down
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/FetchCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FetchCommandTest extends TestCase
/**
* set up
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$this->getRepository()->init();
Expand Down
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/LogCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LogCommandTest extends TestCase
/**
* set up
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$this->getRepository()->init();
Expand Down
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/LsTreeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LsTreeCommandTest extends TestCase
/**
* setUp function
*/
public function setUp()
public function setUp(): void
{
$this->lsTreeCommand = new LsTreeCommand();
}
Expand Down
38 changes: 22 additions & 16 deletions tests/GitElephant/Command/MainCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Matteo Giachino <[email protected]>
*/

class MainCommandTest extends TestCase
{
/**
Expand All @@ -35,7 +35,7 @@ class MainCommandTest extends TestCase
/**
* setup
*/
public function setUp()
public function setUp(): void
{
$this->mainCommand = new MainCommand();
}
Expand All @@ -46,54 +46,60 @@ public function setUp()
public function testInit()
{
$this->assertEquals(MainCommand::GIT_INIT, $this->mainCommand->init());
$this->assertEquals(MainCommand::GIT_INIT." '--bare'", $this->mainCommand->init(true));
$this->assertEquals(MainCommand::GIT_INIT . " '--bare'", $this->mainCommand->init(true));
}

/**
* status test
*/
public function testStatus()
{
$this->assertEquals("'-c' 'color.status'='false' ".MainCommand::GIT_STATUS, $this->mainCommand->status());
$this->assertEquals("'-c' 'color.status'='false' " . MainCommand::GIT_STATUS, $this->mainCommand->status());
}

/**
* add test
*/
public function testAdd()
{
$this->assertEquals(MainCommand::GIT_ADD." '--all' '.'", $this->mainCommand->add());
$this->assertEquals(MainCommand::GIT_ADD." '--all' 'foo'", $this->mainCommand->add('foo'));
$this->assertEquals(MainCommand::GIT_ADD . " '--all' '.'", $this->mainCommand->add());
$this->assertEquals(MainCommand::GIT_ADD . " '--all' 'foo'", $this->mainCommand->add('foo'));
}

/**
* unstage test
*/
public function testUnstage()
{
$this->assertEquals(MainCommand::GIT_RESET." 'HEAD' -- 'foo'", $this->mainCommand->unstage('foo'));
$this->assertEquals(MainCommand::GIT_RESET . " 'HEAD' -- 'foo'", $this->mainCommand->unstage('foo'));
}

/**
* commit test
*/
public function testCommit()
{
$this->assertEquals(MainCommand::GIT_COMMIT." '-m' 'foo'", $this->mainCommand->commit('foo'));
$this->assertEquals(MainCommand::GIT_COMMIT." '-a' '-m' 'foo'", $this->mainCommand->commit('foo', true));
$this->assertEquals(MainCommand::GIT_COMMIT." '--author' 'example <[email protected]>' '-m' 'foo'",
$this->mainCommand->commit('foo', false, 'example <[email protected]>'));
$this->assertEquals(MainCommand::GIT_COMMIT." '-a' '--author' 'example <[email protected]>' '-m' 'foo'",
$this->mainCommand->commit('foo', true, 'example <[email protected]>'));
$this->assertEquals(MainCommand::GIT_COMMIT." '--author' 'example <[email protected]>' '--allow-empty' '-m' 'foo'",
$this->mainCommand->commit('foo', false, 'example <[email protected]>', true));
$this->assertEquals(MainCommand::GIT_COMMIT . " '-m' 'foo'", $this->mainCommand->commit('foo'));
$this->assertEquals(MainCommand::GIT_COMMIT . " '-a' '-m' 'foo'", $this->mainCommand->commit('foo', true));
$this->assertEquals(
MainCommand::GIT_COMMIT . " '--author' 'example <[email protected]>' '-m' 'foo'",
$this->mainCommand->commit('foo', false, 'example <[email protected]>')
);
$this->assertEquals(
MainCommand::GIT_COMMIT . " '-a' '--author' 'example <[email protected]>' '-m' 'foo'",
$this->mainCommand->commit('foo', true, 'example <[email protected]>')
);
$this->assertEquals(
MainCommand::GIT_COMMIT . " '--author' 'example <[email protected]>' '--allow-empty' '-m' 'foo'",
$this->mainCommand->commit('foo', false, 'example <[email protected]>', true)
);
}

/**
* checkout test
*/
public function testCheckout()
{
$this->assertEquals(MainCommand::GIT_CHECKOUT." '-q' 'master'", $this->mainCommand->checkout('master'));
$this->assertEquals(MainCommand::GIT_CHECKOUT . " '-q' 'master'", $this->mainCommand->checkout('master'));
}
}
5 changes: 2 additions & 3 deletions tests/GitElephant/Command/MergeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MergeCommandTest extends TestCase
/**
* setUp
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$this->getRepository()->init();
Expand All @@ -44,12 +44,11 @@ public function testMerge()

/**
* MergeCommand should throw an exception when both --ff-only and --no-ff flags were set.
*
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
*/
public function test_exception_when_calling_merge_with_conflicting_ff_arguments()
{
$branch = $this->getRepository()->getBranch('test');
$this->expectException(\Symfony\Component\Process\Exception\InvalidArgumentException::class);
MergeCommand::getInstance()->merge($branch, "test msg", array('--ff-only', '--no-ff'));
}
}
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/MvCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MvCommandTest extends TestCase
/**
* setUp
*/
public function setUp()
public function setUp(): void
{
$this->getRepository()->init();
$this->addFile('test');
Expand Down
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/PullCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PullCommandTest extends TestCase
/**
* set up
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$this->getRepository()->init();
Expand Down
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/PushCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PushCommandTest extends TestCase
/**
* set up
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$this->getRepository()->init();
Expand Down
2 changes: 1 addition & 1 deletion tests/GitElephant/Command/RemoteCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RemoteCommandTest extends TestCase
/**
* setUp
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$repo = $this->getRepository();
Expand Down
4 changes: 2 additions & 2 deletions tests/GitElephant/Command/ResetCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ResetCommandTest extends TestCase
/**
* setUp
*/
public function setUp()
public function setUp(): void
{
$this->initRepository();
$this->getRepository()->init();
Expand All @@ -28,6 +28,6 @@ public function setUp()
public function testResetHard()
{
$rstc = ResetCommand::getInstance();
$this->assertEquals("reset '--hard' 'dbeac'",$rstc->reset('dbeac',array(ResetCommand::OPTION_HARD)));
$this->assertEquals("reset '--hard' 'dbeac'", $rstc->reset('dbeac', array(ResetCommand::OPTION_HARD)));
}
}
5 changes: 2 additions & 3 deletions tests/GitElephant/Objects/BranchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,21 @@ public function testGetMatches()

/**
* testGetMatchesErrors
*
* @expectedException \InvalidArgumentException
*/
public function testGetMatchesShortShaError()
{
// short sha
$this->expectException(\InvalidArgumentException::class);
$matches = Branch::getMatches('* develop 45eac8c31adfbbf633824cee6ce8cc5040b3351 test message');
}

/**
* testGetMatchesErrors
*
* @expectedException \InvalidArgumentException
*/
public function testGetMatchesNoSpaceError()
{
$this->expectException(\InvalidArgumentException::class);
$matches = Branch::getMatches('* develop 45eac8c31adfbbf633824cee6ce8cc5040b33511test message');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/GitElephant/Objects/Commit/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MessageTest extends \PHPUnit\Framework\TestCase
*/
protected $msg;

protected function setUp()
protected function setUp(): void
{
$this->shortMsg = 'This is the short message';
$this->longMsg = <<<HDOC
Expand Down
Loading

0 comments on commit 8ab2ebb

Please sign in to comment.