Skip to content
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
11 changes: 5 additions & 6 deletions src/Parsing/V2/Field/SimpleField.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class SimpleField extends BaseField
{
/**
* @var string | integer | float | boolean | null Value contained in the field.
* @var string|float|boolean|null Value contained in the field.
*/
public $value;

Expand All @@ -20,6 +20,9 @@ public function __construct(array $serverResponse, int $indentLevel = 0)
{
parent::__construct($serverResponse, $indentLevel);
$this->value = array_key_exists('value', $serverResponse) ? $serverResponse['value'] : null;
if (is_int($this->value)) {
$this->value = (float) $this->value;
}
}

/**
Expand All @@ -31,12 +34,8 @@ public function __toString(): string
return $this->value ? 'True' : 'False';
}
if (is_numeric($this->value)) {
$value = (float)$this->value;
return $value == (int)$value ?
number_format($value, 1, '.', '') :
rtrim(rtrim(number_format($value, 5, '.', ''), '0'), '.');
return number_format($this->value, 1, '.', '');
}

return $this->value !== null ? (string)$this->value : '';
}
}
7 changes: 6 additions & 1 deletion tests/Input/URLInputSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,32 @@ protected function setUp(): void
getenv('GITHUB_WORKSPACE') ?: "."
) . "/tests/resources/file_types/";
}

protected function tearDown(): void
{
putenv('MINDEE_API_KEY=' . $this->oldKey);
}

public function testInputFromHTTPShouldNotThrow()
{
$inputDoc = $this->dummyClient->sourceFromUrl("https://example.com/invoice.pdf");
$this->assertInstanceOf(URLInputSource::class, $inputDoc);
}

public function testInputFromHTTPShouldThrow()
{
$this->expectException(MindeeSourceException::class);
$this->dummyClient->sourceFromUrl("http://example.com/invoice.pdf");
new URLInputSource(url: "http://example.com/invoice.pdf");
}

public function testDownloadFileFails(){
$dummyAddress = "addressthatdoesntworkforcipurposes";
$urlSource = $this->dummyClient->sourceFromUrl("https://$dummyAddress");
$this->expectException(MindeeSourceException::class);
$this->expectExceptionMessage("Failed to download file: Could not resolve host: $dummyAddress");
$urlSource->asLocalInputSource("test.pdf");
}

public function testInvalidFileName(){
$urlSource = $this->dummyClient->sourceFromUrl("https://addressthatdoesntworkforcipurposes");
$this->expectException(MindeeSourceException::class);
Expand Down
8 changes: 7 additions & 1 deletion tests/Parsing/V2/InferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ public function testRawTextsMustBeAccessible(): void

$first = $rawText->pages[0];
$this->assertEquals('This is the raw text of the first page...', $first->content);

foreach ($rawText->pages as $page) {
$this->assertEquals('string', gettype($page->content));
}
}

/**
Expand All @@ -305,7 +309,9 @@ public function testCoordinatesAndLocationDataMustBeAccessible(): void
$inference = $response->inference;
$this->assertNotNull($inference);

$dateField = $inference->result->fields->getSimpleField('date');
$fields = $response->inference->result->fields;

$dateField = $fields->getSimpleField('date');
$this->assertCount(1, $dateField->locations);

$location = $dateField->locations[0];
Expand Down
Loading