Add some tests + phpdoc
This commit is contained in:
parent
3996272cec
commit
623b939df1
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
composer.lock
|
composer.lock
|
||||||
vendor/
|
vendor/
|
||||||
|
docs/
|
||||||
|
@ -7,7 +7,7 @@ It should allow for the image to be displayed in a browser or even a terminal (y
|
|||||||
|
|
||||||
## Why
|
## 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
|
## Usage
|
||||||
|
|
||||||
|
19
phpdoc.dist.xml
Normal file
19
phpdoc.dist.xml
Normal 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>
|
@ -19,6 +19,8 @@ class Fits
|
|||||||
public readonly string $imageBlob;
|
public readonly string $imageBlob;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Construct a Fits object
|
||||||
|
* @param string $path The full path to the FITS file
|
||||||
* @throws InvalidFits, InvalidPath
|
* @throws InvalidFits, InvalidPath
|
||||||
* @todo Check path for reading/writing errors
|
* @todo Check path for reading/writing errors
|
||||||
*/
|
*/
|
||||||
@ -36,6 +38,7 @@ class Fits
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->headerBlock = $this->extractHeader();
|
$this->headerBlock = $this->extractHeader();
|
||||||
|
|
||||||
$this->fitsHeader = new FitsHeader($this->headerBlock);
|
$this->fitsHeader = new FitsHeader($this->headerBlock);
|
||||||
$this->imageBlob = $this->extractImageBlob();
|
$this->imageBlob = $this->extractImageBlob();
|
||||||
}
|
}
|
||||||
@ -67,6 +70,7 @@ class Fits
|
|||||||
*/
|
*/
|
||||||
private function extractHeader(): string
|
private function extractHeader(): string
|
||||||
{
|
{
|
||||||
|
|
||||||
$end = strpos($this->contents, 'END');
|
$end = strpos($this->contents, 'END');
|
||||||
// Determine minimum integer number of blocks including 'END' position
|
// Determine minimum integer number of blocks including 'END' position
|
||||||
$headerEnd = (($end - ($end % 2880)) / 2880 + 1) * 2880;
|
$headerEnd = (($end - ($end % 2880)) / 2880 + 1) * 2880;
|
||||||
|
@ -45,8 +45,10 @@ class FitsHeader
|
|||||||
|
|
||||||
foreach ($filtered as $record) {
|
foreach ($filtered as $record) {
|
||||||
$splitByComment = explode('/', $record);
|
$splitByComment = explode('/', $record);
|
||||||
$comment = isset($splitByComment[1]) ? $splitByComment[1] : null;
|
$comment = $splitByComment[1] ?? null;
|
||||||
[$name, $value] = explode('=', $splitByComment[0]);
|
$keyVal = explode('=', $splitByComment[0]);
|
||||||
|
$name = $keyVal[0];
|
||||||
|
$value = $keyVal[1] ?? '';
|
||||||
|
|
||||||
$keywords[] = new Keyword(
|
$keywords[] = new Keyword(
|
||||||
name : $name,
|
name : $name,
|
||||||
@ -72,7 +74,7 @@ class FitsHeader
|
|||||||
return $keywordsString . $blanks;
|
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
|
public function keyword(string $key): ?Keyword
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ readonly class Keyword
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $name,
|
public string $name,
|
||||||
public string $value,
|
public ?string $value,
|
||||||
public ?string $comment,
|
public ?string $comment,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
24
tests/FitsHeaderTest.php
Normal file
24
tests/FitsHeaderTest.php
Normal 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
16
tests/FitsTest.php
Normal 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
BIN
tests/test_orion.fit
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user