Skip to content

Commit f95136f

Browse files
Added test for unparsable date sent to constructor.
1 parent 8cbbe8a commit f95136f

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

src/ClientDailyPriceFixedIncome.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace DPRMC\InteractiveData;
33

44
use DPRMC\CUSIP;
5+
use DPRMC\InteractiveData\RemotePlusClient\Exceptions\UnparsableDateSentToConstructor;
56

67
/**
78
* Class ClientDailyPriceFixedIncome
@@ -53,16 +54,11 @@ public function __construct( $user, $pass, $date, $cusips, $debug = FALSE ) {
5354
*/
5455
protected function formatDateForRemotePlus( $date ) {
5556
$strTime = strtotime( $date );
56-
if ( $strTime === FALSE ) {
57-
throw new \Exception( "We could not parse the date you sent to the constructor: [" . $date . "]" );
58-
}
59-
57+
if ( $strTime === FALSE ):
58+
throw new UnparsableDateSentToConstructor( "We could not parse the date you sent to the constructor: [" . $date . "]" );
59+
endif;
6060
$date = date( 'Ymd', $strTime );
6161

62-
if ( $date === FALSE ) {
63-
throw new \Exception( "We were unable to format this timestamp into something Remote Plus can read: [" . $strTime . "]" );
64-
}
65-
6662
return $date;
6763
}
6864

@@ -76,13 +72,13 @@ protected function formatDateForRemotePlus( $date ) {
7672
*/
7773
protected function pruneInvalidCusips( $cusips ) {
7874
$validCusips = [];
79-
foreach ( $cusips as $cusip ) {
80-
if ( CUSIP::isCUSIP( $cusip ) ) {
75+
foreach ( $cusips as $cusip ):
76+
if ( CUSIP::isCUSIP( $cusip ) ):
8177
$validCusips[] = $cusip;
82-
} else {
78+
else:
8379
$this->invalidCusips[] = $cusip;
84-
}
85-
}
80+
endif;
81+
endforeach;
8682

8783
return $validCusips;
8884
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace DPRMC\InteractiveData\RemotePlusClient\Exceptions;
3+
4+
use Exception;
5+
6+
class UnparsableDateSentToConstructor extends Exception {
7+
8+
}

tests/ClientDailyPriceFixedIncomeTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
namespace DPRMC\InteractiveData\RemotePlusClient\Tests;
33

44
use DPRMC\InteractiveData\ClientDailyPriceFixedIncome;
5+
use DPRMC\InteractiveData\RemotePlusClient\Exceptions\UnparsableDateSentToConstructor;
56
use GuzzleHttp\Exception\ClientException;
67
use PHPUnit\Framework\TestCase;
78

89
class ClientDailyPriceFixedIncomeTest extends TestCase {
910

10-
public function testConstruct() {
11+
public function testConstructor() {
1112
$client = new ClientDailyPriceFixedIncome( 'user', 'pass', '2017-07-31', [ '38259P508' ], FALSE );
1213
$this->assertInstanceOf( ClientDailyPriceFixedIncome::class, $client );
1314
}
1415

16+
public function testConstructorWithUnparsableDate() {
17+
$this->expectException( UnparsableDateSentToConstructor::class );
18+
new ClientDailyPriceFixedIncome( 'user', 'pass', 'this is not a date', [ '38259P508' ], FALSE );
19+
}
20+
1521
public function testRunWithInvalidCredentials() {
1622
$this->expectException( ClientException::class );
1723
$client = new ClientDailyPriceFixedIncome( 'user', 'pass', '2017-07-31', [ '38259P508' ], FALSE );

0 commit comments

Comments
 (0)