{
\Mockery::close();
}
public function testIsCreatingRepositoryFixtures()
{
$a = $this->client->createRepository(self::$tmpdir . '/testrepo');
$b = $this->client->createRepository(self::$tmpdir . '/anothertestrepo');
$c = $this->client->createRepository(self::$tmpdir . '/bigbadrepo');
$this->assertRegExp("/nothing to commit/", $a->getClient()->run($a, 'status'));
$this->assertRegExp("/nothing to commit/", $b->getClient()->run($b, 'status'));
$this->assertRegExp("/nothing to commit/", $c->getClient()->run($c, 'status'));
}
public function testIsConfiguratingRepository()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$repository->setConfig('user.name', 'Luke Skywalker');
$repository->setConfig('user.email', 'luke@rebel.org');
$this->assertEquals($repository->getConfig('user.name'), 'Luke Skywalker');
$this->assertEquals($repository->getConfig('user.email'), 'luke@rebel.org');
}
public function testIsNamesCorrect()
{
$a = $this->client->createRepository(self::$tmpdir . '/reponame');
$b = $this->client->createRepository(self::$tmpdir . '/another-repo-name/');
$this->assertEquals("reponame", $a->getName());
$this->assertEquals("another-repo-name", $b->getName());
}
public function testIsAdding()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
file_put_contents(self::$tmpdir . '/testrepo/test_file.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
$repository->add('test_file.txt');
$this->assertRegExp("/new file: test_file.txt/", $repository->getClient()->run($repository, 'status'));
}
/**
* @depends testIsAdding
*/
public function testIsAddingDot()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
file_put_contents(self::$tmpdir . '/testrepo/test_file1.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file2.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file3.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
$repository->add();
$this->assertRegExp("/new file: test_file1.txt/", $repository->getClient()->run($repository, 'status'));
$this->assertRegExp("/new file: test_file2.txt/", $repository->getClient()->run($repository, 'status'));
$this->assertRegExp("/new file: test_file3.txt/", $repository->getClient()->run($repository, 'status'));
}
/**
* @depends testIsAddingDot
*/
public function testIsAddingAll()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
file_put_contents(self::$tmpdir . '/testrepo/test_file4.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file5.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file6.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
$repository->addAll();
$this->assertRegExp("/new file: test_file4.txt/", $repository->getClient()->run($repository, 'status'));
$this->assertRegExp("/new file: test_file5.txt/", $repository->getClient()->run($repository, 'status'));
$this->assertRegExp("/new file: test_file6.txt/", $repository->getClient()->run($repository, 'status'));
}
/**
* @depends testIsAddingAll
*/
public function testIsAddingArrayOfFiles()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
file_put_contents(self::$tmpdir . '/testrepo/test_file7.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file8.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file9.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
$repository->add(array('test_file7.txt', 'test_file8.txt', 'test_file9.txt'));
$this->assertRegExp("/new file: test_file7.txt/", $repository->getClient()->run($repository, 'status'));
$this->assertRegExp("/new file: test_file8.txt/", $repository->getClient()->run($repository, 'status'));
$this->assertRegExp("/new file: test_file9.txt/", $repository->getClient()->run($repository, 'status'));
}
/**
* @depends testIsAddingArrayOfFiles
*/
public function testIsCommiting()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$repository->commit("The truth unveiled\n\nThis is a proper commit body");
$this->assertRegExp("/The truth unveiled/", $repository->getClient()->run($repository, 'log'));
$this->assertRegExp("/This is a proper commit body/", $repository->getClient()->run($repository, 'log'));
}
public function testIsCreatingBranches()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$repository->createBranch('issue12');
$repository->createBranch('issue42');
$branches = $repository->getBranches();
$this->assertContains('issue12', $branches);
$this->assertContains('issue42', $branches);
$this->assertContains('master', $branches);
}
public function testIsCreatingTags()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$repository->createTag('1.0.0');
$repository->createTag('1.0.1', 'annotated tag');
$tags = $repository->getTags();
$this->assertContains('1.0.0', $tags);
$this->assertContains('1.0.1', $tags);
}
public function testIsGettingCurrentBranch()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$branch = $repository->getCurrentBranch();
$this->assertTrue($branch === 'master');
$commits = $repository->getCommits();
$hash = $commits[0]->getHash();
$repository->checkout($hash);
$new_branch = $repository->getCurrentBranch();
# $this->assertTrue($new_branch === NULL);
$repository->checkout($branch);
}
public function testIsGettingBranchesWhenHeadIsDetached()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$commits = $repository->getCommits();
$current_branch = $repository->getCurrentBranch();
$hash = $commits[0]->getHash();
$repository->checkout($hash);
$branches = $repository->getBranches();
$this->assertTrue(count($branches) === 3);
$branch = $repository->getHead('develop');
$repository->checkout($current_branch);
}
public function testIsCheckingIfBranchExists()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$this->assertTrue($repository->hasBranch('issue12'));
}
public function testIsCheckingOut()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$branch = $repository->checkout('issue12');
$branch = $repository->getCurrentBranch();
$this->assertTrue($branch === 'issue12');
$repository->checkout('master');
$branch = $repository->getCurrentBranch();
$this->assertTrue($branch === 'master');
}
/**
* @depends testIsCommiting
*/
public function testIsGettingCommits()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$commits = $repository->getCommits();
foreach ($commits as $commit) {
$this->assertTrue($commit->isCommit());
$this->assertInstanceOf('Gitter\Model\Commit\Commit', $commit);
$this->assertEquals($commit->getMessage(), 'The truth unveiled');
$this->assertInstanceOf('Gitter\Model\Commit\Author', $commit->getAuthor());
$this->assertEquals($commit->getAuthor()->getName(), 'Luke Skywalker');
$this->assertEquals($commit->getAuthor()->getEmail(), 'luke@rebel.org');
$this->assertEquals($commit->getCommiter()->getName(), 'Luke Skywalker');
$this->assertEquals($commit->getCommiter()->getEmail(), 'luke@rebel.org');
$this->assertEquals($commit->getParentsHash(), array());
$this->assertInstanceOf('DateTime', $commit->getDate());
$this->assertInstanceOf('DateTime', $commit->getCommiterDate());
$this->assertRegExp('/[a-f0-9]+/', $commit->getHash());
$this->assertRegExp('/[a-f0-9]+/', $commit->getShortHash());
$this->assertRegExp('/[a-f0-9]+/', $commit->getTreeHash());
}
}
/**
* @depends testIsGettingCommits
*/
public function testIsGettingCommitsFromSpecificFile()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$commits = $repository->getCommits('test_file4.txt');
foreach ($commits as $commit) {
$this->assertTrue($commit->isCommit());
$this->assertInstanceOf('Gitter\Model\Commit\Commit', $commit);
$this->assertEquals($commit->getMessage(), "The truth unveiled");
$this->assertInstanceOf('Gitter\Model\Commit\Author', $commit->getAuthor());
$this->assertEquals($commit->getAuthor()->getName(), 'Luke Skywalker');
$this->assertEquals($commit->getAuthor()->getEmail(), 'luke@rebel.org');
}
}
public function testIsGettingTree()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$files = $repository->getTree('master');
foreach ($files as $file) {
$this->assertTrue($file->isBlob());
$this->assertInstanceOf('Gitter\Model\Blob', $file);
$this->assertRegExp('/test_file[0-9]*.txt/', $file->getName());
$this->assertEquals($file->getSize(), '55');
$this->assertEquals($file->getMode(), '100644');
$this->assertRegExp('/[a-f0-9]+/', $file->getHash());
}
}
public function testIsGettingTreeOutput()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$files = $repository->getTree('master')->output();
foreach ($files as $file) {
$this->assertEquals('blob', $file['type']);
$this->assertRegExp('/test_file[0-9]*.txt/', $file['name']);
$this->assertEquals($file['size'], '55');
$this->assertEquals($file['mode'], '100644');
$this->assertRegExp('/[a-f0-9]+/', $file['hash']);
}
}
public function testIsGettingTreesWithinTree()
{
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
// Creating folders
mkdir(self::$tmpdir . '/testrepo/MyFolder');
mkdir(self::$tmpdir . '/testrepo/MyTest');
mkdir(self::$tmpdir . '/testrepo/MyFolder/Tests');
// Populating created folders
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/crazy.php', 'Lorem ipsum dolor sit amet');
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/skywalker.php', 'Lorem ipsum dolor sit amet');
file_put_contents(self::$tmpdir . '/testrepo/MyTest/fortytwo.php', 'Lorem ipsum dolor sit amet');
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/Tests/web.php', 'Lorem ipsum dolor sit amet');
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/Tests/cli.php', 'Lorem ipsum dolor sit amet');
// Adding and commiting
$repository->addAll();
$repository->commit("Creating folders for testIsGettingTreesWithinTrees");
// Checking tree
$files = $repository->getTree('master')->output();
$this->assertEquals('folder', $files[0]['type']);
$this->assertEquals('MyFolder', $files[0]['name']);
$this->assertEquals('', $files[0]['size']);
$this->assertEquals('040000', $files[0]['mode']);
$this->assertEquals('4143e982237f3bdf56b5350f862c334054aad69e', $files[0]['hash']);
$this->assertEquals('folder', $files[1]['type']);