Skip to content

Commit 866b651

Browse files
throw exception when rates file contains content that could not be unserialized
1 parent e218a03 commit 866b651

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151

5252
- name: "Install dependencies with Composer"
5353
uses: "ramsey/composer-install@v2"
54+
5455
- name: "Run PHPUnit"
5556
run: "vendor/bin/phpunit"
5657

phpunit.xml.dist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
beStrictAboutOutputDuringTests="true"
66
bootstrap="vendor/autoload.php"
77
colors="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
8+
convertErrorsToExceptions="false"
9+
convertNoticesToExceptions="false"
10+
convertWarningsToExceptions="false"
1111
failOnRisky="true"
1212
failOnWarning="true"
1313
processIsolation="false"

src/Rates.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ private function loadFromFile()
7575
]
7676
]);
7777

78-
if (is_array($data)) {
79-
$this->rates = $data;
78+
if (false === is_array($data)) {
79+
throw new Exception("Unserializable file content");
8080
}
81+
82+
$this->rates = $data;
8183
}
8284

8385
private function loadFromRemote()

tests/RatesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testRatesAreLoadedFromFile()
8686
// test by invalidating file and testing for exception
8787
file_put_contents('vendor/rates', 'foobar');
8888
$rates = new Rates('vendor/rates', 30, $client);
89-
$this->expectError(Error::class);
89+
$this->expectException(Exception::class);
9090
$this->assertEquals(21.0, $rates->getRateForCountry('NL'));
9191
}
9292

0 commit comments

Comments
 (0)