Skip to content

Commit

Permalink
lift unit test to phpunit:^9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Mitterhauser committed Mar 11, 2024
1 parent db13acc commit 6c16346
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
20 changes: 9 additions & 11 deletions tests/FileVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FileVersionTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$this->tempDir = self::tempdir();
$this->tempDir = $this->tempdir();
file_put_contents($this->tempDir.'/commit.json', json_encode([
'branch' => 'master',
'commit' => '9c9e437'
Expand All @@ -47,28 +47,26 @@ protected function setUp(): void
protected function tearDown(): void
{
parent::tearDown();
self::rmDir($this->tempDir);
$this->rmDir($this->tempDir);
}

/**
* Test retrieving branch and commit from a JSON encoded file.
* @throws \PHPUnit_Framework_AssertionFailedError
* @throws \PHPUnit_Framework_Exception
* @return void
*/
public function testFileVersionRetrieval()
{
$fileVersion = new FileVersion($this->tempDir.'/commit.json');
static::assertInstanceOf(IVersion::class, $fileVersion);
static::assertTrue($fileVersion->exists());
static::assertSame('master', $fileVersion->getBranch());
static::assertSame('9c9e437', $fileVersion->getCommit());
$this->assertInstanceOf(IVersion::class, $fileVersion);
$this->assertTrue($fileVersion->exists());
$this->assertSame('master', $fileVersion->getBranch());
$this->assertSame('9c9e437', $fileVersion->getCommit());
$actual = (string)json_encode($fileVersion);
$expected = (string)json_encode([
'branch' => 'master',
'commit' => '9c9e437'
]);
static::assertJsonStringEqualsJsonString($expected, $actual);
$this->assertJsonStringEqualsJsonString($expected, $actual);
}

/**
Expand All @@ -78,7 +76,7 @@ public function testFileVersionRetrieval()
public function testGettingCommit()
{
$fileVersion = new FileVersion($this->tempDir.'/commit.json');
static::assertSame('9c9e437', $fileVersion->getCommit());
$this->assertSame('9c9e437', $fileVersion->getCommit());
}

/**
Expand All @@ -88,6 +86,6 @@ public function testGettingCommit()
public function testGettingBranch()
{
$fileVersion = new FileVersion($this->tempDir.'/commit.json');
static::assertSame('master', $fileVersion->getBranch());
$this->assertSame('master', $fileVersion->getBranch());
}
}
14 changes: 6 additions & 8 deletions tests/GitVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GitVersionTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$this->tempDir = self::tempdir();
$this->tempDir = $this->tempdir();
mkdir($this->tempDir.'/.git/refs/heads/', 0777, true);
file_put_contents($this->tempDir.'/.git/HEAD', 'ref: refs/heads/master');
file_put_contents($this->tempDir.'/.git/refs/heads/master', '9c9e4373dbd136a4f405a828a9ecf445f207e49c');
Expand All @@ -46,22 +46,20 @@ protected function setUp(): void
protected function tearDown(): void
{
parent::tearDown();
self::rmDir($this->tempDir);
$this->rmDir($this->tempDir);
}

/**
* Test retrieving version information from git.
* @throws \PHPUnit_Framework_AssertionFailedError
* @throws \PHPUnit_Framework_Exception
* @return void
*/
public function testGitVersionRetrieval()
{
$gitVersion = new GitVersion($this->tempDir);
static::assertInstanceOf(IVersion::class, $gitVersion);
static::assertTrue($gitVersion->exists());
static::assertSame('master', $gitVersion->getBranch());
static::assertSame('9c9e437', $gitVersion->getCommit());
$this->assertInstanceOf(IVersion::class, $gitVersion);
$this->assertTrue($gitVersion->exists());
$this->assertSame('master', $gitVersion->getBranch());
$this->assertSame('9c9e437', $gitVersion->getCommit());
$actual = (string)json_encode($gitVersion);
$expected = (string)json_encode([
'branch' => 'master',
Expand Down
28 changes: 12 additions & 16 deletions tests/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class VersionTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$this->tempDir = self::tempdir();
$this->tempDir = $this->tempdir();
file_put_contents($this->tempDir.'/commit.json', json_encode([
'branch' => 'retsam',
'commit' => '765e9c9'
Expand All @@ -52,55 +52,51 @@ protected function setUp(): void
protected function tearDown(): void
{
parent::tearDown();
self::rmDir($this->tempDir);
$this->rmDir($this->tempDir);
}

/**
* Test retrieving the version from the JSON encoded file rather that from the
* git repository.
* @throws \PHPUnit_Framework_AssertionFailedError
* @throws \PHPUnit_Framework_Exception
* @return void
*/
public function testRetrievingFileVersion()
{
$version = new Version();
static::assertInstanceOf(IVersion::class, $version);
$this->assertInstanceOf(IVersion::class, $version);
$version->register(new FileVersion($this->tempDir.'/commit.json'));
//$version->register(new GitVersion($this->tempDir));
static::assertTrue($version->exists());
static::assertSame('retsam', $version->getBranch());
static::assertSame('765e9c9', $version->getCommit());
$this->assertTrue($version->exists());
$this->assertSame('retsam', $version->getBranch());
$this->assertSame('765e9c9', $version->getCommit());
$actual = (string)json_encode($version);
$expected = (string)json_encode([
'branch' => 'retsam',
'commit' => '765e9c9'
]);
static::assertJsonStringEqualsJsonString($expected, $actual);
$this->assertJsonStringEqualsJsonString($expected, $actual);
}


/**
* Test retrieving the version from the git repository rather that from the JSON
* encoded file.
* @throws \PHPUnit_Framework_AssertionFailedError
* @throws \PHPUnit_Framework_Exception
* @return void
*/
public function testRetrievingGitVersion()
{
$version = new Version();
static::assertInstanceOf(IVersion::class, $version);
$this->assertInstanceOf(IVersion::class, $version);
$version->register(new GitVersion($this->tempDir));
$version->register(new FileVersion($this->tempDir.'/commit.json'));
static::assertSame('9c9e437', $version->getCommit());
static::assertTrue($version->exists());
static::assertSame('master', $version->getBranch());
$this->assertSame('9c9e437', $version->getCommit());
$this->assertTrue($version->exists());
$this->assertSame('master', $version->getBranch());
$actual = (string)json_encode($version);
$expected = (string)json_encode([
'branch' => 'master',
'commit' => '9c9e437'
]);
static::assertJsonStringEqualsJsonString($expected, $actual);
$this->assertJsonStringEqualsJsonString($expected, $actual);
}
}

0 comments on commit 6c16346

Please sign in to comment.