Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance exception tests #148

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/Gitonomy/Git/Tests/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion tests/Gitonomy/Git/Tests/BlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Gitonomy\Git\Tests;

use Gitonomy\Git\Exception\RuntimeException;

class BlobTest extends AbstractTest
{
const README_FRAGMENT = 'Foo Bar project';
Expand All @@ -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();
}
Expand Down
11 changes: 7 additions & 4 deletions tests/Gitonomy/Git/Tests/CommitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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);
Expand Down
14 changes: 10 additions & 4 deletions tests/Gitonomy/Git/Tests/HooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
}

Expand All @@ -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');
}

Expand Down
9 changes: 5 additions & 4 deletions tests/Gitonomy/Git/Tests/ReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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');
}

Expand Down
4 changes: 3 additions & 1 deletion tests/Gitonomy/Git/Tests/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Gitonomy\Git\Tests;

use Gitonomy\Git\Blob;
use Gitonomy\Git\Exception\RuntimeException;
use Prophecy\Argument;

class RepositoryTest extends AbstractTest
Expand Down Expand Up @@ -78,14 +79,15 @@ public function testLoggerOk($repository)

/**
* @dataProvider provideFoobar
* @expectedException RuntimeException
*/
public function testLoggerNOk($repository)
{
if (!interface_exists('Psr\Log\LoggerInterface')) {
$this->markTestSkipped();
}

$this->expectException(RuntimeException::class);

$loggerProphecy = $this->prophesize('Psr\Log\LoggerInterface');
$loggerProphecy
->info(Argument::type('string'))
Expand Down
8 changes: 5 additions & 3 deletions tests/Gitonomy/Git/Tests/RevisionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/Gitonomy/Git/Tests/WorkingCopyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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');
}

Expand Down