updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -9,6 +9,7 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Admin;
@@ -17,8 +18,9 @@ use PHPUnit\Framework\TestCase;
abstract class AbstractTest extends TestCase
{
const REPOSITORY_URL = 'http://github.com/gitonomy/foobar.git';
const REPOSITORY_URL = 'https://github.com/gitonomy/foobar.git';
const NO_MESSAGE_COMMIT = '011cd0c1625190d2959ee9a8f9f822006d94b661';
const LONGFILE_COMMIT = '4f17752acc9b7c54ba679291bf24cb7d354f0f4f';
const BEFORE_LONGFILE_COMMIT = 'e0ec50e2af75fa35485513f60b2e658e245227e9';
const LONGMESSAGE_COMMIT = '3febd664b6886344a9b32d70657687ea4b1b4fab';
@@ -51,10 +53,10 @@ abstract class AbstractTest extends TestCase
*/
public static function provideFoobar()
{
return array(
array(self::createFoobarRepository()),
array(self::createFoobarRepository(false)),
);
return [
[self::createFoobarRepository()],
[self::createFoobarRepository(false)],
];
}
/**
@@ -62,10 +64,10 @@ abstract class AbstractTest extends TestCase
*/
public static function provideEmpty()
{
return array(
array(self::createEmptyRepository()),
array(self::createEmptyRepository(false)),
);
return [
[self::createEmptyRepository()],
[self::createEmptyRepository(false)],
];
}
/**
@@ -93,7 +95,7 @@ abstract class AbstractTest extends TestCase
} else {
$dir = $repository->getGitDir();
}
AbstractTest::deleteDir($dir);
self::deleteDir($dir);
});
}
@@ -116,7 +118,7 @@ abstract class AbstractTest extends TestCase
*
* @param string $dir directory to delete
*/
public static function deleteDir($dir)
protected static function deleteDir($dir)
{
$iterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS);
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST);
@@ -138,12 +140,12 @@ abstract class AbstractTest extends TestCase
protected static function getOptions()
{
$command = isset($_SERVER['GIT_COMMAND']) ? $_SERVER['GIT_COMMAND'] : 'git';
$envs = isset($_SERVER['GIT_ENVS']) ? (array) $_SERVER['GIT_ENVS'] : array();
$envs = isset($_SERVER['GIT_ENVS']) ? (array) $_SERVER['GIT_ENVS'] : [];
return array(
'command' => $command,
return [
'command' => $command,
'environment_variables' => $envs,
'process_timeout' => 60,
);
'process_timeout' => 60,
];
}
}

View File

@@ -9,9 +9,11 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Admin;
use Gitonomy\Git\Exception\RuntimeException;
use Gitonomy\Git\Reference\Branch;
use Gitonomy\Git\Repository;
@@ -19,14 +21,20 @@ class AdminTest extends AbstractTest
{
private $tmpDir;
public function setUp()
/**
* @before
*/
public function setUpTmpDir()
{
$this->tmpDir = self::createTempDir();
}
public function tearDown()
/**
* @after
*/
public function tearDownTmpDir()
{
$this->deleteDir(self::createTempDir());
self::deleteDir(self::createTempDir());
}
public function testBare()
@@ -36,8 +44,8 @@ class AdminTest extends AbstractTest
$objectDir = $this->tmpDir.'/objects';
$this->assertTrue($repository->isBare(), 'Repository is bare');
$this->assertTrue(is_dir($objectDir), 'objects/ folder is present');
$this->assertTrue($repository instanceof Repository, 'Admin::init returns a repository');
$this->assertDirectoryExists($objectDir, 'objects/ folder is present');
$this->assertInstanceOf(Repository::class, $repository, 'Admin::init returns a repository');
$this->assertEquals($this->tmpDir, $repository->getGitDir(), 'The folder passed as argument is git dir');
$this->assertNull($repository->getWorkingDir(), 'No working dir in bare repository');
}
@@ -49,8 +57,8 @@ class AdminTest extends AbstractTest
$objectDir = $this->tmpDir.'/.git/objects';
$this->assertFalse($repository->isBare(), 'Repository is not bare');
$this->assertTrue(is_dir($objectDir), 'objects/ folder is present');
$this->assertTrue($repository instanceof Repository, 'Admin::init returns a repository');
$this->assertDirectoryExists($objectDir, 'objects/ folder is present');
$this->assertInstanceOf(Repository::class, $repository, 'Admin::init returns a repository');
$this->assertEquals($this->tmpDir.'/.git', $repository->getGitDir(), 'git dir as subfolder of argument');
$this->assertEquals($this->tmpDir, $repository->getWorkingDir(), 'working dir present in bare repository');
}
@@ -66,12 +74,12 @@ class AdminTest extends AbstractTest
$newRefs = array_keys($new->getReferences()->getAll());
$this->assertTrue(in_array('refs/heads/master', $newRefs));
$this->assertTrue(in_array('refs/tags/0.1', $newRefs));
$this->assertContains('refs/heads/master', $newRefs);
$this->assertContains('refs/tags/0.1', $newRefs);
if ($repository->isBare()) {
$this->assertEquals($newDir, $new->getGitDir());
$this->assertTrue(in_array('refs/heads/new-feature', $newRefs));
$this->assertContains('refs/heads/new-feature', $newRefs);
} else {
$this->assertEquals($newDir.'/.git', $new->getGitDir());
$this->assertEquals($newDir, $new->getWorkingDir());
@@ -89,7 +97,7 @@ class AdminTest extends AbstractTest
self::registerDeletion($new);
$head = $new->getHead();
$this->assertTrue($head instanceof Branch, 'HEAD is a branch');
$this->assertInstanceOf(Branch::class, $head, 'HEAD is a branch');
$this->assertEquals('new-feature', $head->getName(), 'HEAD is branch new-feature');
}
@@ -104,7 +112,7 @@ class AdminTest extends AbstractTest
self::registerDeletion($new);
$head = $new->getHead();
$this->assertTrue($head instanceof Branch, 'HEAD is a branch');
$this->assertInstanceOf(Branch::class, $head, 'HEAD is a branch');
$this->assertEquals('new-feature', $head->getName(), 'HEAD is branch new-feature');
}
@@ -119,14 +127,14 @@ class AdminTest extends AbstractTest
$newRefs = array_keys($new->getReferences()->getAll());
$this->assertTrue(in_array('refs/heads/master', $newRefs));
$this->assertTrue(in_array('refs/tags/0.1', $newRefs));
$this->assertContains('refs/heads/master', $newRefs);
$this->assertContains('refs/tags/0.1', $newRefs);
$this->assertEquals($newDir, $new->getGitDir());
if ($repository->isBare()) {
$this->assertTrue(in_array('refs/heads/new-feature', $newRefs));
$this->assertContains('refs/heads/new-feature', $newRefs);
} else {
$this->assertTrue(in_array('refs/remotes/origin/new-feature', $newRefs));
$this->assertContains('refs/remotes/origin/new-feature', $newRefs);
}
}
@@ -147,11 +155,10 @@ class AdminTest extends AbstractTest
$this->assertFalse(Admin::isValidRepository($url));
}
/**
* @expectedException RuntimeException
*/
public function testExistingFile()
{
$this->expectException(RuntimeException::class);
$file = $this->tmpDir.'/test';
touch($file);
@@ -161,15 +168,15 @@ class AdminTest extends AbstractTest
public function testCloneRepository()
{
$newDir = self::createTempDir();
$args = array();
$args = [];
$new = Admin::cloneRepository($newDir, self::REPOSITORY_URL, $args, self::getOptions());
self::registerDeletion($new);
$newRefs = array_keys($new->getReferences()->getAll());
$this->assertTrue(in_array('refs/heads/master', $newRefs));
$this->assertTrue(in_array('refs/tags/0.1', $newRefs));
$this->assertContains('refs/heads/master', $newRefs);
$this->assertContains('refs/tags/0.1', $newRefs);
$this->assertEquals($newDir.'/.git', $new->getGitDir());
$this->assertEquals($newDir, $new->getWorkingDir());

View File

@@ -9,6 +9,7 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
class BlameTest extends AbstractTest

View File

@@ -9,8 +9,11 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Exception\RuntimeException;
class BlobTest extends AbstractTest
{
const README_FRAGMENT = 'Foo Bar project';
@@ -27,15 +30,20 @@ class BlobTest extends AbstractTest
{
$blob = $this->getReadmeBlob($repository);
$this->assertContains(self::README_FRAGMENT, $blob->getContent());
if (method_exists($this, 'assertStringContainsString')) {
$this->assertStringContainsString(self::README_FRAGMENT, $blob->getContent());
} else {
$this->assertContains(self::README_FRAGMENT, $blob->getContent());
}
}
/**
* @dataProvider provideFoobar
* @expectedException RuntimeException
*/
public function testNotExisting($repository)
{
$this->expectException(RuntimeException::class);
$blob = $repository->getBlob('foobar');
$blob->getContent();
}
@@ -46,7 +54,12 @@ class BlobTest extends AbstractTest
public function testGetMimetype($repository)
{
$blob = $this->getReadmeBlob($repository);
$this->assertRegexp('#text/plain#', $blob->getMimetype());
if (method_exists($this, 'assertMatchesRegularExpression')) {
$this->assertMatchesRegularExpression('#text/plain#', $blob->getMimetype());
} else {
$this->assertRegExp('#text/plain#', $blob->getMimetype());
}
}
/**

View File

@@ -9,10 +9,15 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Commit;
use Gitonomy\Git\Diff\Diff;
use Gitonomy\Git\Exception\InvalidArgumentException;
use Gitonomy\Git\Exception\ReferenceNotFoundException;
use Gitonomy\Git\Repository;
use Gitonomy\Git\Tree;
class CommitTest extends AbstractTest
{
@@ -25,7 +30,7 @@ class CommitTest extends AbstractTest
$diff = $commit->getDiff();
$this->assertTrue($diff instanceof Diff, 'getDiff() returns a Diff object');
$this->assertInstanceOf(Diff::class, $diff, 'getDiff() returns a Diff object');
}
/**
@@ -40,13 +45,13 @@ class CommitTest extends AbstractTest
/**
* @dataProvider provideFoobar
*
* @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException
* @expectedExceptionMessage Reference not found: "that-hash-doest-not-exists"
*/
public function testInvalideHashThrowException($repository)
{
$commit = new Commit($repository, 'that-hash-doest-not-exists');
$this->expectException(ReferenceNotFoundException::class);
$this->expectExceptionMessage('Reference not found: "that-hash-doest-not-exists"');
new Commit($repository, 'that-hash-doest-not-exists');
}
/**
@@ -66,7 +71,7 @@ class CommitTest extends AbstractTest
{
$commit = $repository->getCommit(self::INITIAL_COMMIT);
$this->assertEquals(0, count($commit->getParentHashes()), 'No parent on initial commit');
$this->assertCount(0, $commit->getParentHashes(), 'No parent on initial commit');
}
/**
@@ -77,7 +82,7 @@ class CommitTest extends AbstractTest
$commit = $repository->getCommit(self::LONGFILE_COMMIT);
$parents = $commit->getParentHashes();
$this->assertEquals(1, count($parents), 'One parent found');
$this->assertCount(1, $parents, 'One parent found');
$this->assertEquals(self::BEFORE_LONGFILE_COMMIT, $parents[0], 'Parent hash is correct');
}
@@ -89,8 +94,8 @@ class CommitTest extends AbstractTest
$commit = $repository->getCommit(self::LONGFILE_COMMIT);
$parents = $commit->getParents();
$this->assertEquals(1, count($parents), 'One parent found');
$this->assertTrue($parents[0] instanceof Commit, 'First parent is a Commit object');
$this->assertCount(1, $parents, 'One parent found');
$this->assertInstanceOf(Commit::class, $parents[0], 'First parent is a Commit object');
$this->assertEquals(self::BEFORE_LONGFILE_COMMIT, $parents[0]->getHash(), "First parents's hash is correct");
}
@@ -111,7 +116,7 @@ class CommitTest extends AbstractTest
{
$commit = $repository->getCommit(self::LONGFILE_COMMIT);
$this->assertInstanceOf('Gitonomy\Git\Tree', $commit->getTree(), 'Tree is a tree');
$this->assertInstanceOf(Tree::class, $commit->getTree(), 'Tree is a tree');
$this->assertEquals('b06890c7b10904979d2f69613c2ccda30aafe262', $commit->getTree()->getHash(), 'Tree hash is correct');
}
@@ -185,6 +190,31 @@ class CommitTest extends AbstractTest
$this->assertEquals('add a long file'."\n", $commit->getMessage());
}
/**
* @dataProvider provideFoobar
*
* @param $repository Repository
*/
public function testGetEmptyMessage($repository)
{
$commit = $repository->getCommit(self::NO_MESSAGE_COMMIT);
$this->assertEquals('', $commit->getMessage());
}
/**
* @dataProvider provideFoobar
*
* @param $repository Repository
*/
public function testGetEmptyMessageFromLog($repository)
{
$commit = $repository->getCommit(self::NO_MESSAGE_COMMIT);
$commitMessageFromLog = $commit->getLog()->getCommits()[0]->getMessage();
$this->assertEquals('', $commitMessageFromLog);
}
/**
* This test ensures that GPG signed commits does not break the reading of a commit
* message.
@@ -223,14 +253,8 @@ class CommitTest extends AbstractTest
public function testGetBodyMessage($repository)
{
$commit = $repository->getCommit(self::LONGMESSAGE_COMMIT);
$message = <<<EOL
If you want to know everything,
I ran something like `chmox +x test.sh`
Hello and good bye.
EOL;
$nl = chr(10);
$message = "If you want to know everything,{$nl}I ran something like `chmox +x test.sh`{$nl}{$nl}Hello and good bye.{$nl}";
$this->assertEquals($message, $commit->getBodyMessage());
$commit = $repository->getCommit(self::INITIAL_COMMIT);
@@ -239,11 +263,12 @@ EOL;
}
/**
* @expectedException InvalidArgumentException
* @dataProvider provideFoobar
*/
public function testGetIncludingBranchesException($repository)
{
$this->expectException(InvalidArgumentException::class);
$commit = $repository->getCommit(self::INITIAL_COMMIT);
$commit->getIncludingBranches(false, false);

View File

@@ -9,6 +9,7 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Diff\Diff;
@@ -19,6 +20,7 @@ class DiffTest extends AbstractTest
const CREATE_COMMIT = 'e6fa3c792facc06faa049a6938c84c411954deb5';
const RENAME_COMMIT = '6640e0ef31518054847a1876328e26ee64083e0a';
const CHANGEMODE_COMMIT = '93da965f58170f13017477b9a608657e87e23230';
const FILE_WITH_UMLAUTS_COMMIT = '8defb9217692dc1f4c18e05e343ca91cf5047702';
/**
* @dataProvider provideFoobar
@@ -44,17 +46,17 @@ class DiffTest extends AbstractTest
{
$files = $diff->getFiles();
$this->assertEquals(2, count($files), '1 file in diff');
$this->assertCount(2, $files, '1 file in diff');
$this->assertTrue($files[0]->isCreation(), 'script_A.php created');
$this->assertEquals(null, $files[0]->getOldName(), 'First file name is a new file');
$this->assertEquals(null, $files[0]->getOldName(), 'First file name is a new file');
$this->assertEquals('script_A.php', $files[0]->getNewName(), 'First file name is script_A.php');
$this->assertEquals(null, $files[0]->getOldMode(), 'First file mode is a new file');
$this->assertEquals('100644', $files[0]->getNewMode(), 'First file mode is correct');
$this->assertEquals(null, $files[0]->getOldMode(), 'First file mode is a new file');
$this->assertEquals('100644', $files[0]->getNewMode(), 'First file mode is correct');
$this->assertEquals(1, $files[0]->getAdditions(), '1 line added');
$this->assertEquals(0, $files[0]->getDeletions(), '0 lines deleted');
$this->assertEquals(0, $files[0]->getDeletions(), '0 lines deleted');
}
/**
@@ -64,14 +66,14 @@ class DiffTest extends AbstractTest
{
$files = $repository->getCommit(self::BEFORE_LONGFILE_COMMIT)->getDiff()->getFiles();
$this->assertEquals(1, count($files), '1 files in diff');
$this->assertCount(1, $files, '1 files in diff');
$this->assertTrue($files[0]->isModification(), 'image.jpg modified');
$this->assertEquals('image.jpg', $files[0]->getOldName(), 'Second file name is image.jpg');
$this->assertEquals('image.jpg', $files[0]->getNewName(), 'Second file name is image.jpg');
$this->assertEquals('100644', $files[0]->getOldMode(), 'Second file mode is a new file');
$this->assertEquals('100644', $files[0]->getNewMode(), 'Second file mode is correct');
$this->assertEquals('100644', $files[0]->getOldMode(), 'Second file mode is a new file');
$this->assertEquals('100644', $files[0]->getNewMode(), 'Second file mode is correct');
$this->assertTrue($files[0]->isBinary(), 'binary file');
$this->assertEquals(0, $files[0]->getAdditions(), '0 lines added');
@@ -85,7 +87,7 @@ class DiffTest extends AbstractTest
{
$files = $repository->getCommit(self::DELETE_COMMIT)->getDiff()->getFiles();
$this->assertEquals(1, count($files), '1 files modified');
$this->assertCount(1, $files, '1 files modified');
$this->assertTrue($files[0]->isDeletion(), 'File deletion');
$this->assertEquals('script_B.php', $files[0]->getOldName(), 'verify old filename');
@@ -99,7 +101,7 @@ class DiffTest extends AbstractTest
{
$files = $repository->getCommit(self::RENAME_COMMIT)->getDiff()->getFiles();
$this->assertEquals(1, count($files), '1 files modified');
$this->assertCount(1, $files, '1 files modified');
$this->assertTrue($files[0]->isModification());
$this->assertTrue($files[0]->isRename());
@@ -115,7 +117,7 @@ class DiffTest extends AbstractTest
{
$files = $repository->getCommit(self::CHANGEMODE_COMMIT)->getDiff()->getFiles();
$this->assertEquals(1, count($files), '1 files modified');
$this->assertCount(1, $files, '1 files modified');
$this->assertTrue($files[0]->isModification());
$this->assertTrue($files[0]->isChangeMode());
@@ -133,10 +135,19 @@ class DiffTest extends AbstractTest
$changes = $files[0]->getChanges();
$this->assertEquals(0, $changes[0]->getRangeOldStart());
$this->assertEquals(0, $changes[0]->getRangeOldCount());
$this->assertSame(0, $changes[0]->getRangeOldStart());
$this->assertSame(0, $changes[0]->getRangeOldCount());
$this->assertEquals(1, $changes[0]->getRangeNewStart());
$this->assertEquals(0, $changes[0]->getRangeNewCount());
$this->assertSame(1, $changes[0]->getRangeNewStart());
$this->assertSame(0, $changes[0]->getRangeNewCount());
}
/**
* @dataProvider provideFoobar
*/
public function testWorksWithUmlauts($repository)
{
$files = $repository->getCommit(self::FILE_WITH_UMLAUTS_COMMIT)->getDiff()->getFiles();
$this->assertSame('file_with_umlauts_\303\244\303\266\303\274', $files[0]->getNewName());
}
}

View File

@@ -9,13 +9,20 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Exception\InvalidArgumentException;
use Gitonomy\Git\Exception\LogicException;
class HooksTest extends AbstractTest
{
private static $symlinkOnWindows = null;
public static function setUpBeforeClass()
/**
* @beforeClass
*/
public static function setUpWindows()
{
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
self::$symlinkOnWindows = true;
@@ -48,7 +55,8 @@ class HooksTest extends AbstractTest
$file = $this->hookPath($repository, $hook);
$this->assertTrue($repository->getHooks()->has($hook), "hook $hook in repository");
$this->assertTrue(file_exists($file), "Hook $hook is present");
$this->assertFileExists($file, "Hook $hook is present");
}
public function assertNoHook($repository, $hook)
@@ -56,7 +64,12 @@ class HooksTest extends AbstractTest
$file = $this->hookPath($repository, $hook);
$this->assertFalse($repository->getHooks()->has($hook), "No hook $hook in repository");
$this->assertFalse(file_exists($file), "Hook $hook is not present");
if (method_exists($this, 'assertFileDoesNotExist')) {
$this->assertFileDoesNotExist($file, "Hook $hook is not present");
} else {
$this->assertFileNotExists($file, "Hook $hook is not present");
}
}
/**
@@ -71,10 +84,11 @@ class HooksTest extends AbstractTest
/**
* @dataProvider provideFoobar
* @expectedException InvalidArgumentException
*/
public function testGet_InvalidName_ThrowsException($repository)
{
$this->expectException(InvalidArgumentException::class);
$repository->getHooks()->get('foo');
}
@@ -99,15 +113,21 @@ class HooksTest extends AbstractTest
$repository->getHooks()->setSymlink('foo', $file);
$this->assertTrue(is_link($this->hookPath($repository, 'foo')), 'foo hook is a symlink');
$this->assertEquals($file, readlink($this->hookPath($repository, 'foo')), 'target of symlink is correct');
$this->assertEquals(
str_replace('\\', '/', $file),
str_replace('\\', '/', readlink($this->hookPath($repository, 'foo'))),
'target of symlink is correct'
);
}
/**
* @dataProvider provideFoobar
* @expectedException LogicException
*/
public function testSymlink_WithExisting_ThrowsLogicException($repository)
{
$this->expectException(LogicException::class);
$this->markAsSkippedIfSymlinkIsMissing();
$file = $this->hookPath($repository, 'target-symlink');
@@ -140,7 +160,8 @@ class HooksTest extends AbstractTest
{
$repository->getHooks()->set('foo', 'bar');
$this->setExpectedException('LogicException');
$this->expectException(LogicException::class);
$repository->getHooks()->set('foo', 'bar');
}
@@ -153,15 +174,21 @@ class HooksTest extends AbstractTest
touch($file);
$repository->getHooks()->remove('foo');
$this->assertFalse(file_exists($file));
if (method_exists($this, 'assertFileDoesNotExist')) {
$this->assertFileDoesNotExist($file);
} else {
$this->assertFileNotExists($file);
}
}
/**
* @dataProvider provideFoobar
* @expectedException LogicException
*/
public function testRemove_NotExisting_ThrowsLogicException($repository)
{
$this->expectException(LogicException::class);
$repository->getHooks()->remove('foo');
}

View File

@@ -9,9 +9,8 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Log;
namespace Gitonomy\Git\Tests;
class LogTest extends AbstractTest
{
@@ -23,8 +22,8 @@ class LogTest extends AbstractTest
$logReadme = $repository->getLog(self::LONGFILE_COMMIT, 'README');
$logImage = $repository->getLog(self::LONGFILE_COMMIT, 'image.jpg');
$this->assertEquals(3, count($logReadme));
$this->assertEquals(2, count($logImage));
$this->assertCount(3, $logReadme);
$this->assertCount(2, $logImage);
}
/**
@@ -36,7 +35,7 @@ class LogTest extends AbstractTest
$commits = $log->getCommits();
$this->assertEquals(3, count($commits), '3 commits in log');
$this->assertCount(3, $commits, '3 commits in log');
$this->assertEquals(self::LONGFILE_COMMIT, $commits[0]->getHash(), 'First is requested one');
$this->assertEquals(self::BEFORE_LONGFILE_COMMIT, $commits[1]->getHash(), "Second is longfile parent\'s");
}
@@ -68,7 +67,7 @@ class LogTest extends AbstractTest
{
$log = $repository->getLog(self::LONGFILE_COMMIT);
$expectedHashes = array(self::LONGFILE_COMMIT, self::BEFORE_LONGFILE_COMMIT);
$expectedHashes = [self::LONGFILE_COMMIT, self::BEFORE_LONGFILE_COMMIT];
foreach ($log as $entry) {
$hash = array_shift($expectedHashes);
$this->assertEquals($hash, $entry->getHash());

View File

@@ -9,6 +9,7 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\PushReference;
@@ -23,12 +24,12 @@ class PushReferenceTest extends AbstractTest
public function provideIsers()
{
// mask: force fastforward create delete
return array(
array('foo', PushReference::ZERO, self::LONGFILE_COMMIT, self::CREATE),
array('foo', self::LONGFILE_COMMIT, PushReference::ZERO, self::DELETE),
array('foo', self::LONGFILE_COMMIT, self::BEFORE_LONGFILE_COMMIT, self::FORCE),
array('foo', self::BEFORE_LONGFILE_COMMIT, self::LONGFILE_COMMIT, self::FAST_FORWARD),
);
return [
['foo', PushReference::ZERO, self::LONGFILE_COMMIT, self::CREATE],
['foo', self::LONGFILE_COMMIT, PushReference::ZERO, self::DELETE],
['foo', self::LONGFILE_COMMIT, self::BEFORE_LONGFILE_COMMIT, self::FORCE],
['foo', self::BEFORE_LONGFILE_COMMIT, self::LONGFILE_COMMIT, self::FAST_FORWARD],
];
}
/**
@@ -37,10 +38,10 @@ class PushReferenceTest extends AbstractTest
public function testIsers($reference, $before, $after, $mask)
{
$reference = new PushReference(self::createFoobarRepository(), $reference, $before, $after);
$this->assertEquals($mask & self::CREATE, $reference->isCreate(), 'Create value is correct.');
$this->assertEquals($mask & self::DELETE, $reference->isDelete(), 'Delete value is correct.');
$this->assertEquals($mask & self::FORCE, $reference->isForce(), 'Force value is correct.');
$this->assertEquals($mask & self::FAST_FORWARD, $reference->isFastForward(), 'FastForward value is correct.');
$this->assertEquals($mask & self::CREATE, $reference->isCreate(), 'Create value is correct.');
$this->assertEquals($mask & self::DELETE, $reference->isDelete(), 'Delete value is correct.');
$this->assertEquals($mask & self::FORCE, $reference->isForce(), 'Force value is correct.');
$this->assertEquals($mask & self::FAST_FORWARD, $reference->isFastForward(), 'FastForward value is correct.');
}
/**
@@ -51,7 +52,7 @@ class PushReferenceTest extends AbstractTest
$ref = new PushReference($repository, 'foo', self::INITIAL_COMMIT, self::LONGFILE_COMMIT);
$log = $ref->getLog()->getCommits();
$this->assertEquals(7, count($log), '7 commits in log');
$this->assertCount(7, $log, '7 commits in log');
$this->assertEquals('add a long file', $log[0]->getShortMessage(), 'First commit is correct');
}
@@ -64,7 +65,7 @@ class PushReferenceTest extends AbstractTest
{
$ref = new PushReference($repository, 'foo', self::INITIAL_COMMIT, self::SIGNED_COMMIT);
$log = $ref->getLog()->getCommits();
$this->assertEquals(16, count($log), '16 commits in log');
$this->assertCount(16, $log, '16 commits in log');
$this->assertEquals('signed commit', $log[0]->getShortMessage(), 'Last commit is correct');
}
@@ -75,8 +76,8 @@ class PushReferenceTest extends AbstractTest
{
$ref = new PushReference($repository, 'foo', PushReference::ZERO, self::LONGFILE_COMMIT);
$log = $ref->getLog(array(self::INITIAL_COMMIT))->getCommits();
$this->assertEquals(7, count($log), '7 commits in log');
$log = $ref->getLog([self::INITIAL_COMMIT])->getCommits();
$this->assertCount(7, $log, '7 commits in log');
$this->assertEquals('add a long file', $log[0]->getShortMessage(), 'First commit is correct');
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* This file is part of Gitonomy.
*
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
* (c) Julien DIDIER <genzo.wm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Repository;
class ReferenceBagTest extends AbstractTest
{
/**
* @dataProvider provideFoobar
*/
public function testUnknownReference(Repository $repository)
{
$hash = $repository->getLog()->getSingleCommit()->getHash();
$repository->run('update-ref', ['refs/pipelines/1', $hash]);
$repository->run('update-ref', ['refs/merge-request/1/head', $hash]);
$repository->run('update-ref', ['refs/pull/1/head', $hash]);
$repository->run('update-ref', ['refs/notes/gtm-data', $hash]);
$refs = $repository->getReferences()->getAll();
if (method_exists($this, 'assertIsArray')) {
$this->assertIsArray($refs);
} else {
$this->assertInternalType('array', $refs);
}
// Check that at least it has the master ref
$this->assertArrayHasKey('refs/heads/master', $refs);
// Check that our custom refs have been ignored
$this->assertArrayNotHasKey('refs/pipelines/1', $refs);
$this->assertArrayNotHasKey('refs/merge-request/1/head', $refs);
$this->assertArrayNotHasKey('refs/pull/1/head', $refs);
$this->assertArrayNotHasKey('refs/notes/gtm-data', $refs);
}
}

View File

@@ -9,22 +9,22 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Exception\ReferenceNotFoundException;
use Gitonomy\Git\Reference\Branch;
use Gitonomy\Git\Reference\Tag;
class ReferenceTest extends AbstractTest
{
private $references;
/**
* @dataProvider provideEmpty
*/
public function testEmptyRepository($repository)
{
$this->assertCount(0, $repository->getReferences());
$this->assertEquals(array(), $repository->getReferences()->getAll());
$this->assertEquals([], $repository->getReferences()->getAll());
}
/**
@@ -34,7 +34,7 @@ class ReferenceTest extends AbstractTest
{
$branch = $repository->getReferences()->getBranch('master');
$this->assertTrue($branch instanceof Branch, 'Branch object is correct type');
$this->assertInstanceOf(Branch::class, $branch, 'Branch object is correct type');
$this->assertEquals($branch->getCommitHash(), $branch->getCommit()->getHash(), 'Hash is correctly resolved');
}
@@ -58,11 +58,12 @@ class ReferenceTest extends AbstractTest
/**
* @dataProvider provideFoobar
* @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException
*/
public function testGetBranch_NotExisting_Error($repository)
{
$branch = $repository->getReferences()->getBranch('notexisting');
$this->expectException(ReferenceNotFoundException::class);
$repository->getReferences()->getBranch('notexisting');
}
/**
@@ -72,7 +73,8 @@ class ReferenceTest extends AbstractTest
{
$tag = $repository->getReferences()->getTag('0.1');
$this->assertTrue($tag instanceof Tag, 'Tag object is correct type');
$this->assertInstanceOf(Tag::class, $tag, 'Tag object is correct type');
$this->assertFalse($tag->isAnnotated(), 'Tag is not annotated');
$this->assertEquals(self::LONGFILE_COMMIT, $tag->getCommitHash(), 'Commit hash is correct');
$this->assertEquals(self::LONGFILE_COMMIT, $tag->getCommit()->getHash(), 'Commit hash is correct');
@@ -80,11 +82,38 @@ class ReferenceTest extends AbstractTest
/**
* @dataProvider provideFoobar
* @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException
*/
public function testAnnotatedTag($repository)
{
$tag = $repository->getReferences()->getTag('annotated');
$this->assertInstanceOf(Tag::class, $tag, 'Tag object is correct type');
$this->assertTrue($tag->isAnnotated(), 'Tag is annotated');
$this->assertFalse($tag->isSigned(), 'Tag is not signed');
$this->assertEquals('Graham Campbell', $tag->getTaggerName(), 'Tagger name is correct');
$this->assertEquals('graham@alt-three.com', $tag->getTaggerEmail(), 'Tagger email is correct');
$this->assertEquals(1471428000, $tag->getTaggerDate()->getTimestamp(), 'Tag date is correct');
$this->assertEquals('heading', $tag->getSubjectMessage(), 'Message heading is correct');
$this->assertEquals("body\nbody", $tag->getBodyMessage(), 'Message body is correct');
$closure = function () {
return parent::getCommit();
};
$parentCommit = $closure->bindTo($tag, Tag::class);
$this->assertNotEquals($parentCommit()->getHash(), $tag->getCommit()->getHash(), 'Tag commit is not the same as main commit');
$this->assertEquals('fbde681b329a39e08b63dc54b341a3274c0380c0', $tag->getCommit()->getHash(), 'Tag commit is correct');
}
/**
* @dataProvider provideFoobar
*/
public function testGetTag_NotExisting_Error($repository)
{
$branch = $repository->getReferences()->getTag('notexisting');
$this->expectException(ReferenceNotFoundException::class);
$repository->getReferences()->getTag('notexisting');
}
/**
@@ -95,8 +124,8 @@ class ReferenceTest extends AbstractTest
$commit = $repository->getReferences()->getTag('0.1')->getCommit();
$resolved = $repository->getReferences()->resolve($commit->getHash());
$this->assertEquals(1, count($resolved), '1 revision resolved');
$this->assertTrue(reset($resolved) instanceof Tag, 'Resolved object is a tag');
$this->assertCount(1, $resolved, '1 revision resolved');
$this->assertInstanceOf(Tag::class, reset($resolved), 'Resolved object is a tag');
}
/**
@@ -107,8 +136,8 @@ class ReferenceTest extends AbstractTest
$commit = $repository->getReferences()->getTag('0.1')->getCommit();
$resolved = $repository->getReferences()->resolveTags($commit->getHash());
$this->assertEquals(1, count($resolved), '1 revision resolved');
$this->assertTrue(reset($resolved) instanceof Tag, 'Resolved object is a tag');
$this->assertCount(1, $resolved, '1 revision resolved');
$this->assertInstanceOf(Tag::class, reset($resolved), 'Resolved object is a tag');
}
/**
@@ -121,12 +150,12 @@ class ReferenceTest extends AbstractTest
$resolved = $repository->getReferences()->resolveBranches($master->getCommitHash());
if ($repository->isBare()) {
$this->assertEquals(1, count($resolved), '1 revision resolved');
$this->assertCount(1, $resolved, '1 revision resolved');
} else {
$this->assertEquals(2, count($resolved), '2 revision resolved');
$this->assertCount(2, $resolved, '2 revision resolved');
}
$this->assertTrue(reset($resolved) instanceof Branch, 'Resolved object is a branch');
$this->assertInstanceOf(Branch::class, reset($resolved), 'Resolved object is a branch');
}
/**
@@ -144,7 +173,7 @@ class ReferenceTest extends AbstractTest
{
$i = 0;
foreach ($repository->getReferences() as $ref) {
++$i;
$i++;
}
$this->assertGreaterThanOrEqual(2, $i, 'At least two references in repository');
}

View File

@@ -9,10 +9,11 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Blob;
use Gitonomy\Git\Repository;
use Gitonomy\Git\Exception\RuntimeException;
use Prophecy\Argument;
class RepositoryTest extends AbstractTest
@@ -20,12 +21,17 @@ class RepositoryTest extends AbstractTest
/**
* @dataProvider provideFoobar
*/
public function testGetBlob_WithExisting_Works($repository)
public function testGetBlobWithExistingWorks($repository)
{
$blob = $repository->getCommit(self::LONGFILE_COMMIT)->getTree()->resolvePath('README.md');
$this->assertTrue($blob instanceof Blob, 'getBlob() returns a Blob object');
$this->assertContains('Foo Bar project', $blob->getContent(), 'file is correct');
$this->assertInstanceOf(Blob::class, $blob, 'getBlob() returns a Blob object');
if (method_exists($this, 'assertStringContainsString')) {
$this->assertStringContainsString('Foo Bar project', $blob->getContent(), 'file is correct');
} else {
$this->assertContains('Foo Bar project', $blob->getContent(), 'file is correct');
}
}
/**
@@ -34,7 +40,8 @@ class RepositoryTest extends AbstractTest
public function testGetSize($repository)
{
$size = $repository->getSize();
$this->assertGreaterThan(70, $size, 'Repository is greater than 70KB');
$this->assertGreaterThanOrEqual(69, $size, 'Repository is at least 69KB');
$this->assertLessThan(80, $size, 'Repository is less than 80KB');
}
public function testIsBare()
@@ -66,12 +73,10 @@ class RepositoryTest extends AbstractTest
$loggerProphecy = $this->prophesize('Psr\Log\LoggerInterface');
$loggerProphecy
->info('run command: remote "" ')
->shouldBeCalledTimes(1)
;
->shouldBeCalledTimes(1);
$loggerProphecy
->debug(Argument::type('string')) // duration, return code and output
->shouldBeCalledTimes(3)
;
->shouldBeCalledTimes(3);
$repository->setLogger($loggerProphecy->reveal());
@@ -80,7 +85,6 @@ class RepositoryTest extends AbstractTest
/**
* @dataProvider provideFoobar
* @expectedException RuntimeException
*/
public function testLoggerNOk($repository)
{
@@ -88,19 +92,18 @@ class RepositoryTest extends AbstractTest
$this->markTestSkipped();
}
$this->expectException(RuntimeException::class);
$loggerProphecy = $this->prophesize('Psr\Log\LoggerInterface');
$loggerProphecy
->info(Argument::type('string'))
->shouldBeCalledTimes(1)
;
->shouldBeCalledTimes(1);
$loggerProphecy
->debug(Argument::type('string')) // duration, return code and output
->shouldBeCalledTimes(3)
;
->shouldBeCalledTimes(3);
$loggerProphecy
->error(Argument::type('string'))
->shouldBeCalledTimes(1)
;
->shouldBeCalledTimes(1);
$repository->setLogger($loggerProphecy->reveal());

View File

@@ -9,9 +9,11 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Commit;
use Gitonomy\Git\Exception\ReferenceNotFoundException;
use Gitonomy\Git\Log;
use Gitonomy\Git\Revision;
@@ -24,23 +26,24 @@ class RevisionTest extends AbstractTest
{
$revision = $repository->getRevision(self::LONGFILE_COMMIT.'^');
$this->assertTrue($revision instanceof Revision, 'Revision object type');
$this->assertInstanceOf(Revision::class, $revision, 'Revision object type');
$commit = $revision->getCommit();
$this->assertTrue($commit instanceof Commit, 'getCommit returns a Commit');
$this->assertInstanceOf(Commit::class, $commit, 'getCommit returns a Commit');
$this->assertEquals(self::BEFORE_LONGFILE_COMMIT, $commit->getHash(), 'Resolution is correct');
}
/**
* @dataProvider provideFoobar
* @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException
* @expectedExceptionMessage Can not find revision "non-existent-commit"
*/
public function testGetFailingReference($repository)
{
$revision = $repository->getRevision('non-existent-commit')->getCommit();
$this->expectException(ReferenceNotFoundException::class);
$this->expectExceptionMessage('Can not find revision "non-existent-commit"');
$repository->getRevision('non-existent-commit')->getCommit();
}
/**
@@ -52,9 +55,9 @@ class RevisionTest extends AbstractTest
$log = $revision->getLog(null, 2, 3);
$this->assertTrue($log instanceof Log, 'Log type object');
$this->assertInstanceOf(Log::class, $log, 'Log type object');
$this->assertEquals(2, $log->getOffset(), 'Log offset is passed');
$this->assertEquals(3, $log->getLimit(), 'Log limit is passed');
$this->assertEquals(array($revision), $log->getRevisions()->getAll(), 'Revision is passed');
$this->assertEquals([$revision], $log->getRevisions()->getAll(), 'Revision is passed');
}
}

View File

@@ -9,6 +9,7 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Blob;
@@ -16,6 +17,7 @@ use Gitonomy\Git\Blob;
class TreeTest extends AbstractTest
{
const PATH_RESOLVING_COMMIT = 'cc06ac171d884282202dff88c1ded499a1f89420';
/**
* @dataProvider provideFooBar
*/
@@ -25,10 +27,10 @@ class TreeTest extends AbstractTest
$entries = $tree->getEntries();
$this->assertTrue(isset($entries['long.php']), 'long.php is present');
$this->assertNotEmpty($entries['long.php'], 'long.php is present');
$this->assertTrue($entries['long.php'][1] instanceof Blob, 'long.php is a Blob');
$this->assertTrue(isset($entries['README.md']), 'README.md is present');
$this->assertNotEmpty($entries['README.md'], 'README.md is present');
$this->assertTrue($entries['README.md'][1] instanceof Blob, 'README.md is a Blob');
}
@@ -43,6 +45,6 @@ class TreeTest extends AbstractTest
$resolved = $tree->resolvePath($path);
$entries = $resolved->getEntries();
$this->assertTrue(isset($entries['d']), 'Successfully resolved source folder');
$this->assertNotEmpty($entries['d'], 'Successfully resolved source folder');
}
}

View File

@@ -9,18 +9,20 @@
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Gitonomy\Git\Tests;
use Gitonomy\Git\Admin;
use Gitonomy\Git\Exception\LogicException;
use Gitonomy\Git\Exception\RuntimeException;
use Gitonomy\Git\Reference\Branch;
class WorkingCopyTest extends AbstractTest
{
/**
* @expectedException LogicException
*/
public function testNoWorkingCopyInBare()
{
$this->expectException(LogicException::class);
$path = self::createTempDir();
$repo = Admin::init($path, true, self::getOptions());
@@ -34,7 +36,7 @@ class WorkingCopyTest extends AbstractTest
$wc->checkout('origin/new-feature', 'new-feature');
$head = $repository->getHead();
$this->assertTrue($head instanceof Branch, 'HEAD is a branch');
$this->assertInstanceOf(Branch::class, $head, 'HEAD is a branch');
$this->assertEquals('new-feature', $head->getName(), 'HEAD is branch new-feature');
}
@@ -48,7 +50,7 @@ class WorkingCopyTest extends AbstractTest
$file = $repository->getWorkingDir().'/foobar-test';
file_put_contents($file, 'test');
$repository->run('add', array($file));
$repository->run('add', [$file]);
$diffStaged = $wc->getDiffStaged();
$this->assertCount(1, $diffStaged->getFiles());
@@ -69,11 +71,10 @@ class WorkingCopyTest extends AbstractTest
$this->assertCount(1, $diffPending->getFiles());
}
/**
* @expectedException RuntimeException
*/
public function testCheckoutUnexisting()
{
$this->expectException(RuntimeException::class);
self::createFoobarRepository(false)->getWorkingCopy()->checkout('foobar');
}