From c2d15e6c3bd8a29bae89d184a999ddac15fcb807 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sun, 1 May 2016 22:29:51 -0400 Subject: New plugin repo is cloned to /store/pluginrepos/REPONAME for analysis --- library/kzykhys/git/test/PHPGit/BaseTestCase.php | 33 ++++ .../git/test/PHPGit/Command/AddCommandTest.php | 42 +++++ .../git/test/PHPGit/Command/ArchiveCommandTest.php | 32 ++++ .../git/test/PHPGit/Command/BranchCommandTest.php | 106 +++++++++++ .../git/test/PHPGit/Command/CatCommandTest.php | 65 +++++++ .../test/PHPGit/Command/CheckoutCommandTest.php | 65 +++++++ .../git/test/PHPGit/Command/CloneCommandTest.php | 28 +++ .../git/test/PHPGit/Command/CommitCommandTest.php | 26 +++ .../git/test/PHPGit/Command/ConfigCommandTest.php | 55 ++++++ .../test/PHPGit/Command/DescribeCommandTest.php | 36 ++++ .../git/test/PHPGit/Command/FetchCommandTest.php | 36 ++++ .../git/test/PHPGit/Command/MergeCommandTest.php | 101 ++++++++++ .../git/test/PHPGit/Command/MvCommandTest.php | 26 +++ .../git/test/PHPGit/Command/PullCommandTest.php | 22 +++ .../git/test/PHPGit/Command/PushCommandTest.php | 34 ++++ .../git/test/PHPGit/Command/RebaseCommandTest.php | 154 ++++++++++++++++ .../Command/Remote/SetBranchesCommandTest.php | 28 +++ .../PHPGit/Command/Remote/SetHeadCommandTest.php | 56 ++++++ .../PHPGit/Command/Remote/SetUrlCommandTest.php | 46 +++++ .../git/test/PHPGit/Command/RemoteCommandTest.php | 100 ++++++++++ .../git/test/PHPGit/Command/ResetCommandTest.php | 128 +++++++++++++ .../git/test/PHPGit/Command/RmCommandTest.php | 51 ++++++ .../test/PHPGit/Command/ShortlogCommandTest.php | 71 +++++++ .../git/test/PHPGit/Command/ShowCommandTest.php | 26 +++ .../git/test/PHPGit/Command/StashCommandTest.php | 204 +++++++++++++++++++++ .../git/test/PHPGit/Command/StatusCommandTest.php | 76 ++++++++ .../git/test/PHPGit/Command/TagCommandTest.php | 58 ++++++ .../git/test/PHPGit/Exception/GitExceptionTest.php | 23 +++ library/kzykhys/git/test/PHPGit/GitTest.php | 33 ++++ 29 files changed, 1761 insertions(+) create mode 100644 library/kzykhys/git/test/PHPGit/BaseTestCase.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/AddCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/ArchiveCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/BranchCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/CatCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/CheckoutCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/CloneCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/CommitCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/ConfigCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/DescribeCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/FetchCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/MergeCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/MvCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/PullCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/PushCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/RebaseCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/Remote/SetBranchesCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/Remote/SetHeadCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/Remote/SetUrlCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/RemoteCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/ResetCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/RmCommandTest.php create mode 100755 library/kzykhys/git/test/PHPGit/Command/ShortlogCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/ShowCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/StashCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/StatusCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Command/TagCommandTest.php create mode 100644 library/kzykhys/git/test/PHPGit/Exception/GitExceptionTest.php create mode 100644 library/kzykhys/git/test/PHPGit/GitTest.php (limited to 'library/kzykhys/git/test') diff --git a/library/kzykhys/git/test/PHPGit/BaseTestCase.php b/library/kzykhys/git/test/PHPGit/BaseTestCase.php new file mode 100644 index 000000000..df69b216e --- /dev/null +++ b/library/kzykhys/git/test/PHPGit/BaseTestCase.php @@ -0,0 +1,33 @@ + + */ +abstract class BaseTestCase extends PHPUnit_Framework_TestCase +{ + + /** + * @var string + */ + protected $directory; + + /** + * {@inheritdoc} + */ + public function setUp() + { + $this->directory = __DIR__.'/../../build/' . strtolower(get_class($this)); + } + + /** + * {@inheritdoc} + */ + public function tearDown() + { + $filesystem = new Filesystem(); + $filesystem->remove($this->directory); + } + +} \ No newline at end of file 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 @@ + + */ +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 @@ + + */ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 @@ +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 ']); + $this->assertCount(1, $shortlog['Name Two ']); + $this->assertEquals('1', $shortlog['Name One '][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 ' => 2, + 'Name Two ' => 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 @@ +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 @@ +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 @@ +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 @@ +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 diff --git a/library/kzykhys/git/test/PHPGit/Exception/GitExceptionTest.php b/library/kzykhys/git/test/PHPGit/Exception/GitExceptionTest.php new file mode 100644 index 000000000..154d6b906 --- /dev/null +++ b/library/kzykhys/git/test/PHPGit/Exception/GitExceptionTest.php @@ -0,0 +1,23 @@ +setRepository(sys_get_temp_dir()); + try { + $git->status(); + $this->fail('Previous operation should fail'); + } catch (GitException $e) { + $command = $e->getCommandLine(); + $command = str_replace(array('"', "'"), '', $command); + $this->assertStringEndsWith('status --porcelain -s -b --null', $command); + } + } + +} \ No newline at end of file diff --git a/library/kzykhys/git/test/PHPGit/GitTest.php b/library/kzykhys/git/test/PHPGit/GitTest.php new file mode 100644 index 000000000..c9aceeb13 --- /dev/null +++ b/library/kzykhys/git/test/PHPGit/GitTest.php @@ -0,0 +1,33 @@ +assertNotEmpty($git->getVersion()); + } + + /** + * @expectedException \PHPGit\Exception\GitException + */ + public function testInvalidGitBinary() + { + $git = new Git(); + $git->setBin('/foo/bar'); + $git->getVersion(); + } + + /** + * @expectedException \BadMethodCallException + */ + public function testBadMethodCall() + { + $git = new Git(); + $git->foo(); + } + +} \ No newline at end of file -- cgit v1.2.3