|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * This file is part of the GitCommandBundle package. |
| 4 | + * |
| 5 | + * (c) Paul Schweppe <paulschweppe@gmail.com> |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | + |
| 11 | +namespace VersionControl\GitCommandBundle\Tests\GitCommands\Command; |
| 12 | + |
| 13 | +use VersionControl\GitCommandBundle\Tests\GitCommandTestCase; |
| 14 | + |
| 15 | +/** |
| 16 | + * Description of GitBranchCommandTest. |
| 17 | + * |
| 18 | + * @author fr_user |
| 19 | + */ |
| 20 | +class GitTagCommandTest extends GitCommandTestCase |
| 21 | +{ |
| 22 | + /** |
| 23 | + * setUp, called on every method. |
| 24 | + */ |
| 25 | + public function setUp() |
| 26 | + { |
| 27 | + $this->initGitCommandsLocal(); |
| 28 | + $this->gitCommands->command('init')->initRepository(); |
| 29 | + $this->addFile('test'); |
| 30 | + $this->gitCommands->command('commit')->stageAll(); |
| 31 | + $this->gitCommands->command('commit')->commit('first commit', 'Paul Schweppe <paulschweppe@gmail.com>'); |
| 32 | + $this->addFile('test2'); |
| 33 | + $this->gitCommands->command('commit')->stageAll(); |
| 34 | + $this->gitCommands->command('commit')->commit('Second commit', 'Paul Schweppe <paulschweppe@gmail.com>'); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Test current branch. |
| 39 | + */ |
| 40 | + public function testGetTagsNoTags() |
| 41 | + { |
| 42 | + $tags = $this->gitCommands->command('tag')->getTags(); |
| 43 | + $this->assertCount(0, $tags,'Tag count does not equal expected 0. Actual:'.count($tags)); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Test create local branch. |
| 48 | + */ |
| 49 | + public function testCreateAnnotatedTag() |
| 50 | + { |
| 51 | + $tagCommand = $this->gitCommands->command('tag'); |
| 52 | + |
| 53 | + $this->assertEquals('', $tagCommand->createAnnotatedTag('tag1','Test of tag1'), 'create tag command'); |
| 54 | + |
| 55 | + $tags = $this->gitCommands->command('tag')->getTags(); |
| 56 | + $this->assertCount(1, $tags,'Tag count does not equal expected 1. Actual:'.count($tags)); |
| 57 | + |
| 58 | + $errorMessage = ''; |
| 59 | + try { |
| 60 | + $tagCommand->createAnnotatedTag('tag1','Test of tag1'); |
| 61 | + } catch (\VersionControl\GitCommandBundle\GitCommands\Exception\RunGitCommandException $e) { |
| 62 | + $errorMessage = $e->getMessage(); |
| 63 | + } |
| 64 | + $this->assertEquals("fatal: tag 'tag1' already exists", trim($errorMessage), 'create branch command error'); |
| 65 | + } |
| 66 | + |
| 67 | + public function testPushTag() |
| 68 | + { |
| 69 | + $tagCommand = $this->gitCommands->command('tag'); |
| 70 | + |
| 71 | + $this->assertEquals('', $tagCommand->createAnnotatedTag('tag1','Test of tag1'), 'create tag command'); |
| 72 | + |
| 73 | + // |
| 74 | + try { |
| 75 | + $this->assertEquals('', $tagCommand->pushTag('origin','tag1'), 'Push tag1 to origin'); |
| 76 | + }catch (\VersionControl\GitCommandBundle\GitCommands\Exception\RunGitCommandException $e) { |
| 77 | + $errorMessage = $e->getMessage(); |
| 78 | + } |
| 79 | + $this->assertContains("fatal: 'origin' does not appear to be a git repository", trim($errorMessage), 'push tag command error'); |
| 80 | + |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + /** |
| 88 | + * Test branch names. |
| 89 | + */ |
| 90 | + public function testValidateTagName() |
| 91 | + { |
| 92 | + $this->assertTrue($this->gitCommands->command('branch')->validateBranchName('test'), 'Branch name "test" should be valid'); |
| 93 | + $this->assertTrue($this->gitCommands->command('branch')->validateBranchName('test1232'), 'Branch name "test" should be valid'); |
| 94 | + $this->assertTrue($this->gitCommands->command('branch')->validateBranchName('test!£$test'), 'Branch name "test!£$test" should be valid'); |
| 95 | + |
| 96 | + $this->assertFalse($this->gitCommands->command('branch')->validateBranchName('..test'), 'Branch name "..test" should be invalid'); |
| 97 | + $this->assertFalse($this->gitCommands->command('branch')->validateBranchName('te:st'), 'Branch name "te:st" should be invalid'); |
| 98 | + $this->assertFalse($this->gitCommands->command('branch')->validateBranchName('te~st'), 'Branch name "te~st" should be invalid'); |
| 99 | + $this->assertFalse($this->gitCommands->command('branch')->validateBranchName('te^st'), 'Branch name "te^st" should be invalid'); |
| 100 | + $this->assertFalse($this->gitCommands->command('branch')->validateBranchName('test/'), 'Branch name "test/" should be invalid'); |
| 101 | + $this->assertFalse($this->gitCommands->command('branch')->validateBranchName('\test'), 'Branch name "\test" should be invalid'); |
| 102 | + $this->assertFalse($this->gitCommands->command('branch')->validateBranchName('test test'), 'Branch name "test test" should be invalid'); |
| 103 | + } |
| 104 | + |
| 105 | + |
| 106 | +} |
0 commit comments