diff --git a/tests/Gitonomy/Git/Tests/AdminTest.php b/tests/Gitonomy/Git/Tests/AdminTest.php index cf7937f..7234bdf 100644 --- a/tests/Gitonomy/Git/Tests/AdminTest.php +++ b/tests/Gitonomy/Git/Tests/AdminTest.php @@ -13,6 +13,7 @@ namespace Gitonomy\Git\Tests; use Gitonomy\Git\Admin; +use Gitonomy\Git\Exception\RuntimeException; use Gitonomy\Git\Reference\Branch; use Gitonomy\Git\Repository; @@ -148,11 +149,10 @@ public function testCheckInvalidRepository() $this->assertFalse(Admin::isValidRepository($url)); } - /** - * @expectedException RuntimeException - */ public function testExistingFile() { + $this->expectException(RuntimeException::class); + $file = $this->tmpDir.'/test'; touch($file); diff --git a/tests/Gitonomy/Git/Tests/BlobTest.php b/tests/Gitonomy/Git/Tests/BlobTest.php index 8dbe271..36b1d58 100644 --- a/tests/Gitonomy/Git/Tests/BlobTest.php +++ b/tests/Gitonomy/Git/Tests/BlobTest.php @@ -12,6 +12,8 @@ namespace Gitonomy\Git\Tests; +use Gitonomy\Git\Exception\RuntimeException; + class BlobTest extends AbstractTest { const README_FRAGMENT = 'Foo Bar project'; @@ -33,10 +35,11 @@ public function testGetContent($repository) /** * @dataProvider provideFoobar - * @expectedException RuntimeException */ public function testNotExisting($repository) { + $this->expectException(RuntimeException::class); + $blob = $repository->getBlob('foobar'); $blob->getContent(); } diff --git a/tests/Gitonomy/Git/Tests/CommitTest.php b/tests/Gitonomy/Git/Tests/CommitTest.php index bd2e918..bb4b275 100644 --- a/tests/Gitonomy/Git/Tests/CommitTest.php +++ b/tests/Gitonomy/Git/Tests/CommitTest.php @@ -14,6 +14,8 @@ use Gitonomy\Git\Commit; use Gitonomy\Git\Diff\Diff; +use Gitonomy\Git\Exception\InvalidArgumentException; +use Gitonomy\Git\Exception\ReferenceNotFoundException; use Gitonomy\Git\Tree; class CommitTest extends AbstractTest @@ -42,12 +44,12 @@ public function testGetHash($repository) /** * @dataProvider provideFoobar - * - * @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException - * @expectedExceptionMessage Reference not found: "that-hash-doest-not-exists" */ public function testInvalideHashThrowException($repository) { + $this->expectException(ReferenceNotFoundException::class); + $this->expectExceptionMessage('Reference not found: "that-hash-doest-not-exists"'); + new Commit($repository, 'that-hash-doest-not-exists'); } @@ -241,11 +243,12 @@ public function testGetBodyMessage($repository) } /** - * @expectedException InvalidArgumentException * @dataProvider provideFoobar */ public function testGetIncludingBranchesException($repository) { + $this->expectException(InvalidArgumentException::class); + $commit = $repository->getCommit(self::INITIAL_COMMIT); $commit->getIncludingBranches(false, false); diff --git a/tests/Gitonomy/Git/Tests/HooksTest.php b/tests/Gitonomy/Git/Tests/HooksTest.php index f08901e..e3478c7 100644 --- a/tests/Gitonomy/Git/Tests/HooksTest.php +++ b/tests/Gitonomy/Git/Tests/HooksTest.php @@ -12,6 +12,9 @@ namespace Gitonomy\Git\Tests; +use Gitonomy\Git\Exception\InvalidArgumentException; +use Gitonomy\Git\Exception\LogicException; + class HooksTest extends AbstractTest { private static $symlinkOnWindows = null; @@ -72,10 +75,11 @@ public function testHas($repository) /** * @dataProvider provideFoobar - * @expectedException InvalidArgumentException */ public function testGet_InvalidName_ThrowsException($repository) { + $this->expectException(InvalidArgumentException::class); + $repository->getHooks()->get('foo'); } @@ -105,10 +109,11 @@ public function testSymlink($repository) /** * @dataProvider provideFoobar - * @expectedException LogicException */ public function testSymlink_WithExisting_ThrowsLogicException($repository) { + $this->expectException(LogicException::class); + $this->markAsSkippedIfSymlinkIsMissing(); $file = $this->hookPath($repository, 'target-symlink'); @@ -141,7 +146,7 @@ public function testSet_Existing_ThrowsLogicException($repository) { $repository->getHooks()->set('foo', 'bar'); - $this->expectException('LogicException'); + $this->expectException(LogicException::class); $repository->getHooks()->set('foo', 'bar'); } @@ -159,10 +164,11 @@ public function testRemove($repository) /** * @dataProvider provideFoobar - * @expectedException LogicException */ public function testRemove_NotExisting_ThrowsLogicException($repository) { + $this->expectException(LogicException::class); + $repository->getHooks()->remove('foo'); } diff --git a/tests/Gitonomy/Git/Tests/ReferenceTest.php b/tests/Gitonomy/Git/Tests/ReferenceTest.php index b1ebcfa..d1c00fc 100644 --- a/tests/Gitonomy/Git/Tests/ReferenceTest.php +++ b/tests/Gitonomy/Git/Tests/ReferenceTest.php @@ -12,13 +12,12 @@ namespace Gitonomy\Git\Tests; +use Gitonomy\Git\Exception\ReferenceNotFoundException; use Gitonomy\Git\Reference\Branch; use Gitonomy\Git\Reference\Tag; class ReferenceTest extends AbstractTest { - private $references; - /** * @dataProvider provideEmpty */ @@ -59,10 +58,11 @@ public function testHasTag($repository) /** * @dataProvider provideFoobar - * @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException */ public function testGetBranch_NotExisting_Error($repository) { + $this->expectException(ReferenceNotFoundException::class); + $repository->getReferences()->getBranch('notexisting'); } @@ -101,10 +101,11 @@ public function testAnnotatedTag($repository) /** * @dataProvider provideFoobar - * @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException */ public function testGetTag_NotExisting_Error($repository) { + $this->expectException(ReferenceNotFoundException::class); + $repository->getReferences()->getTag('notexisting'); } diff --git a/tests/Gitonomy/Git/Tests/RepositoryTest.php b/tests/Gitonomy/Git/Tests/RepositoryTest.php index d86dc84..6eee0e6 100644 --- a/tests/Gitonomy/Git/Tests/RepositoryTest.php +++ b/tests/Gitonomy/Git/Tests/RepositoryTest.php @@ -13,6 +13,7 @@ namespace Gitonomy\Git\Tests; use Gitonomy\Git\Blob; +use Gitonomy\Git\Exception\RuntimeException; use Prophecy\Argument; class RepositoryTest extends AbstractTest @@ -78,7 +79,6 @@ public function testLoggerOk($repository) /** * @dataProvider provideFoobar - * @expectedException RuntimeException */ public function testLoggerNOk($repository) { @@ -86,6 +86,8 @@ public function testLoggerNOk($repository) $this->markTestSkipped(); } + $this->expectException(RuntimeException::class); + $loggerProphecy = $this->prophesize('Psr\Log\LoggerInterface'); $loggerProphecy ->info(Argument::type('string')) diff --git a/tests/Gitonomy/Git/Tests/RevisionTest.php b/tests/Gitonomy/Git/Tests/RevisionTest.php index 1ffb94a..8471184 100644 --- a/tests/Gitonomy/Git/Tests/RevisionTest.php +++ b/tests/Gitonomy/Git/Tests/RevisionTest.php @@ -13,6 +13,7 @@ namespace Gitonomy\Git\Tests; use Gitonomy\Git\Commit; +use Gitonomy\Git\Exception\ReferenceNotFoundException; use Gitonomy\Git\Log; use Gitonomy\Git\Revision; @@ -36,12 +37,13 @@ public function testGetCommit($repository) /** * @dataProvider provideFoobar - * @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException - * @expectedExceptionMessage Can not find revision "non-existent-commit" */ public function testGetFailingReference($repository) { - $revision = $repository->getRevision('non-existent-commit')->getCommit(); + $this->expectException(ReferenceNotFoundException::class); + $this->expectExceptionMessage('Can not find revision "non-existent-commit"'); + + $repository->getRevision('non-existent-commit')->getCommit(); } /** diff --git a/tests/Gitonomy/Git/Tests/WorkingCopyTest.php b/tests/Gitonomy/Git/Tests/WorkingCopyTest.php index 891ac7f..dfa048f 100644 --- a/tests/Gitonomy/Git/Tests/WorkingCopyTest.php +++ b/tests/Gitonomy/Git/Tests/WorkingCopyTest.php @@ -13,15 +13,16 @@ namespace Gitonomy\Git\Tests; use Gitonomy\Git\Admin; +use Gitonomy\Git\Exception\LogicException; +use Gitonomy\Git\Exception\RuntimeException; use Gitonomy\Git\Reference\Branch; class WorkingCopyTest extends AbstractTest { - /** - * @expectedException LogicException - */ public function testNoWorkingCopyInBare() { + $this->expectException(LogicException::class); + $path = self::createTempDir(); $repo = Admin::init($path, true, self::getOptions()); @@ -70,11 +71,10 @@ public function testDiffPending() $this->assertCount(1, $diffPending->getFiles()); } - /** - * @expectedException RuntimeException - */ public function testCheckoutUnexisting() { + $this->expectException(RuntimeException::class); + self::createFoobarRepository(false)->getWorkingCopy()->checkout('foobar'); }