Skip to content

Commit

Permalink
Update the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tvbeek committed Sep 16, 2021
1 parent 5141d88 commit f89bf13
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/HashFinders/GitFileSystemHashFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace TJVB\GitHash\Tests\HashFinders;

use TJVB\GitHash\Exceptions\GitHashException;
use TJVB\GitHash\HashFinders\GitFileSystemHashFinder;
use TJVB\GitHash\HashFinders\GitProcessCommandHashFinder;
use TJVB\GitHash\Tests\TestCase;
use TJVB\GitHash\Values\GitHash;

Expand Down Expand Up @@ -39,4 +41,34 @@ public function weCanFindAHashFromTheRepositoryRoot(): void
// @TODO work with a fixed git directory to get a fixed hash
$this->assertInstanceOf(GitHash::class, $result);
}

/**
* @test
*/
public function weCantFindAHashIfTheDirectoryDoesntContainAGitDirectory(): void
{
// setup / mock
$this->expectException(GitHashException::class);

// run
$finder = new GitFileSystemHashFinder();
$finder->findHash(__DIR__);

// verify/assert
}

/**
* @test
*/
public function weCantFindAHashIfTheDirectoryIsNotPartOfAGitRepository(): void
{
// setup / mock
$this->expectException(GitHashException::class);

// run
$finder = new GitProcessCommandHashFinder();
$finder->findHash(sys_get_temp_dir());

// verify/assert
}
}
50 changes: 50 additions & 0 deletions tests/HashFinders/GitProcessCommandHashFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace Tjvb\GitHash\Tests\HashFinders;

use TJVB\GitHash\Exceptions\GitHashException;
use TJVB\GitHash\HashFinders\GitFileSystemHashFinder;
use TJVB\GitHash\HashFinders\GitProcessCommandHashFinder;
use TJVB\GitHash\Tests\TestCase;
use TJVB\GitHash\Values\GitHash;

class GitProcessCommandHashFinderTest extends TestCase
{
Expand All @@ -23,4 +26,51 @@ public function weSeeThatTheFinderIsAvailable(): void
// verify/assert
$this->assertTrue($finder->isAvailable());
}

/**
* @test
*/
public function weCanFindAHashFromTheRepositoryRoot(): void
{
// setup / mock

// run
$finder = new GitProcessCommandHashFinder();
$result = $finder->findHash(self::PROJECT_ROOT);

// verify/assert
// @TODO work with a fixed git directory to get a fixed hash
$this->assertInstanceOf(GitHash::class, $result);
}

/**
* @test
*/
public function weCanFindAHashFromASubDirectory(): void
{
// setup / mock

// run
$finder = new GitProcessCommandHashFinder();
$result = $finder->findHash(self::PROJECT_ROOT);

// verify/assert
// @TODO work with a fixed git directory to get a fixed hash
$this->assertInstanceOf(GitHash::class, $result);
}

/**
* @test
*/
public function weCantFindAHashIfTheDirectoryIsNotPartOfAGitRepository(): void
{
// setup / mock
$this->expectException(GitHashException::class);

// run
$finder = new GitProcessCommandHashFinder();
$finder->findHash(sys_get_temp_dir());

// verify/assert
}
}
62 changes: 62 additions & 0 deletions tests/HashFinders/GitShellExecCommandHashFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Tjvb\GitHash\Tests\HashFinders;

use TJVB\GitHash\Exceptions\GitHashException;
use TJVB\GitHash\HashFinders\GitFileSystemHashFinder;
use TJVB\GitHash\HashFinders\GitProcessCommandHashFinder;
use TJVB\GitHash\HashFinders\GitShellExecCommandHashFinder;
use TJVB\GitHash\Tests\TestCase;
use TJVB\GitHash\Values\GitHash;

class GitShellExecCommandHashFinderTest extends TestCase
{

/**
* @test
*/
public function weSeeThatTheFinderIsAvailable(): void
{
// setup / mock

// run
$finder = new GitShellExecCommandHashFinder();

// verify/assert
$this->assertTrue($finder->isAvailable());
}

/**
* @test
*/
public function weCanFindAHashFromTheRepositoryRoot(): void
{
// setup / mock

// run
$finder = new GitShellExecCommandHashFinder();
$result = $finder->findHash(self::PROJECT_ROOT);

// verify/assert
// @TODO work with a fixed git directory to get a fixed hash
$this->assertInstanceOf(GitHash::class, $result);
}

/**
* @test
*/
public function weCanFindAHashFromASubDirectory(): void
{
// setup / mock

// run
$finder = new GitShellExecCommandHashFinder();
$result = $finder->findHash(self::PROJECT_ROOT);

// verify/assert
// @TODO work with a fixed git directory to get a fixed hash
$this->assertInstanceOf(GitHash::class, $result);
}
}

0 comments on commit f89bf13

Please sign in to comment.