Add some tests + phpdoc

This commit is contained in:
Nicolò P 2024-12-23 22:19:37 +01:00
parent 3996272cec
commit 623b939df1
9 changed files with 71 additions and 5 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
composer.lock
vendor/
docs/

View File

@ -7,7 +7,7 @@ It should allow for the image to be displayed in a browser or even a terminal (y
## Why
Why not? But seriously, this doesn't make any sense, you should never use it in any circumstance whatsoever! The idea for this terrible endeavour came from [a video by Dylan O'Donnell](https://youtube.com).
Why not? But seriously, this doesn't make any sense, you should never use it in any circumstance whatsoever!
## Usage

19
phpdoc.dist.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/phpDocumentor/phpDocumentor/master/data/xsd/phpdoc.xsd"
>
<paths>
<output>docs/api</output>
<cache>docs/cache</cache>
</paths>
<version number="3.0.0">
<api>
<source dsn=".">
<path>src</path>
</source>
</api>
</version>
</phpdocumentor>

View File

@ -19,6 +19,8 @@ class Fits
public readonly string $imageBlob;
/**
* Construct a Fits object
* @param string $path The full path to the FITS file
* @throws InvalidFits, InvalidPath
* @todo Check path for reading/writing errors
*/
@ -36,6 +38,7 @@ class Fits
}
$this->headerBlock = $this->extractHeader();
$this->fitsHeader = new FitsHeader($this->headerBlock);
$this->imageBlob = $this->extractImageBlob();
}
@ -67,6 +70,7 @@ class Fits
*/
private function extractHeader(): string
{
$end = strpos($this->contents, 'END');
// Determine minimum integer number of blocks including 'END' position
$headerEnd = (($end - ($end % 2880)) / 2880 + 1) * 2880;

View File

@ -45,8 +45,10 @@ class FitsHeader
foreach ($filtered as $record) {
$splitByComment = explode('/', $record);
$comment = isset($splitByComment[1]) ? $splitByComment[1] : null;
[$name, $value] = explode('=', $splitByComment[0]);
$comment = $splitByComment[1] ?? null;
$keyVal = explode('=', $splitByComment[0]);
$name = $keyVal[0];
$value = $keyVal[1] ?? '';
$keywords[] = new Keyword(
name : $name,
@ -72,7 +74,7 @@ class FitsHeader
return $keywordsString . $blanks;
}
/**
* Retrieve a Keyword object base on key name
* Retrieve a Keyword object based on key name
*/
public function keyword(string $key): ?Keyword
{

View File

@ -12,7 +12,7 @@ readonly class Keyword
{
public function __construct(
public string $name,
public string $value,
public ?string $value,
public ?string $comment,
) {}

24
tests/FitsHeaderTest.php Normal file
View File

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class FitsHeaderTest extends TestCase
{
public function testKeywordValue(): void
{
$fits = new Dumbastro\FitsPhp\Fits(__DIR__ . '/test_orion.fit');
$header = new Dumbastro\FitsPhp\FitsHeader($fits->headerBlock);
$this->assertSame(
trim($header->getKeywordValue('BITPIX')),
'16'
);
$this->assertSame(
trim($header->getKeywordValue('NAXIS')),
'3'
);
}
}

16
tests/FitsTest.php Normal file
View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class FitsTest extends TestCase
{
public function testValidatesFits(): void
{
$fits = new Dumbastro\FitsPhp\Fits(__DIR__ . '/test_orion.fit');
$this->assertTrue($fits->validate());
}
}

BIN
tests/test_orion.fit Normal file

Binary file not shown.