|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of the SVN-Buddy library. |
| 4 | + * For the full copyright and license information, please view |
| 5 | + * the LICENSE file that was distributed with this source code. |
| 6 | + * |
| 7 | + * @copyright Alexander Obuhovich <aik.bold@gmail.com> |
| 8 | + * @link https://github.com/console-helpers/svn-buddy |
| 9 | + */ |
| 10 | + |
| 11 | +namespace Tests\ConsoleHelpers\SVNBuddy\Repository; |
| 12 | + |
| 13 | + |
| 14 | +use ConsoleHelpers\SVNBuddy\Repository\CommitMessageBuilder; |
| 15 | +use Prophecy\Argument; |
| 16 | +use Prophecy\Prophecy\ObjectProphecy; |
| 17 | + |
| 18 | +class CommitMessageBuilderTest extends \PHPUnit_Framework_TestCase |
| 19 | +{ |
| 20 | + |
| 21 | + /** |
| 22 | + * Repository connector. |
| 23 | + * |
| 24 | + * @var ObjectProphecy |
| 25 | + */ |
| 26 | + protected $connector; |
| 27 | + |
| 28 | + /** |
| 29 | + * Revision log factory |
| 30 | + * |
| 31 | + * @var ObjectProphecy |
| 32 | + */ |
| 33 | + protected $revisionLogFactory; |
| 34 | + |
| 35 | + /** |
| 36 | + * Commit message builder. |
| 37 | + * |
| 38 | + * @var CommitMessageBuilder |
| 39 | + */ |
| 40 | + protected $commitMessageBuilder; |
| 41 | + |
| 42 | + protected function setUp() |
| 43 | + { |
| 44 | + parent::setUp(); |
| 45 | + |
| 46 | + $this->connector = $this->prophesize('ConsoleHelpers\SVNBuddy\Repository\Connector\Connector'); |
| 47 | + |
| 48 | + $revision_list_parser = $this->prophesize('ConsoleHelpers\SVNBuddy\Repository\Parser\RevisionListParser'); |
| 49 | + $revision_list_parser->expandRanges(Argument::cetera())->willReturnArgument(0); |
| 50 | + |
| 51 | + $this->revisionLogFactory = $this->prophesize( |
| 52 | + 'ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLogFactory' |
| 53 | + ); |
| 54 | + |
| 55 | + $this->commitMessageBuilder = new CommitMessageBuilder( |
| 56 | + $this->connector->reveal(), |
| 57 | + $revision_list_parser->reveal(), |
| 58 | + $this->revisionLogFactory->reveal() |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + public function testBuildWithoutChangelist() |
| 63 | + { |
| 64 | + $merge_info = '/projects/project-name/trunk:10,15' . PHP_EOL; |
| 65 | + $this->connector->getProperty('svn:mergeinfo', '/path/to/working-copy', 'BASE')->willReturn($merge_info); |
| 66 | + $this->connector->getProperty('svn:mergeinfo', '/path/to/working-copy', null)->willReturn($merge_info); |
| 67 | + |
| 68 | + $this->assertEmpty($this->commitMessageBuilder->build('/path/to/working-copy')); |
| 69 | + } |
| 70 | + |
| 71 | + public function testBuildWithChangelist() |
| 72 | + { |
| 73 | + $merge_info = '/projects/project-name/trunk:10,15' . PHP_EOL; |
| 74 | + $this->connector->getProperty('svn:mergeinfo', '/path/to/working-copy', 'BASE')->willReturn($merge_info); |
| 75 | + $this->connector->getProperty('svn:mergeinfo', '/path/to/working-copy', null)->willReturn($merge_info); |
| 76 | + |
| 77 | + $this->assertEquals('cl name', $this->commitMessageBuilder->build('/path/to/working-copy', 'cl name')); |
| 78 | + } |
| 79 | + |
| 80 | + public function testBuildMergeResult() |
| 81 | + { |
| 82 | + $this->prepareMergeResult(); |
| 83 | + |
| 84 | + $expected = <<<COMMIT_MSG |
| 85 | +Merging from Trunk to Stable |
| 86 | +* r18: a-line1 |
| 87 | +a-line2 |
| 88 | +* r33: b-line1 |
| 89 | +b-line2 |
| 90 | +
|
| 91 | +Merging from Branch-name to Stable |
| 92 | +* r4: c-line1 |
| 93 | +c-line2 |
| 94 | +COMMIT_MSG; |
| 95 | + |
| 96 | + $this->assertEquals($expected, $this->commitMessageBuilder->build('/path/to/working-copy')); |
| 97 | + } |
| 98 | + |
| 99 | + public function testBuildWithConflicts() |
| 100 | + { |
| 101 | + $merge_info = '/projects/project-name/trunk:10,15' . PHP_EOL; |
| 102 | + $this->connector->getProperty('svn:mergeinfo', '/path/to/working-copy', 'BASE')->willReturn($merge_info); |
| 103 | + $this->connector->getProperty('svn:mergeinfo', '/path/to/working-copy', null)->willReturn($merge_info); |
| 104 | + |
| 105 | + $expected = <<<COMMIT_MSG |
| 106 | +
|
| 107 | +Conflicts: |
| 108 | + * sub-folder/file1.txt |
| 109 | + * file2.ext |
| 110 | +COMMIT_MSG; |
| 111 | + |
| 112 | + $this->assertEquals( |
| 113 | + $expected, |
| 114 | + $this->commitMessageBuilder->build( |
| 115 | + '/path/to/working-copy', |
| 116 | + null, |
| 117 | + array( |
| 118 | + 'sub-folder/file1.txt', |
| 119 | + 'file2.ext', |
| 120 | + ) |
| 121 | + ) |
| 122 | + ); |
| 123 | + } |
| 124 | + |
| 125 | + public function testBuildEverythingPresent() |
| 126 | + { |
| 127 | + $this->prepareMergeResult(); |
| 128 | + |
| 129 | + $expected = <<<COMMIT_MSG |
| 130 | +cl one |
| 131 | +Merging from Trunk to Stable |
| 132 | +* r18: a-line1 |
| 133 | +a-line2 |
| 134 | +* r33: b-line1 |
| 135 | +b-line2 |
| 136 | +
|
| 137 | +Merging from Branch-name to Stable |
| 138 | +* r4: c-line1 |
| 139 | +c-line2 |
| 140 | +
|
| 141 | +Conflicts: |
| 142 | + * sub-folder/file1.txt |
| 143 | + * file2.ext |
| 144 | +COMMIT_MSG; |
| 145 | + |
| 146 | + $this->assertEquals( |
| 147 | + $expected, |
| 148 | + $this->commitMessageBuilder->build( |
| 149 | + '/path/to/working-copy', |
| 150 | + 'cl one', |
| 151 | + array( |
| 152 | + 'sub-folder/file1.txt', |
| 153 | + 'file2.ext', |
| 154 | + ) |
| 155 | + ) |
| 156 | + ); |
| 157 | + } |
| 158 | + |
| 159 | + protected function prepareMergeResult() |
| 160 | + { |
| 161 | + $this->connector->getProperty('svn:mergeinfo', '/path/to/working-copy', 'BASE')->willReturn( |
| 162 | + '/projects/project-name/trunk:10,15' . PHP_EOL |
| 163 | + ); |
| 164 | + $this->connector->getProperty('svn:mergeinfo', '/path/to/working-copy', null)->willReturn( |
| 165 | + '/projects/project-name/trunk:10,15,18,33' . PHP_EOL . |
| 166 | + '/projects/project-name/branches/branch-name:4' . PHP_EOL |
| 167 | + ); |
| 168 | + |
| 169 | + $this->connector |
| 170 | + ->getWorkingCopyUrl('/path/to/working-copy') |
| 171 | + ->willReturn('svn://repository.com/path/to/project/tags/stable'); |
| 172 | + |
| 173 | + $this->connector |
| 174 | + ->getRootUrl('svn://repository.com/path/to/project/tags/stable') |
| 175 | + ->willReturn('svn://repository.com'); |
| 176 | + |
| 177 | + $revision_log1 = $this->getRevisionLog('svn://repository.com/projects/project-name/trunk'); |
| 178 | + $revision_log1->getRevisionsData('summary', array(18, 33))->willReturn(array( |
| 179 | + 18 => array( |
| 180 | + 'author' => 'user1', |
| 181 | + 'date' => 3534535353, |
| 182 | + 'msg' => 'a-line1' . PHP_EOL . 'a-line2' . PHP_EOL . PHP_EOL, |
| 183 | + ), |
| 184 | + 33 => array( |
| 185 | + 'author' => 'user2', |
| 186 | + 'date' => 35345445353, |
| 187 | + 'msg' => 'b-line1' . PHP_EOL . 'b-line2' . PHP_EOL . PHP_EOL, |
| 188 | + ), |
| 189 | + )); |
| 190 | + |
| 191 | + $revision_log2 = $this->getRevisionLog('svn://repository.com/projects/project-name/branches/branch-name'); |
| 192 | + $revision_log2->getRevisionsData('summary', array(4))->willReturn(array( |
| 193 | + 4 => array( |
| 194 | + 'author' => 'user2', |
| 195 | + 'date' => 35345444353, |
| 196 | + 'msg' => 'c-line1' . PHP_EOL . 'c-line2' . PHP_EOL . PHP_EOL, |
| 197 | + ), |
| 198 | + )); |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * Returns revision log object for given url. |
| 203 | + * |
| 204 | + * @param string $repository_url Repository url. |
| 205 | + * |
| 206 | + * @return ObjectProphecy |
| 207 | + */ |
| 208 | + protected function getRevisionLog($repository_url) |
| 209 | + { |
| 210 | + $revision_log = $this->prophesize('ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLog'); |
| 211 | + $this->revisionLogFactory->getRevisionLog($repository_url)->willReturn($revision_log); |
| 212 | + |
| 213 | + return $revision_log; |
| 214 | + } |
| 215 | + |
| 216 | +} |
0 commit comments