Skip to content

Commit 7d5c2ff

Browse files
Allow empty shortname in search results (#63)
1 parent 7256169 commit 7d5c2ff

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/ResultDecoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ResultDecoder
2323
public const HISTORICAL_DATA_HEADER_LINE = ['Date', 'Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume'];
2424
public const DIVIDEND_DATA_HEADER_LINE = ['Date', 'Dividends'];
2525
public const SPLIT_DATA_HEADER_LINE = ['Date', 'Stock Splits'];
26-
public const SEARCH_RESULT_FIELDS = ['symbol', 'shortname', 'exchange', 'quoteType', 'exchDisp', 'typeDisp'];
26+
public const SEARCH_RESULT_FIELDS = ['symbol', 'exchange', 'quoteType', 'exchDisp', 'typeDisp'];
2727

2828
public const OPTION_CHAIN_FIELDS_MAP = [
2929
'underlyingSymbol' => ValueMapperInterface::TYPE_STRING,
@@ -154,7 +154,7 @@ private function createSearchResultFromJson(array $json): SearchResult
154154

155155
return new SearchResult(
156156
$json['symbol'],
157-
$json['shortname'],
157+
$json['shortname'] ?? null,
158158
$json['exchange'],
159159
$json['quoteType'],
160160
$json['exchDisp'],

tests/Unit/ResultDecoderTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,39 @@ public function transformSearchResult_jsonWithMissedFieldGiven_createSearchResul
514514
$this->resultDecoder->transformSearchResult(json_encode($jsonArray));
515515
}
516516

517+
#[Test]
518+
public function transformSearchResult_jsonWithoutShortname_createSearchResultWithNullShortname(): void
519+
{
520+
$jsonArray = [
521+
'quotes' => [
522+
[
523+
'symbol' => 'AAPL',
524+
'exchange' => 'NMS',
525+
'quoteType' => 'EQUITY',
526+
'exchDisp' => 'NASDAQ',
527+
'typeDisp' => 'Equity',
528+
// shortname is intentionally missing
529+
],
530+
],
531+
];
532+
533+
$returnedResult = $this->resultDecoder->transformSearchResult(json_encode($jsonArray));
534+
535+
$this->assertIsArray($returnedResult);
536+
$this->assertCount(1, $returnedResult);
537+
$this->assertContainsOnlyInstancesOf(SearchResult::class, $returnedResult);
538+
539+
$expectedItem = new SearchResult(
540+
'AAPL',
541+
null, // shortname should be null
542+
'NMS',
543+
'EQUITY',
544+
'NASDAQ',
545+
'Equity'
546+
);
547+
$this->assertEquals($expectedItem, $returnedResult[0]);
548+
}
549+
517550
#[Test]
518551
#[DataProvider('provideTransformQuotesInvalidResult')]
519552
public function transformOptionChains_jsonGiven_createArrayOfInvalidResult(array $responseBody): void

0 commit comments

Comments
 (0)