Complex classes like RepositoryTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use RepositoryTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class RepositoryTest extends TestCase |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * setUp |
||
| 33 | */ |
||
| 34 | public function setUp() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @covers \GitElephant\Repository::__construct |
||
| 41 | * @covers \GitElephant\Repository::getPath |
||
| 42 | */ |
||
| 43 | public function testConstruct() |
||
| 44 | { |
||
| 45 | $this->assertEquals($this->getRepository()->getPath(), $this->path); |
||
| 46 | |||
| 47 | $this->expectException('GitElephant\Exception\InvalidRepositoryPathException'); |
||
| 48 | $repo = new Repository('non-existent-path'); |
||
|
|
|||
| 49 | |||
| 50 | $repo = Repository::open($this->path); |
||
| 51 | $this->assertInstanceOf('GitElephant\Repository', $repo); |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @covers \GitElephant\Repository::init |
||
| 56 | */ |
||
| 57 | public function testInit() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * testName |
||
| 75 | */ |
||
| 76 | public function testName() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @covers \GitElephant\Repository::stage |
||
| 84 | */ |
||
| 85 | public function testStage() |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @covers \GitElephant\Repository::unstage |
||
| 101 | */ |
||
| 102 | public function testUnstage() |
||
| 103 | { |
||
| 104 | $this->getRepository()->init(); |
||
| 105 | $this->addFile('test'); |
||
| 106 | $this->getRepository()->commit('first commit', true); |
||
| 107 | $this->addFile('test2'); |
||
| 108 | $this->assertCount(1, $this->getRepository()->getStatus()->untracked()); |
||
| 109 | $this->assertCount(0, $this->getRepository()->getStatus()->added()); |
||
| 110 | $this->getRepository()->stage('test2'); |
||
| 111 | $this->assertCount(0, $this->getRepository()->getStatus()->untracked()); |
||
| 112 | $this->assertCount(1, $this->getRepository()->getStatus()->added()); |
||
| 113 | $this->getRepository()->unstage('test2'); |
||
| 114 | $this->assertCount(1, $this->getRepository()->getStatus()->untracked()); |
||
| 115 | $this->assertCount(0, $this->getRepository()->getStatus()->added()); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @covers \GitElephant\Repository::commit |
||
| 120 | * @covers \GitElephant\Repository::getStatusOutput |
||
| 121 | */ |
||
| 122 | public function testCommit() |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @covers \GitElephant\Repository::getStatusOutput |
||
| 150 | */ |
||
| 151 | public function testGetStatus() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @covers \GitElephant\Repository::createBranch |
||
| 165 | */ |
||
| 166 | public function testCreateBranch() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @covers \GitElephant\Repository::deleteBranch |
||
| 177 | */ |
||
| 178 | public function testDeleteBranch() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @covers \GitElephant\Repository::getBranches |
||
| 197 | */ |
||
| 198 | public function testGetBranches() |
||
| 199 | { |
||
| 200 | $this->getRepository()->init(); |
||
| 201 | $this->addFile('test'); |
||
| 202 | $this->getRepository()->stage(); |
||
| 203 | $this->getRepository()->commit('initial import', true); |
||
| 204 | $this->assertCount( |
||
| 205 | 1, |
||
| 206 | $this->getRepository()->getBranches(), |
||
| 207 | 'an initialized repository should have only one branch' |
||
| 208 | ); |
||
| 209 | $this->getRepository()->createBranch('test-branch'); |
||
| 210 | $this->assertCount(2, $this->getRepository()->getBranches(), 'two branches expected'); |
||
| 211 | $branches = $this->getRepository()->getBranches(); |
||
| 212 | /** @var Branch $branch */ |
||
| 213 | $branch = $branches[0]; |
||
| 214 | $this->assertEquals('master', $branch->getName()); |
||
| 215 | $this->getRepository()->deleteBranch('test-branch'); |
||
| 216 | $this->assertCount(1, $this->getRepository()->getBranches(), 'one branch expected'); |
||
| 217 | $this->assertInstanceOf( |
||
| 218 | 'GitElephant\Objects\Branch', |
||
| 219 | $this->getRepository()->getMainBranch(), |
||
| 220 | 'main branch should be an instance of Branch' |
||
| 221 | ); |
||
| 222 | $this->assertTrue( |
||
| 223 | $this->getRepository()->getMainBranch()->getCurrent(), |
||
| 224 | 'getCurrent on main branch should be true' |
||
| 225 | ); |
||
| 226 | $this->assertEquals( |
||
| 227 | 'master', |
||
| 228 | $this->getRepository()->getMainBranch()->getName(), |
||
| 229 | 'main branch should be named "master"' |
||
| 230 | ); |
||
| 231 | $this->assertEquals(['master'], $this->getRepository()->getBranches(true)); |
||
| 232 | $this->getRepository()->createBranch('develop'); |
||
| 233 | $this->assertContains('master', $this->getRepository()->getBranches(true)); |
||
| 234 | $this->assertContains('develop', $this->getRepository()->getBranches(true)); |
||
| 235 | } |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @covers \GitElephant\Repository::getMainBranch |
||
| 239 | */ |
||
| 240 | public function testGetMainBranch() |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @covers \GitElephant\Repository::getBranch |
||
| 250 | */ |
||
| 251 | public function testGetBranch() |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @covers \GitElephant\Repository::merge |
||
| 262 | */ |
||
| 263 | public function testMerge() |
||
| 264 | { |
||
| 265 | $this->getRepository()->init(); |
||
| 266 | $this->addFile('test-file'); |
||
| 267 | $this->getRepository()->commit('test', true); |
||
| 268 | $this->assertEquals(1, count($this->getRepository()->getTree())); |
||
| 269 | $this->getRepository()->createBranch('branch2'); |
||
| 270 | $this->getRepository()->checkout('branch2'); |
||
| 271 | $this->addFile('file2'); |
||
| 272 | $this->getRepository()->commit('test2', true); |
||
| 273 | $this->assertEquals(2, count($this->getRepository()->getTree())); |
||
| 274 | $this->getRepository()->checkout('master'); |
||
| 275 | $this->assertEquals(1, count($this->getRepository()->getTree())); |
||
| 276 | $this->getRepository()->merge($this->getRepository()->getBranch('branch2')); |
||
| 277 | $this->assertEquals(2, count($this->getRepository()->getTree())); |
||
| 278 | |||
| 279 | // attempt to merge a different branch by forcing a 3-way merge and verify the merge commit message |
||
| 280 | $this->getRepository()->createBranch('branch3'); |
||
| 281 | $this->getRepository()->checkout('branch3'); |
||
| 282 | $this->addFile('file3'); |
||
| 283 | $this->getRepository()->commit('test3', true); |
||
| 284 | $this->assertEquals(3, count($this->getRepository()->getTree())); |
||
| 285 | $this->getRepository()->checkout('master'); |
||
| 286 | $this->assertEquals(2, count($this->getRepository()->getTree())); |
||
| 287 | $this->getRepository()->merge($this->getRepository()->getBranch('branch3'), 'test msg', 'no-ff'); |
||
| 288 | $this->assertEquals(3, count($this->getRepository()->getTree())); |
||
| 289 | $this->assertEquals('test msg', $this->getRepository()->getCommit()->getMessage()->getFullMessage()); |
||
| 290 | |||
| 291 | // attempt a fast forward merge where a 3-way is necessary and trap the resulting exception |
||
| 292 | $this->getRepository()->checkout('branch2'); |
||
| 293 | $this->addFile('file4'); |
||
| 294 | $this->getRepository()->commit('test4', true); |
||
| 295 | $this->assertEquals(3, count($this->getRepository()->getTree())); |
||
| 296 | $this->getRepository()->checkout('master'); |
||
| 297 | $this->assertEquals(3, count($this->getRepository()->getTree())); |
||
| 298 | try { |
||
| 299 | $this->getRepository()->merge($this->getRepository()->getBranch('branch2'), '', 'ff-only'); |
||
| 300 | } |
||
| 301 | catch (\RuntimeException $e) { |
||
| 302 | return; |
||
| 303 | } |
||
| 304 | $this->fail("Merge should have produced a runtime exception."); |
||
| 305 | } |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @covers \GitElephant\Repository::getTags |
||
| 309 | * @covers \GitElephant\Repository::getTag |
||
| 310 | * @covers \GitElephant\Repository::createTag |
||
| 311 | * @covers \GitElephant\Repository::deleteTag |
||
| 312 | */ |
||
| 313 | public function testTags() |
||
| 326 | |||
| 327 | /** |
||
| 328 | * test getLastTag |
||
| 329 | */ |
||
| 330 | public function testGetLastTag() |
||
| 331 | { |
||
| 332 | $this->getRepository()->init(); |
||
| 333 | $this->addFile('test-file'); |
||
| 334 | $this->getRepository()->commit('test', true); |
||
| 335 | $this->getRepository()->createTag('0.0.2'); |
||
| 336 | sleep(1); |
||
| 337 | $this->getRepository()->createTag('0.0.4'); |
||
| 338 | sleep(1); |
||
| 339 | $this->getRepository()->createTag('0.0.3'); |
||
| 340 | sleep(1); |
||
| 341 | $this->getRepository()->createTag('0.0.1'); |
||
| 342 | sleep(1); |
||
| 343 | $this->assertEquals(Tag::pick($this->getRepository(), '0.0.1'), $this->getRepository()->getLastTag()); |
||
| 344 | |||
| 345 | $this->getRepository()->createTag('0.0.05'); |
||
| 346 | $this->assertEquals(Tag::pick($this->getRepository(), '0.0.05'), $this->getRepository()->getLastTag()); |
||
| 347 | |||
| 348 | $this->getRepository()->deleteTag(Tag::pick($this->getRepository(), '0.0.05')); |
||
| 349 | $this->assertEquals(Tag::pick($this->getRepository(), '0.0.1'), $this->getRepository()->getLastTag()); |
||
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @covers \GitElephant\Repository::getCommit |
||
| 354 | */ |
||
| 355 | public function testGetCommit() |
||
| 362 | |||
| 363 | public function testGetBranchOrTag() |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @covers \GitElephant\Repository::getObjectLog |
||
| 377 | */ |
||
| 378 | public function testGetObjectLog() |
||
| 379 | { |
||
| 380 | $repo = $this->getRepository(); |
||
| 381 | $repo->init(); |
||
| 382 | |||
| 383 | $this->addFolder('test'); |
||
| 384 | |||
| 385 | $this->addFile('A.txt', 'test'); |
||
| 386 | $repo->commit('added A.txt', true); |
||
| 387 | |||
| 388 | $this->addFile('B.txt', 'test'); |
||
| 389 | $repo->commit('added B.txt', true); |
||
| 390 | |||
| 391 | $this->addFile('C.txt', 'test'); |
||
| 392 | $repo->commit('added C.txt', true); |
||
| 393 | |||
| 394 | $this->addFile('D.txt', 'test'); |
||
| 395 | $repo->commit('added D.txt', true); |
||
| 396 | |||
| 397 | $this->addFile('E.txt', 'test'); |
||
| 398 | $repo->commit('added E.txt', true); |
||
| 399 | |||
| 400 | $tree = $repo->getTree(); |
||
| 401 | $obj = $tree[0]; |
||
| 402 | |||
| 403 | $log = $this->getRepository()->getObjectLog($obj); |
||
| 404 | $this->assertInstanceOf(Log::class, $log); |
||
| 405 | $this->assertEquals(1, $log->count()); |
||
| 406 | |||
| 407 | $log = $this->getRepository()->getObjectLog($obj, null, 10); |
||
| 408 | $this->assertEquals(5, $log->count()); |
||
| 409 | |||
| 410 | $this->assertEquals('added E.txt', $log->first()->getMessage()->toString()); |
||
| 411 | $this->assertEquals('added A.txt', $log->last()->getMessage()->toString()); |
||
| 412 | } |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Test logs on different tree objects |
||
| 416 | * |
||
| 417 | * @covers \GitElephant\Repository::getObjectLog |
||
| 418 | */ |
||
| 419 | public function testGetObjectLogFolders() |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Test logs on different branches |
||
| 457 | * |
||
| 458 | * @covers \GitElephant\Repository::getObjectLog |
||
| 459 | */ |
||
| 460 | public function testGetObjectLogBranches() |
||
| 461 | { |
||
| 462 | $repo = $this->getRepository(); |
||
| 463 | $repo->init(); |
||
| 464 | |||
| 465 | $this->addFolder('A'); |
||
| 466 | $this->addFile('A1.txt', 'A'); |
||
| 467 | $repo->commit('A/A1', true); |
||
| 468 | |||
| 469 | $this->addFile('A2.txt', 'A'); |
||
| 470 | $repo->commit('A/A2', true); |
||
| 471 | |||
| 472 | $repo->createBranch('test-branch'); |
||
| 473 | $repo->checkout('test-branch'); |
||
| 474 | |||
| 475 | $this->addFile('A3.txt', 'A'); |
||
| 476 | $repo->commit('A/A3', true); |
||
| 477 | |||
| 478 | // master branch |
||
| 479 | $repo->checkout('master'); |
||
| 480 | $tree = $repo->getTree(); |
||
| 481 | $dir = $tree[0]; |
||
| 482 | $log = $repo->getObjectLog($dir, null, 10); |
||
| 483 | |||
| 484 | $this->assertEquals(2, $log->count()); |
||
| 485 | $this->assertEquals('A/A2', $log->first()->getMessage()->toString()); |
||
| 486 | |||
| 487 | // test branch |
||
| 488 | $repo->checkout('test-branch'); |
||
| 489 | $tree = $repo->getTree(); |
||
| 490 | $dir = $tree[0]; |
||
| 491 | $log = $repo->getObjectLog($dir, null, 10); |
||
| 492 | |||
| 493 | $this->assertEquals(3, $log->count()); |
||
| 494 | $this->assertEquals('A/A3', $log->first()->getMessage()->toString()); |
||
| 495 | } |
||
| 496 | |||
| 497 | /** |
||
| 498 | * @covers \GitElephant\Repository::getLog |
||
| 499 | */ |
||
| 500 | public function testGetLog() |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @covers \GitElephant\Repository::getLog |
||
| 516 | */ |
||
| 517 | public function testGetLog_for_a_branch() |
||
| 533 | |||
| 534 | /** |
||
| 535 | * @covers \GitElephant\Repository::checkout |
||
| 536 | */ |
||
| 537 | public function testCheckout() |
||
| 547 | |||
| 548 | /** |
||
| 549 | * @covers \GitElephant\Repository::checkout |
||
| 550 | */ |
||
| 551 | public function testCheckoutTag() |
||
| 568 | |||
| 569 | /** |
||
| 570 | * @covers \GitElephant\Repository::getTree |
||
| 571 | * @covers \GitElephant\Objects\Tree |
||
| 572 | */ |
||
| 573 | public function testGetTree() |
||
| 627 | |||
| 628 | /** |
||
| 629 | * @covers \GitElephant\Repository::getDiff |
||
| 630 | */ |
||
| 631 | public function testGetDiff() |
||
| 646 | |||
| 647 | /** |
||
| 648 | * testCloneFrom |
||
| 649 | */ |
||
| 650 | public function testCloneFrom() |
||
| 664 | |||
| 665 | /** |
||
| 666 | * testOutputContent |
||
| 667 | */ |
||
| 668 | public function testOutputContent() |
||
| 679 | |||
| 680 | /** |
||
| 681 | * testMove |
||
| 682 | */ |
||
| 683 | public function testMove() |
||
| 684 | { |
||
| 685 | $this->getRepository()->init(); |
||
| 686 | $this->addFile('foo'); |
||
| 687 | $this->getRepository()->commit('commit 1', true); |
||
| 688 | $this->getRepository()->move('foo', 'bar'); |
||
| 689 | $status = $this->getRepository()->getStatusOutput(); |
||
| 690 | |||
| 691 | $this->assertRegExp('/(.*): foo -> bar/', $status[4]); |
||
| 692 | } |
||
| 693 | |||
| 694 | /** |
||
| 695 | * testRemove |
||
| 696 | */ |
||
| 697 | public function testRemove() |
||
| 698 | { |
||
| 699 | $this->getRepository()->init(); |
||
| 700 | $this->addFile('foo'); |
||
| 701 | $this->getRepository()->commit('commit 1', true); |
||
| 702 | $this->getRepository()->remove('foo'); |
||
| 703 | $status = $this->getRepository()->getStatusOutput(); |
||
| 704 | |||
| 705 | $this->assertRegExp('/(.*): foo/', $status[4]); |
||
| 706 | } |
||
| 707 | |||
| 708 | /** |
||
| 709 | * testCountCommits |
||
| 710 | */ |
||
| 711 | public function testCountCommits() |
||
| 729 | |||
| 730 | /** |
||
| 731 | * testHumanishName |
||
| 732 | */ |
||
| 733 | public function testHumanishName() |
||
| 738 | |||
| 739 | /** |
||
| 740 | * testCreateFromRemote |
||
| 741 | * |
||
| 742 | */ |
||
| 743 | public function testCreateFromRemote() |
||
| 765 | |||
| 766 | /** |
||
| 767 | * testAddRemote |
||
| 768 | */ |
||
| 769 | public function testRemote() |
||
| 781 | |||
| 782 | /** |
||
| 783 | * testFetch, git branch -a should find the branch |
||
| 784 | */ |
||
| 785 | public function testFetch() |
||
| 806 | |||
| 807 | /** |
||
| 808 | * test pull |
||
| 809 | */ |
||
| 810 | public function testPull() |
||
| 825 | |||
| 826 | /** |
||
| 827 | * test pull |
||
| 828 | */ |
||
| 829 | public function testPush() |
||
| 853 | |||
| 854 | public function testRevParse() |
||
| 865 | |||
| 866 | public function testIsBare() |
||
| 881 | |||
| 882 | /** |
||
| 883 | * test add, remove and get global configs |
||
| 884 | * |
||
| 885 | * @covers \GitElephant\Repository::addGlobalConfig |
||
| 886 | * @covers \GitElephant\Repository::getGlobalConfigs |
||
| 887 | * @covers \GitElephant\Repository::removeGlobalConfig |
||
| 888 | */ |
||
| 889 | public function testGlobalConfigs() |
||
| 890 | { |
||
| 891 | $repo = $this->getRepository(); |
||
| 892 | |||
| 893 | $configs = [ |
||
| 894 | 'test1' => true, |
||
| 895 | 'test2' => 1, |
||
| 896 | 'test3' => 'value', |
||
| 897 | ]; |
||
| 898 | $this->assertEmpty($repo->getGlobalConfigs()); |
||
| 899 | |||
| 900 | foreach ($configs as $configName => $configValue) { |
||
| 901 | $repo->addGlobalConfig($configName, $configValue); |
||
| 902 | } |
||
| 903 | $this->assertSame($configs, $repo->getGlobalConfigs()); |
||
| 904 | |||
| 905 | foreach ($configs as $configName => $configValue) { |
||
| 906 | $repo->removeGlobalConfig($configName); |
||
| 907 | } |
||
| 908 | $this->assertEmpty($repo->getGlobalConfigs()); |
||
| 909 | } |
||
| 910 | |||
| 911 | /** |
||
| 912 | * test reset |
||
| 913 | */ |
||
| 914 | public function testResetHard() |
||
| 915 | { |
||
| 916 | $this->initRepository(); |
||
| 917 | $repo = $this->getRepository(); |
||
| 918 | $repo->init(); |
||
| 919 | $this->addFile('file1'); |
||
| 920 | $repo->stage(); |
||
| 921 | $repo->commit('message1'); |
||
| 922 | $headCommit = $repo->getCommit(); |
||
| 923 | $this->addFile('file2'); |
||
| 924 | $repo->stage(); |
||
| 925 | $repo->commit('message2'); |
||
| 926 | |||
| 927 | $this->assertEquals(2, $repo->countCommits()); |
||
| 928 | $repo->reset($headCommit, [ResetCommand::OPTION_HARD]); |
||
| 929 | $this->assertEquals(1, $repo->countCommits()); |
||
| 930 | $this->assertEmpty($repo->getIndexStatus()->added()); |
||
| 931 | } |
||
| 932 | |||
| 933 | /** |
||
| 934 | * test reset |
||
| 935 | */ |
||
| 936 | public function testResetSoft() |
||
| 937 | { |
||
| 938 | $this->initRepository(); |
||
| 939 | $repo = $this->getRepository(); |
||
| 940 | $repo->init(); |
||
| 941 | $this->addFile('file1'); |
||
| 942 | $repo->stage(); |
||
| 943 | $repo->commit('message1'); |
||
| 944 | $headCommit = $repo->getCommit(); |
||
| 945 | $this->addFile('file2'); |
||
| 946 | $repo->stage(); |
||
| 947 | $repo->commit('message2'); |
||
| 948 | |||
| 949 | $this->assertEquals(2, $repo->countCommits()); |
||
| 950 | $repo->reset($headCommit, [ResetCommand::OPTION_SOFT]); |
||
| 951 | $this->assertEquals(1, $repo->countCommits()); |
||
| 952 | $this->assertNotEmpty($repo->getIndexStatus()->added()); |
||
| 953 | } |
||
| 954 | |||
| 955 | /** |
||
| 956 | * test add, remove and get global options |
||
| 957 | * |
||
| 958 | * @covers \GitElephant\Repository::addGlobalOption |
||
| 959 | * @covers \GitElephant\Repository::getGlobalOptions |
||
| 960 | * @covers \GitElephant\Repository::removeGlobalOption |
||
| 961 | */ |
||
| 962 | public function testGlobalOptions() |
||
| 963 | { |
||
| 964 | $repo = $this->getRepository(); |
||
| 965 | |||
| 966 | $options = [ |
||
| 967 | 'test1' => true, |
||
| 968 | 'test2' => 1, |
||
| 969 | 'test3' => 'value', |
||
| 970 | ]; |
||
| 971 | $this->assertEmpty($repo->getGlobalOptions()); |
||
| 972 | |||
| 973 | foreach ($options as $configName => $configValue) { |
||
| 974 | $repo->addGlobalOption($configName, $configValue); |
||
| 975 | } |
||
| 976 | $this->assertSame($options, $repo->getGlobalOptions()); |
||
| 977 | |||
| 978 | foreach ($options as $configName => $configValue) { |
||
| 979 | $repo->removeGlobalOption($configName); |
||
| 980 | } |
||
| 981 | $this->assertEmpty($repo->getGlobalOptions()); |
||
| 982 | } |
||
| 983 | |||
| 984 | /** |
||
| 985 | * test add, remove and get global command arguments |
||
| 986 | * |
||
| 987 | * @covers \GitElephant\Repository::addGlobalCommandArgument |
||
| 988 | * @covers \GitElephant\Repository::getGlobalCommandArguments |
||
| 989 | * @covers \GitElephant\Repository::removeGlobalCommandArgument |
||
| 990 | */ |
||
| 991 | public function testGlobalCommandArguments() |
||
| 992 | { |
||
| 993 | $repo = $this->getRepository(); |
||
| 994 | |||
| 995 | $args = [ |
||
| 996 | true, |
||
| 997 | 1, |
||
| 998 | 'value', |
||
| 999 | ]; |
||
| 1000 | $this->assertEmpty($repo->getGlobalCommandArguments()); |
||
| 1001 | |||
| 1002 | foreach ($args as $configValue) { |
||
| 1003 | $repo->addGlobalCommandArgument($configValue); |
||
| 1004 | } |
||
| 1005 | $this->assertSame($args, $repo->getGlobalCommandArguments()); |
||
| 1006 | |||
| 1007 | foreach ($args as $configValue) { |
||
| 1008 | $repo->removeGlobalCommandArgument($configValue); |
||
| 1009 | } |
||
| 1010 | $this->assertEmpty($repo->getGlobalCommandArguments()); |
||
| 1011 | } |
||
| 1012 | |||
| 1013 | /** |
||
| 1014 | * @covers \GitElephant\Repository::stash |
||
| 1015 | */ |
||
| 1016 | public function testStashThrowsExceptionIfNoCommits() |
||
| 1017 | { |
||
| 1018 | $this->getRepository()->init(); |
||
| 1019 | $this->addFile('test'); |
||
| 1020 | |||
| 1021 | $this->expectException('RuntimeException'); |
||
| 1022 | $this->getRepository()->stash('My stash', true); |
||
| 1023 | } |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * @covers \GitElephant\Repository::stash |
||
| 1027 | */ |
||
| 1028 | public function testStash() |
||
| 1029 | { |
||
| 1030 | $this->getRepository()->init(); |
||
| 1031 | $this->addFile('test'); |
||
| 1032 | $this->getRepository()->commit('Test commit', true); |
||
| 1033 | $this->addFile('test2'); |
||
| 1034 | $this->getRepository()->stash('My stash', true); |
||
| 1035 | $this->assertTrue($this->getRepository()->isClean()); |
||
| 1036 | $stashList = $this->getRepository()->stashList(); |
||
| 1037 | $this->assertEquals(1, preg_match('%My stash%', $stashList[0])); |
||
| 1038 | } |
||
| 1039 | |||
| 1040 | /** |
||
| 1041 | * @covers \GitElephant\Repository::stashList |
||
| 1042 | */ |
||
| 1043 | public function testStashList() |
||
| 1052 | |||
| 1053 | /** |
||
| 1054 | * @covers \GitElephant\Repository::stashShow |
||
| 1055 | */ |
||
| 1056 | public function testStashShow() |
||
| 1065 | |||
| 1066 | /** |
||
| 1067 | * @covers \GitElephant\Repository::stashDrop |
||
| 1068 | */ |
||
| 1069 | public function testStashDrop() |
||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * @covers \GitElephant\Repository::stashPop |
||
| 1082 | */ |
||
| 1083 | public function testStashPop() |
||
| 1094 | |||
| 1095 | /** |
||
| 1096 | * @covers \GitElephant\Repository::stashApply |
||
| 1097 | */ |
||
| 1098 | public function testStashApply() |
||
| 1109 | |||
| 1110 | /** |
||
| 1111 | * @covers \GitElephant\Repository::stashBranch |
||
| 1112 | */ |
||
| 1113 | public function testStashBranch() |
||
| 1123 | |||
| 1124 | /** |
||
| 1125 | * @covers \GitElephant\Repository::stashCreate |
||
| 1126 | */ |
||
| 1127 | public function testStashCreate() |
||
| 1135 | |||
| 1136 | /** |
||
| 1137 | * @covers \GitElephant\Repository::stashCreate |
||
| 1138 | */ |
||
| 1139 | public function testStashClear() |
||
| 1151 | |||
| 1152 | } |
||
| 1153 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.