aboutsummaryrefslogtreecommitdiffstats
path: root/library/kzykhys/git/test/PHPGit/Command
diff options
context:
space:
mode:
Diffstat (limited to 'library/kzykhys/git/test/PHPGit/Command')
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/AddCommandTest.php42
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/ArchiveCommandTest.php32
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/BranchCommandTest.php106
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/CatCommandTest.php65
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/CheckoutCommandTest.php65
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/CloneCommandTest.php28
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/CommitCommandTest.php26
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/ConfigCommandTest.php55
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/DescribeCommandTest.php36
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/FetchCommandTest.php36
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/MergeCommandTest.php101
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/MvCommandTest.php26
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/PullCommandTest.php22
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/PushCommandTest.php34
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/RebaseCommandTest.php154
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/Remote/SetBranchesCommandTest.php28
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/Remote/SetHeadCommandTest.php56
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/Remote/SetUrlCommandTest.php46
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/RemoteCommandTest.php100
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/ResetCommandTest.php128
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/RmCommandTest.php51
-rwxr-xr-xlibrary/kzykhys/git/test/PHPGit/Command/ShortlogCommandTest.php71
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/ShowCommandTest.php26
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/StashCommandTest.php204
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/StatusCommandTest.php76
-rw-r--r--library/kzykhys/git/test/PHPGit/Command/TagCommandTest.php58
26 files changed, 1672 insertions, 0 deletions
diff --git a/library/kzykhys/git/test/PHPGit/Command/AddCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/AddCommandTest.php
new file mode 100644
index 000000000..1fad08417
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/AddCommandTest.php
@@ -0,0 +1,42 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+/**
+ * @author Kazuyuki Hayashi <hayashi@valnur.net>
+ */
+class AddCommandTest extends BaseTestCase
+{
+
+ public function testAdd()
+ {
+ $filesystem = new Filesystem();
+ $filesystem->mkdir($this->directory);
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
+ $filesystem->dumpFile($this->directory . '/test.md', '**foo**');
+
+ $this->assertTrue($git->add('test.txt'));
+ $this->assertTrue($git->add(array('test.md'), array('force' => true)));
+ }
+
+ /**
+ * @expectedException \PHPGit\Exception\GitException
+ * @expectedExceptionCode 128
+ */
+ public function testException()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $git->add('foo');
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/ArchiveCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/ArchiveCommandTest.php
new file mode 100644
index 000000000..982c8f7c7
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/ArchiveCommandTest.php
@@ -0,0 +1,32 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+/**
+ * @author Kazuyuki Hayashi <hayashi@valnur.net>
+ */
+class ArchiveCommandTest extends BaseTestCase
+{
+
+ public function testArchive()
+ {
+ $filesystem = new Filesystem();
+ $filesystem->mkdir($this->directory);
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', 'hello');
+ $git->add('test.txt');
+ $git->commit('Initial commit');
+
+ $git->archive($this->directory . '/test.zip', 'master', null, array('format' => 'zip', 'prefix' => 'test/'));
+
+ $this->assertFileExists($this->directory . '/test.zip');
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/BranchCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/BranchCommandTest.php
new file mode 100644
index 000000000..4deeea367
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/BranchCommandTest.php
@@ -0,0 +1,106 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class BranchCommandTest extends BaseTestCase
+{
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', '');
+ $git->add('test.txt');
+ $git->commit('Initial commit');
+ }
+
+ public function testBranch()
+ {
+ $git = new Git();
+ $git->setRepository($this->directory);
+
+ $branches = $git->branch();
+
+ $this->assertCount(1, $branches);
+ $this->assertEquals('master', $branches['master']['name']);
+ $this->assertTrue($branches['master']['current']);
+ $this->assertEquals('Initial commit', $branches['master']['title']);
+ }
+
+ public function testAllBranch()
+ {
+ $git = new Git();
+ $git->clone('file://' . realpath($this->directory), $this->directory.'2');
+ $git->setRepository($this->directory.'2');
+
+ $branches = $git->branch(array('remotes' => true));
+ $this->assertArrayHasKey('origin/master', $branches);
+
+ $branches = $git->branch(array('all' => true));
+ $this->assertArrayHasKey('master', $branches);
+ $this->assertArrayHasKey('remotes/origin/master', $branches);
+
+ $filesystem = new Filesystem();
+ $filesystem->remove($this->directory.'2');
+ }
+
+ public function testBranchCreate()
+ {
+ $git = new Git();
+ $git->setRepository($this->directory);
+
+ $git->branch->create('1.0');
+ $branches = $git->branch();
+ $this->assertCount(2, $branches);
+
+ $git->branch->create('1.0-fix', '1.0', array('force' => true));
+ $branches = $git->branch();
+ $this->assertCount(3, $branches);
+ $this->assertArrayHasKey('1.0', $branches);
+ $this->assertArrayHasKey('1.0-fix', $branches);
+ }
+
+ public function testBranchMove()
+ {
+ $git = new Git();
+ $git->setRepository($this->directory);
+ $git->branch->create('1.0');
+ $git->branch->move('1.0', '1.0.x');
+ $branches = $git->branch();
+ $this->assertCount(2, $branches);
+ $this->assertArrayHasKey('1.0.x', $branches);
+
+ $git->branch->move('1.0.x', '2.x', array('force' => true));
+ $branches = $git->branch();
+ $this->assertCount(2, $branches);
+ $this->assertArrayHasKey('2.x', $branches);
+ }
+
+ public function testBranchDelete()
+ {
+ $git = new Git();
+ $git->setRepository($this->directory);
+ $git->branch->create('1.0');
+ $git->branch->create('2.0');
+ $branches = $git->branch();
+ $this->assertCount(3, $branches);
+
+ $git->branch->delete('1.0');
+ $branches = $git->branch();
+ $this->assertCount(2, $branches);
+
+ $git->branch->delete('2.0', array('force' => true));
+ $branches = $git->branch();
+ $this->assertCount(1, $branches);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/CatCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/CatCommandTest.php
new file mode 100644
index 000000000..945924ccb
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/CatCommandTest.php
@@ -0,0 +1,65 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class CatCommandTest extends BaseTestCase
+{
+
+ public function testCatBlob()
+ {
+ $filesystem = new Filesystem();
+ $filesystem->mkdir($this->directory);
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
+ $git->add('test.txt');
+ $git->commit('Initial commit');
+
+ $tree = $git->tree();
+
+ $this->assertEquals('foo', $git->cat->blob($tree[0]['hash']));
+ }
+
+ public function testCatType()
+ {
+ $filesystem = new Filesystem();
+ $filesystem->mkdir($this->directory);
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
+ $git->add('test.txt');
+ $git->commit('Initial commit');
+
+ $tree = $git->tree();
+
+ $this->assertEquals('blob', $git->cat->type($tree[0]['hash']));
+ }
+
+ public function testCatSize()
+ {
+ $filesystem = new Filesystem();
+ $filesystem->mkdir($this->directory);
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
+ $git->add('test.txt');
+ $git->commit('Initial commit');
+
+ $tree = $git->tree();
+
+ $this->assertEquals(3, $git->cat->size($tree[0]['hash']));
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/CheckoutCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/CheckoutCommandTest.php
new file mode 100644
index 000000000..c306ea407
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/CheckoutCommandTest.php
@@ -0,0 +1,65 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class CheckoutCommandTest extends BaseTestCase
+{
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', '');
+ $git->add('test.txt');
+ $git->commit('Initial commit');
+ }
+
+ public function testCheckout()
+ {
+ $git = new Git();
+ $git->setRepository($this->directory);
+ $git->branch->create('next');
+ $git->checkout('next');
+
+ $branches = $git->branch();
+ $this->assertArrayHasKey('next', $branches);
+ $this->assertTrue($branches['next']['current']);
+ }
+
+ public function testCheckoutCreate()
+ {
+ $git = new Git();
+ $git->setRepository($this->directory);
+ $git->checkout->create('next');
+
+ $branches = $git->branch();
+ $this->assertArrayHasKey('next', $branches);
+ $this->assertTrue($branches['next']['current']);
+
+ $git->checkout->create('develop', 'next');
+
+ $branches = $git->branch();
+ $this->assertArrayHasKey('develop', $branches);
+ $this->assertTrue($branches['develop']['current']);
+ }
+
+ public function testCheckoutOrphan()
+ {
+ $git = new Git();
+ $git->setRepository($this->directory);
+ $git->checkout->orphan('gh-pages', 'master', array('force' => true));
+
+ $status = $git->status();
+ $this->assertEquals('gh-pages', $status['branch']);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/CloneCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/CloneCommandTest.php
new file mode 100644
index 000000000..d6a4d26ff
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/CloneCommandTest.php
@@ -0,0 +1,28 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class CloneCommandTest extends BaseTestCase
+{
+
+ public function testClone()
+ {
+ $git = new Git();
+ $git->clone('https://github.com/kzykhys/Text.git', $this->directory);
+ $git->setRepository($this->directory);
+
+ $this->assertFileExists($this->directory . '/.git');
+
+ $filesystem = new Filesystem();
+ $filesystem->remove($this->directory);
+
+ $git->setRepository('.');
+ $git->clone('https://github.com/kzykhys/Text.git', $this->directory, array('shared' => true));
+
+ $this->assertFileExists($this->directory . '/.git');
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/CommitCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/CommitCommandTest.php
new file mode 100644
index 000000000..01b50ad8d
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/CommitCommandTest.php
@@ -0,0 +1,26 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class CommitCommandTest extends BaseTestCase
+{
+
+ public function testCommit()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem = new Filesystem();
+ $filesystem->dumpFile($this->directory . '/test.txt', '');
+ $git->add('test.txt');
+ $git->commit('Initial commit');
+ $logs = $git->log('test.txt');
+
+ $this->assertCount(1, $logs);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/ConfigCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/ConfigCommandTest.php
new file mode 100644
index 000000000..fba2fbf76
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/ConfigCommandTest.php
@@ -0,0 +1,55 @@
+<?php
+
+use PHPGit\Git;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class ConfigCommandTest extends BaseTestCase
+{
+
+ public function testConfigSetAndList()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $before = $git->config();
+
+ $git->config->set('user.name', 'John Doe');
+
+ $config = $git->config();
+ $this->assertArrayHasKey('user.name', $config);
+
+ $expected = 'John Doe';
+
+ if (isset($before['user.name'])) {
+ $expected = $before['user.name'] . "\n" . $expected;
+ }
+
+ $this->assertEquals($expected, $config['user.name']);
+ }
+
+ public function testConfigAdd()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $before = $git->config();
+
+ $git->config->set('user.name', 'John Doe');
+ $git->config->add('user.name', 'Foo');
+
+ $config = $git->config();
+ $this->assertArrayHasKey('user.name', $config);
+
+ $expected = "John Doe\nFoo";
+
+ if (isset($before['user.name'])) {
+ $expected = $before['user.name'] . "\n" . $expected;
+ }
+
+ $this->assertEquals($expected, $config['user.name']);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/DescribeCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/DescribeCommandTest.php
new file mode 100644
index 000000000..04d3bd3b0
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/DescribeCommandTest.php
@@ -0,0 +1,36 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class DescribeCommandTest extends BaseTestCase
+{
+
+ public function testDescribeTags()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('README.md');
+ $git->commit('Initial commit');
+ $git->tag->create('v1.0.0');
+ $version = $git->describe->tags('HEAD');
+
+ $this->assertEquals('v1.0.0', $version);
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello2');
+ $git->add('README.md');
+ $git->commit('Fixes README');
+ $version = $git->describe->tags('HEAD');
+
+ $this->assertStringStartsWith('v1.0.0', $version);
+ $this->assertStringEndsNotWith('v1.0.0', $version);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/FetchCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/FetchCommandTest.php
new file mode 100644
index 000000000..f52943099
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/FetchCommandTest.php
@@ -0,0 +1,36 @@
+<?php
+
+use PHPGit\Git;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class FetchCommandTest extends BaseTestCase
+{
+
+ public function testFetch()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
+ $git->fetch('origin', '+refs/heads/*:refs/remotes/origin/*');
+
+ $tags = $git->tag();
+ $this->assertContains('v1.0.0', $tags);
+ }
+
+ public function testFetchAll()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
+ $git->fetch->all();
+
+ $tags = $git->tag();
+ $this->assertContains('v1.0.0', $tags);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/MergeCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/MergeCommandTest.php
new file mode 100644
index 000000000..208461523
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/MergeCommandTest.php
@@ -0,0 +1,101 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class MergeCommandTest extends BaseTestCase
+{
+
+ public function testMerge()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
+ $git->add('test.txt');
+ $git->commit('master');
+
+ $git->checkout->create('develop');
+ $filesystem->dumpFile($this->directory . '/test.txt', 'bar');
+ $git->add('test.txt');
+ $git->commit('develop');
+
+ $git->checkout('master');
+
+ $this->assertEquals('foo', file_get_contents($this->directory . '/test.txt'));
+
+ $git->merge('develop');
+
+ $this->assertEquals('bar', file_get_contents($this->directory . '/test.txt'));
+ }
+
+ /**
+ * @expectedException \PHPGit\Exception\GitException
+ */
+ public function testMergeFail()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ // branch:master
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
+ $git->add('test.txt');
+ $git->commit('master');
+
+ // branch:develop
+ $git->checkout->create('develop');
+ $filesystem->dumpFile($this->directory . '/test.txt', 'bar');
+ $git->add('test.txt');
+ $git->commit('develop');
+
+ // branch:master
+ $git->checkout('master');
+ $filesystem->dumpFile($this->directory . '/test.txt', 'baz');
+ $git->merge('develop');
+ }
+
+ public function testMergeAbort()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ // branch:master
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
+ $git->add('test.txt');
+ $git->commit('master');
+
+ // branch:develop
+ $git->checkout->create('develop');
+ $filesystem->dumpFile($this->directory . '/test.txt', 'bar');
+ $git->add('test.txt');
+ $git->commit('develop');
+
+ // branch:master
+ $git->checkout('master');
+ $filesystem->dumpFile($this->directory . '/test.txt', 'baz');
+ $git->add('test.txt');
+ $git->commit('master');
+
+ try {
+ $git->merge('develop');
+ $this->fail('$git->merge("develop") should fail');
+ } catch (Exception $e) {
+ }
+
+ $git->merge->abort();
+
+ $this->assertEquals('baz', file_get_contents($this->directory . '/test.txt'));
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/MvCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/MvCommandTest.php
new file mode 100644
index 000000000..dd5f46c55
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/MvCommandTest.php
@@ -0,0 +1,26 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class MvCommandTest extends BaseTestCase
+{
+
+ public function testMv()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
+ $git->add('test.txt');
+ $git->commit('Initial commit');
+ $git->mv('test.txt', 'test2.txt');
+
+ $this->assertFileExists($this->directory . '/test2.txt');
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/PullCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/PullCommandTest.php
new file mode 100644
index 000000000..89dec75a9
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/PullCommandTest.php
@@ -0,0 +1,22 @@
+<?php
+
+use PHPGit\Git;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class PullCommandTest extends BaseTestCase
+{
+
+ public function testPull()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
+ $git->pull('origin', 'master');
+
+ $this->assertFileExists($this->directory . '/README.md');
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/PushCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/PushCommandTest.php
new file mode 100644
index 000000000..11424cebc
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/PushCommandTest.php
@@ -0,0 +1,34 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class PushCommandTest extends BaseTestCase
+{
+
+ public function testPush()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory, array('shared' => true, 'bare' => true));
+
+ $git->clone('file://' . realpath($this->directory), $this->directory.'2');
+ $git->setRepository($this->directory.'2');
+
+ $filesystem->dumpFile($this->directory.'2/test.txt', 'foobar');
+ $git->add('test.txt');
+ $git->commit('test');
+ $git->push('origin', 'master');
+
+ $git->clone('file://' . realpath($this->directory), $this->directory.'3');
+
+ $this->assertFileExists($this->directory.'3/test.txt');
+
+ $filesystem->remove($this->directory.'2');
+ $filesystem->remove($this->directory.'3');
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/RebaseCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/RebaseCommandTest.php
new file mode 100644
index 000000000..af7e87a19
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/RebaseCommandTest.php
@@ -0,0 +1,154 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class RebaseCommandTest extends BaseTestCase
+{
+
+ public function testRebase()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', '123');
+ $git->add('test.txt');
+ $git->commit('initial commit');
+
+ $git->checkout->create('next');
+ $filesystem->dumpFile($this->directory . '/test2.txt', '123');
+ $git->add('test2.txt');
+ $git->commit('test');
+
+ $git->checkout('master');
+ $git->rebase('next', 'master');
+
+ $this->assertFileExists($this->directory. '/test2.txt');
+ }
+
+ public function testRebaseOnto()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/test.txt', '123');
+ $git->add('test.txt');
+ $git->commit('initial commit');
+
+ $git->checkout->create('next');
+ $filesystem->dumpFile($this->directory . '/test2.txt', '123');
+ $git->add('test2.txt');
+ $git->commit('test');
+
+ $git->checkout->create('topic', 'next');
+ $filesystem->dumpFile($this->directory . '/test3.txt', '123');
+ $git->add('test3.txt');
+ $git->commit('test');
+
+ $git->rebase('next', null, array('onto' => 'master'));
+ $this->assertFileNotExists($this->directory . '/test2.txt');
+ }
+
+ public function testRebaseContinue()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
+ $git->add('test.txt');
+ $git->commit('initial commit');
+
+ $git->checkout->create('next');
+ $filesystem->dumpFile($this->directory . '/test.txt', 'bar');
+ $git->add('test.txt');
+ $git->commit('next commit');
+
+ $git->checkout('master');
+ $filesystem->dumpFile($this->directory . '/test.txt', 'baz');
+ $git->add('test.txt');
+ $git->commit('master commit');
+
+ try {
+ $git->rebase('next');
+ $this->fail('GitException should be thrown');
+ } catch (\PHPGit\Exception\GitException $e) {
+ }
+
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foobar');
+ $git->add('test.txt');
+ $git->rebase->continues();
+ }
+
+ public function testRebaseAbort()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
+ $git->add('test.txt');
+ $git->commit('initial commit');
+
+ $git->checkout->create('next');
+ $filesystem->dumpFile($this->directory . '/test.txt', 'bar');
+ $git->add('test.txt');
+ $git->commit('next commit');
+
+ $git->checkout('master');
+ $filesystem->dumpFile($this->directory . '/test.txt', 'baz');
+ $git->add('test.txt');
+ $git->commit('master commit');
+
+ try {
+ $git->rebase('next');
+ $this->fail('GitException should be thrown');
+ } catch (\PHPGit\Exception\GitException $e) {
+ }
+
+ $git->rebase->abort();
+ }
+
+ public function testRebaseSkip()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', 'foo');
+ $git->add('test.txt');
+ $git->commit('initial commit');
+
+ $git->checkout->create('next');
+ $filesystem->dumpFile($this->directory . '/test.txt', 'bar');
+ $git->add('test.txt');
+ $git->commit('next commit');
+
+ $git->checkout('master');
+ $filesystem->dumpFile($this->directory . '/test.txt', 'baz');
+ $git->add('test.txt');
+ $git->commit('master commit');
+
+ try {
+ $git->rebase('next');
+ $this->fail('GitException should be thrown');
+ } catch (\PHPGit\Exception\GitException $e) {
+ }
+
+ $git->rebase->skip();
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/Remote/SetBranchesCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/Remote/SetBranchesCommandTest.php
new file mode 100644
index 000000000..4f428f832
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/Remote/SetBranchesCommandTest.php
@@ -0,0 +1,28 @@
+<?php
+
+use PHPGit\Git;
+
+require_once __DIR__ . '/../../BaseTestCase.php';
+
+class SetBranchesCommandTest extends BaseTestCase
+{
+
+ public function testSetBranches()
+ {
+ $git = new Git();
+ $git->clone('https://github.com/kzykhys/Text.git', $this->directory);
+ $git->setRepository($this->directory);
+
+ $git->remote->branches('origin', array('master'));
+ }
+
+ public function testSetBranchesAdd()
+ {
+ $git = new Git();
+ $git->clone('https://github.com/kzykhys/Text.git', $this->directory);
+ $git->setRepository($this->directory);
+
+ $git->remote->branches->add('origin', array('gh-pages'));
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/Remote/SetHeadCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/Remote/SetHeadCommandTest.php
new file mode 100644
index 000000000..679c2976f
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/Remote/SetHeadCommandTest.php
@@ -0,0 +1,56 @@
+<?php
+
+use PHPGit\Git;
+
+require_once __DIR__ . '/../../BaseTestCase.php';
+
+class SetHeadCommandTest extends BaseTestCase
+{
+
+ public function testSetHead()
+ {
+ $git = new Git();
+ $git->clone('https://github.com/kzykhys/Text.git', $this->directory);
+ $git->setRepository($this->directory);
+
+ $before = $git->branch(array('all' => true));
+
+ $git->remote->head('origin', 'master');
+
+ $after = $git->branch(array('all' => true));
+
+ $this->assertEquals($before, $after);
+ }
+
+ public function testSetHeadDelete()
+ {
+ $git = new Git();
+ $git->clone('https://github.com/kzykhys/Text.git', $this->directory);
+ $git->setRepository($this->directory);
+
+ $before = $git->branch(array('all' => true));
+
+ $git->remote->head->delete('origin');
+
+ $after = $git->branch(array('all' => true));
+
+ $this->assertNotEquals($before, $after);
+ }
+
+ public function testSetHeadRemote()
+ {
+ $git = new Git();
+ $git->clone('https://github.com/kzykhys/Text.git', $this->directory);
+ $git->setRepository($this->directory);
+
+ $before = $git->branch(array('all' => true));
+
+ $git->remote->head->delete('origin');
+ $git->remote->head->remote('origin');
+
+ $after = $git->branch(array('all' => true));
+
+ $this->assertEquals($before, $after);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/Remote/SetUrlCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/Remote/SetUrlCommandTest.php
new file mode 100644
index 000000000..b70b67d40
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/Remote/SetUrlCommandTest.php
@@ -0,0 +1,46 @@
+<?php
+
+use PHPGit\Git;
+
+require_once __DIR__ . '/../../BaseTestCase.php';
+
+class SetUrlCommandTest extends BaseTestCase
+{
+
+ public function testSetUrl()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $git->remote->add('origin', 'http://example.com/test.git');
+ $git->remote->url('origin', 'https://github.com/kzykhys/Text.git', 'http://example.com/test.git');
+
+ $remotes = $git->remote();
+
+ $this->assertEquals('https://github.com/kzykhys/Text.git', $remotes['origin']['fetch']);
+ }
+
+ public function testSetUrlAdd()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $git->remote->add('origin', 'http://example.com/test.git');
+ $git->remote->url->add('origin', 'https://github.com/kzykhys/Text.git');
+ }
+
+ public function testSetUrlDelete()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $git->remote->add('origin', 'http://example.com/test.git');
+ $git->remote->url->add('origin', 'https://github.com/kzykhys/Text.git');
+ $git->remote->url->delete('origin', 'https://github.com');
+
+ $remotes = $git->remote();
+
+ $this->assertEquals('http://example.com/test.git', $remotes['origin']['fetch']);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/RemoteCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/RemoteCommandTest.php
new file mode 100644
index 000000000..78aa81309
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/RemoteCommandTest.php
@@ -0,0 +1,100 @@
+<?php
+
+use PHPGit\Git;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class RemoteCommandTest extends BaseTestCase
+{
+
+ public function testRemote()
+ {
+ $git = new Git();
+ $git->clone('https://github.com/kzykhys/Text.git', $this->directory);
+ $git->setRepository($this->directory);
+
+ $remotes = $git->remote();
+
+ $this->assertEquals(array(
+ 'origin' => array(
+ 'fetch' => 'https://github.com/kzykhys/Text.git',
+ 'push' => 'https://github.com/kzykhys/Text.git'
+ )
+ ), $remotes);
+ }
+
+ public function testRemoteAdd()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
+
+ $remotes = $git->remote();
+
+ $this->assertEquals(array(
+ 'origin' => array(
+ 'fetch' => 'https://github.com/kzykhys/Text.git',
+ 'push' => 'https://github.com/kzykhys/Text.git'
+ )
+ ), $remotes);
+ }
+
+ public function testRemoteRename()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
+ $git->remote->rename('origin', 'upstream');
+
+ $remotes = $git->remote();
+ $this->assertEquals(array(
+ 'upstream' => array(
+ 'fetch' => 'https://github.com/kzykhys/Text.git',
+ 'push' => 'https://github.com/kzykhys/Text.git'
+ )
+ ), $remotes);
+ }
+
+ public function testRemoteRm()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
+ $git->remote->rm('origin');
+
+ $remotes = $git->remote();
+ $this->assertEquals(array(), $remotes);
+ }
+
+ public function testRemoteShow()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
+
+ $this->assertNotEmpty($git->remote->show('origin'));
+ }
+
+ public function testRemotePrune()
+ {
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
+ $git->remote->prune('origin');
+ }
+
+ /**
+ * @expectedException \BadMethodCallException
+ */
+ public function testBadMethodCall()
+ {
+ $git = new Git();
+ $git->remote->foo();
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/ResetCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/ResetCommandTest.php
new file mode 100644
index 000000000..777e48512
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/ResetCommandTest.php
@@ -0,0 +1,128 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+
+class ResetCommandTest extends BaseTestCase
+{
+
+ public function testReset()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'foo');
+ $git->add('README.md');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('README.md');
+
+ $git->reset('README.md', 'HEAD');
+ }
+
+ public function testResetSoft()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'foo');
+ $git->add('README.md');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+
+ $git->reset->soft();
+ }
+
+ public function testResetMixed()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'foo');
+ $git->add('README.md');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+
+ $git->reset->mixed();
+ }
+
+ public function testResetHard()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'foo');
+ $git->add('README.md');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+
+ $git->reset->hard('HEAD');
+ }
+
+ public function testResetMerge()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'foo');
+ $git->add('README.md');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+
+ $git->reset->merge();
+ }
+
+ public function testResetKeep()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'foo');
+ $git->add('README.md');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+
+ $git->reset->keep();
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testResetInvalidMode()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'foo');
+ $git->add('README.md');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+
+ $git->reset->mode('foo');
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/RmCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/RmCommandTest.php
new file mode 100644
index 000000000..34996cc12
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/RmCommandTest.php
@@ -0,0 +1,51 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class RmCommandTest extends BaseTestCase
+{
+
+ public function testRm()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'foo');
+ $filesystem->dumpFile($this->directory . '/bin/test.php', 'foo');
+ $git->add(array('README.md', 'bin/test.php'));
+ $git->commit('Initial commit');
+
+ $git->rm('README.md');
+ $git->rm('bin', array('recursive' => true));
+
+ $this->assertFileNotExists($this->directory . '/README.md');
+ }
+
+ public function testRmCached()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'foo');
+ $git->add('README.md');
+ $git->commit('Initial commit');
+
+ $git->rm->cached('README.md');
+ $git->commit('Delete README.md');
+
+ $this->assertFileExists($this->directory . '/README.md');
+
+ $tree = $git->tree();
+ $this->assertEquals(array(), $tree);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/ShortlogCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/ShortlogCommandTest.php
new file mode 100755
index 000000000..48967cab1
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/ShortlogCommandTest.php
@@ -0,0 +1,71 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class ShortlogCommandTest extends BaseTestCase
+{
+
+ public function testShortlog()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $git->config->set('user.name', 'Name One');
+ $git->config->set('user.email', 'one@example.com');
+ $filesystem->dumpFile($this->directory . '/test.txt', '');
+ $git->add('test.txt');
+ $git->commit('1');
+ $filesystem->dumpFile($this->directory . '/test2.txt', '');
+ $git->add('test2.txt');
+ $git->commit('2');
+
+ $git->config->set('user.name', 'Name Two');
+ $git->config->set('user.email', 'two@example.com');
+ $filesystem->dumpFile($this->directory . '/test3.txt', '');
+ $git->add('test3.txt');
+ $git->commit('3');
+
+ $shortlog = $git->shortlog();
+
+ $this->assertCount(2, $shortlog);
+ $this->assertCount(2, $shortlog['Name One <one@example.com>']);
+ $this->assertCount(1, $shortlog['Name Two <two@example.com>']);
+ $this->assertEquals('1', $shortlog['Name One <one@example.com>'][0]['subject']);
+ }
+
+ public function testShortlogSummary()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $git->config->set('user.name', 'Name One');
+ $git->config->set('user.email', 'one@example.com');
+ $filesystem->dumpFile($this->directory . '/test.txt', '');
+ $git->add('test.txt');
+ $git->commit('1');
+ $filesystem->dumpFile($this->directory . '/test2.txt', '');
+ $git->add('test2.txt');
+ $git->commit('2');
+
+ $git->config->set('user.name', 'Name Two');
+ $git->config->set('user.email', 'two@example.com');
+ $filesystem->dumpFile($this->directory . '/test3.txt', '');
+ $git->add('test3.txt');
+ $git->commit('3');
+
+ $summary = $git->shortlog->summary();
+
+ $this->assertEquals(array(
+ 'Name One <one@example.com>' => 2,
+ 'Name Two <two@example.com>' => 1
+ ), $summary);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/ShowCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/ShowCommandTest.php
new file mode 100644
index 000000000..25b22fe4f
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/ShowCommandTest.php
@@ -0,0 +1,26 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class ShowCommandTest extends BaseTestCase
+{
+
+ public function testShow()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'foobar');
+ $git->add('README.md');
+ $git->commit('Initial commit');
+
+ $git->show('master', array('format' => 'oneline'));
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/StashCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/StashCommandTest.php
new file mode 100644
index 000000000..bb87e48ea
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/StashCommandTest.php
@@ -0,0 +1,204 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class StashCommandTest extends BaseTestCase
+{
+
+ public function testStash()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
+ $git->stash();
+
+ $this->assertEquals('hello', file_get_contents($this->directory.'/README.md'));
+ }
+
+ public function testStashSave()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
+ $git->stash->save('stash test');
+
+ $this->assertEquals('hello', file_get_contents($this->directory.'/README.md'));
+ }
+
+ public function testStashList()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
+ $git->stash();
+
+ $stashes = $git->stash->lists();
+
+ $this->assertCount(1, $stashes);
+ $this->assertEquals('master', $stashes[0]['branch']);
+ $this->assertStringEndsWith('Initial commit', $stashes[0]['message']);
+ }
+
+ public function testStashShow()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
+ $git->stash();
+ $git->stash->show('stash@{0}');
+ }
+
+ public function testStashDrop()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
+ $git->stash();
+ $git->stash->drop();
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
+ $git->stash();
+ $git->stash->drop('stash@{0}');
+
+ $this->assertCount(0, $git->stash->lists());
+ }
+
+ public function testStashPop()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
+ $git->stash->save('stash#1');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'bar');
+ $git->stash->save('stash#2');
+ $git->stash->pop('stash@{1}');
+
+ $this->assertEquals('hi!', file_get_contents($this->directory.'/README.md'));
+ $this->assertCount(1, $git->stash->lists());
+ }
+
+ public function testStashApply()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
+ $git->stash->save('stash#1');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'bar');
+ $git->stash->save('stash#2');
+ $git->stash->apply('stash@{1}');
+
+ $this->assertEquals('hi!', file_get_contents($this->directory.'/README.md'));
+ $this->assertCount(2, $git->stash->lists());
+ }
+
+ public function testStashBranch()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
+ $git->stash();
+
+ $git->stash->branch('dev', 'stash@{0}');
+ $status = $git->status();
+
+ $this->assertEquals('dev', $status['branch']);
+ $this->assertEquals('hi!', file_get_contents($this->directory.'/README.md'));
+ }
+
+ public function testStashClear()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
+ $git->stash();
+ $git->stash->clear();
+
+ $this->assertCount(0, $git->stash->lists());
+ }
+
+ public function testStashCreate()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+
+ $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
+ $object = $git->stash->create();
+
+ $this->assertNotEmpty($object);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/StatusCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/StatusCommandTest.php
new file mode 100644
index 000000000..ad04a74c0
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/StatusCommandTest.php
@@ -0,0 +1,76 @@
+<?php
+
+use PHPGit\Command\StatusCommand;
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class StatusCommandTest extends BaseTestCase
+{
+
+ public function testStatus()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/item1.txt', '1');
+ $filesystem->dumpFile($this->directory . '/item2.txt', '2');
+ $filesystem->dumpFile($this->directory . '/item3.txt', '3');
+
+ $git->add('item1.txt');
+ $git->add('item2.txt');
+
+ $filesystem->dumpFile($this->directory . '/item1.txt', '1-1');
+
+ $status = $git->status();
+
+ $this->assertEquals(array(
+ 'branch' => 'master',
+ 'changes' => array(
+ array('file' => 'item1.txt', 'index' => StatusCommand::ADDED, 'work_tree' => StatusCommand::MODIFIED),
+ array('file' => 'item2.txt', 'index' => StatusCommand::ADDED, 'work_tree' => StatusCommand::UNMODIFIED),
+ array('file' => 'item3.txt', 'index' => StatusCommand::UNTRACKED, 'work_tree' => StatusCommand::UNTRACKED),
+ )
+ ), $status);
+ }
+
+ public function testDetachedHeadStatus()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/item1.txt', '1');
+ $git->add('item1.txt');
+ $git->commit('initial commit');
+ $logs = $git->log();
+ $hash = $logs[0]['hash'];
+
+ $git->checkout($hash);
+ $status = $git->status();
+ $this->assertEquals(null, $status['branch']);
+ }
+
+ public function testTrackingBranchStatus()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->clone('https://github.com/kzykhys/Text.git', $this->directory);
+ $git->setRepository($this->directory);
+
+ $filesystem->dumpFile($this->directory . '/test.txt', '1');
+ $git->add('test.txt');
+ $git->commit('test');
+
+ $status = $git->status();
+ $this->assertEquals('master', $status['branch']);
+ }
+
+} \ No newline at end of file
diff --git a/library/kzykhys/git/test/PHPGit/Command/TagCommandTest.php b/library/kzykhys/git/test/PHPGit/Command/TagCommandTest.php
new file mode 100644
index 000000000..5715ba92e
--- /dev/null
+++ b/library/kzykhys/git/test/PHPGit/Command/TagCommandTest.php
@@ -0,0 +1,58 @@
+<?php
+
+use PHPGit\Git;
+use Symfony\Component\Filesystem\Filesystem;
+
+require_once __DIR__ . '/../BaseTestCase.php';
+
+class TagCommandTest extends BaseTestCase
+{
+
+ public function testTagDelete()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+ $git->tag->create('v1.0.0');
+ $git->tag->delete('v1.0.0');
+ $this->assertCount(0, $git->tag());
+ }
+
+ /**
+ * @expectedException \PHPGit\Exception\GitException
+ */
+ public function testTagVerify()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+ $git->tag->create('v1.0.0');
+ $git->tag->verify('v1.0.0');
+ }
+
+ public function testCreateTagFromCommit()
+ {
+ $filesystem = new Filesystem();
+
+ $git = new Git();
+ $git->init($this->directory);
+ $git->setRepository($this->directory);
+ $filesystem->dumpFile($this->directory . '/README.md', 'hello');
+ $git->add('.');
+ $git->commit('Initial commit');
+ $log = $git->log(null, null, array('limit' => 1));
+ $git->tag->create('v1.0.0', $log[0]['hash']);
+ $this->assertCount(1, $git->tag());
+ }
+
+} \ No newline at end of file