Skip to content

Commit 4b9314e

Browse files
peter279kGrahamCampbell
authored andcommitted
Enhance exception tests (#148)
1 parent 827384f commit 4b9314e

File tree

8 files changed

+43
-26
lines changed

8 files changed

+43
-26
lines changed

tests/Gitonomy/Git/Tests/AdminTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Gitonomy\Git\Tests;
1414

1515
use Gitonomy\Git\Admin;
16+
use Gitonomy\Git\Exception\RuntimeException;
1617
use Gitonomy\Git\Reference\Branch;
1718
use Gitonomy\Git\Repository;
1819

@@ -148,11 +149,10 @@ public function testCheckInvalidRepository()
148149
$this->assertFalse(Admin::isValidRepository($url));
149150
}
150151

151-
/**
152-
* @expectedException RuntimeException
153-
*/
154152
public function testExistingFile()
155153
{
154+
$this->expectException(RuntimeException::class);
155+
156156
$file = $this->tmpDir.'/test';
157157
touch($file);
158158

tests/Gitonomy/Git/Tests/BlobTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace Gitonomy\Git\Tests;
1414

15+
use Gitonomy\Git\Exception\RuntimeException;
16+
1517
class BlobTest extends AbstractTest
1618
{
1719
const README_FRAGMENT = 'Foo Bar project';
@@ -33,10 +35,11 @@ public function testGetContent($repository)
3335

3436
/**
3537
* @dataProvider provideFoobar
36-
* @expectedException RuntimeException
3738
*/
3839
public function testNotExisting($repository)
3940
{
41+
$this->expectException(RuntimeException::class);
42+
4043
$blob = $repository->getBlob('foobar');
4144
$blob->getContent();
4245
}

tests/Gitonomy/Git/Tests/CommitTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
use Gitonomy\Git\Commit;
1616
use Gitonomy\Git\Diff\Diff;
17+
use Gitonomy\Git\Exception\InvalidArgumentException;
18+
use Gitonomy\Git\Exception\ReferenceNotFoundException;
1719
use Gitonomy\Git\Tree;
1820

1921
class CommitTest extends AbstractTest
@@ -42,12 +44,12 @@ public function testGetHash($repository)
4244

4345
/**
4446
* @dataProvider provideFoobar
45-
*
46-
* @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException
47-
* @expectedExceptionMessage Reference not found: "that-hash-doest-not-exists"
4847
*/
4948
public function testInvalideHashThrowException($repository)
5049
{
50+
$this->expectException(ReferenceNotFoundException::class);
51+
$this->expectExceptionMessage('Reference not found: "that-hash-doest-not-exists"');
52+
5153
new Commit($repository, 'that-hash-doest-not-exists');
5254
}
5355

@@ -241,11 +243,12 @@ public function testGetBodyMessage($repository)
241243
}
242244

243245
/**
244-
* @expectedException InvalidArgumentException
245246
* @dataProvider provideFoobar
246247
*/
247248
public function testGetIncludingBranchesException($repository)
248249
{
250+
$this->expectException(InvalidArgumentException::class);
251+
249252
$commit = $repository->getCommit(self::INITIAL_COMMIT);
250253

251254
$commit->getIncludingBranches(false, false);

tests/Gitonomy/Git/Tests/HooksTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
namespace Gitonomy\Git\Tests;
1414

15+
use Gitonomy\Git\Exception\InvalidArgumentException;
16+
use Gitonomy\Git\Exception\LogicException;
17+
1518
class HooksTest extends AbstractTest
1619
{
1720
private static $symlinkOnWindows = null;
@@ -72,10 +75,11 @@ public function testHas($repository)
7275

7376
/**
7477
* @dataProvider provideFoobar
75-
* @expectedException InvalidArgumentException
7678
*/
7779
public function testGet_InvalidName_ThrowsException($repository)
7880
{
81+
$this->expectException(InvalidArgumentException::class);
82+
7983
$repository->getHooks()->get('foo');
8084
}
8185

@@ -105,10 +109,11 @@ public function testSymlink($repository)
105109

106110
/**
107111
* @dataProvider provideFoobar
108-
* @expectedException LogicException
109112
*/
110113
public function testSymlink_WithExisting_ThrowsLogicException($repository)
111114
{
115+
$this->expectException(LogicException::class);
116+
112117
$this->markAsSkippedIfSymlinkIsMissing();
113118

114119
$file = $this->hookPath($repository, 'target-symlink');
@@ -141,7 +146,7 @@ public function testSet_Existing_ThrowsLogicException($repository)
141146
{
142147
$repository->getHooks()->set('foo', 'bar');
143148

144-
$this->expectException('LogicException');
149+
$this->expectException(LogicException::class);
145150
$repository->getHooks()->set('foo', 'bar');
146151
}
147152

@@ -159,10 +164,11 @@ public function testRemove($repository)
159164

160165
/**
161166
* @dataProvider provideFoobar
162-
* @expectedException LogicException
163167
*/
164168
public function testRemove_NotExisting_ThrowsLogicException($repository)
165169
{
170+
$this->expectException(LogicException::class);
171+
166172
$repository->getHooks()->remove('foo');
167173
}
168174

tests/Gitonomy/Git/Tests/ReferenceTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212

1313
namespace Gitonomy\Git\Tests;
1414

15+
use Gitonomy\Git\Exception\ReferenceNotFoundException;
1516
use Gitonomy\Git\Reference\Branch;
1617
use Gitonomy\Git\Reference\Tag;
1718

1819
class ReferenceTest extends AbstractTest
1920
{
20-
private $references;
21-
2221
/**
2322
* @dataProvider provideEmpty
2423
*/
@@ -59,10 +58,11 @@ public function testHasTag($repository)
5958

6059
/**
6160
* @dataProvider provideFoobar
62-
* @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException
6361
*/
6462
public function testGetBranch_NotExisting_Error($repository)
6563
{
64+
$this->expectException(ReferenceNotFoundException::class);
65+
6666
$repository->getReferences()->getBranch('notexisting');
6767
}
6868

@@ -101,10 +101,11 @@ public function testAnnotatedTag($repository)
101101

102102
/**
103103
* @dataProvider provideFoobar
104-
* @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException
105104
*/
106105
public function testGetTag_NotExisting_Error($repository)
107106
{
107+
$this->expectException(ReferenceNotFoundException::class);
108+
108109
$repository->getReferences()->getTag('notexisting');
109110
}
110111

tests/Gitonomy/Git/Tests/RepositoryTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Gitonomy\Git\Tests;
1414

1515
use Gitonomy\Git\Blob;
16+
use Gitonomy\Git\Exception\RuntimeException;
1617
use Prophecy\Argument;
1718

1819
class RepositoryTest extends AbstractTest
@@ -78,14 +79,15 @@ public function testLoggerOk($repository)
7879

7980
/**
8081
* @dataProvider provideFoobar
81-
* @expectedException RuntimeException
8282
*/
8383
public function testLoggerNOk($repository)
8484
{
8585
if (!interface_exists('Psr\Log\LoggerInterface')) {
8686
$this->markTestSkipped();
8787
}
8888

89+
$this->expectException(RuntimeException::class);
90+
8991
$loggerProphecy = $this->prophesize('Psr\Log\LoggerInterface');
9092
$loggerProphecy
9193
->info(Argument::type('string'))

tests/Gitonomy/Git/Tests/RevisionTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Gitonomy\Git\Tests;
1414

1515
use Gitonomy\Git\Commit;
16+
use Gitonomy\Git\Exception\ReferenceNotFoundException;
1617
use Gitonomy\Git\Log;
1718
use Gitonomy\Git\Revision;
1819

@@ -36,12 +37,13 @@ public function testGetCommit($repository)
3637

3738
/**
3839
* @dataProvider provideFoobar
39-
* @expectedException Gitonomy\Git\Exception\ReferenceNotFoundException
40-
* @expectedExceptionMessage Can not find revision "non-existent-commit"
4140
*/
4241
public function testGetFailingReference($repository)
4342
{
44-
$revision = $repository->getRevision('non-existent-commit')->getCommit();
43+
$this->expectException(ReferenceNotFoundException::class);
44+
$this->expectExceptionMessage('Can not find revision "non-existent-commit"');
45+
46+
$repository->getRevision('non-existent-commit')->getCommit();
4547
}
4648

4749
/**

tests/Gitonomy/Git/Tests/WorkingCopyTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
namespace Gitonomy\Git\Tests;
1414

1515
use Gitonomy\Git\Admin;
16+
use Gitonomy\Git\Exception\LogicException;
17+
use Gitonomy\Git\Exception\RuntimeException;
1618
use Gitonomy\Git\Reference\Branch;
1719

1820
class WorkingCopyTest extends AbstractTest
1921
{
20-
/**
21-
* @expectedException LogicException
22-
*/
2322
public function testNoWorkingCopyInBare()
2423
{
24+
$this->expectException(LogicException::class);
25+
2526
$path = self::createTempDir();
2627
$repo = Admin::init($path, true, self::getOptions());
2728

@@ -70,11 +71,10 @@ public function testDiffPending()
7071
$this->assertCount(1, $diffPending->getFiles());
7172
}
7273

73-
/**
74-
* @expectedException RuntimeException
75-
*/
7674
public function testCheckoutUnexisting()
7775
{
76+
$this->expectException(RuntimeException::class);
77+
7878
self::createFoobarRepository(false)->getWorkingCopy()->checkout('foobar');
7979
}
8080

0 commit comments

Comments
 (0)