From 8ba278bea834407bc8db64a44ad374ea58e85da9 Mon Sep 17 00:00:00 2001 From: misantron Date: Mon, 5 Mar 2018 21:06:09 +0300 Subject: [PATCH] File key get contents test --- src/Signer/Key.php | 2 +- test/unit/Signer/KeyTest.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Signer/Key.php b/src/Signer/Key.php index fb2e8611..b01dff6b 100644 --- a/src/Signer/Key.php +++ b/src/Signer/Key.php @@ -64,7 +64,7 @@ private function readFile($content) throw new InvalidArgumentException('You must inform a valid key file'); } - $content = file_get_contents($file); + $content = @file_get_contents($file); if ($content === false) { throw new InvalidArgumentException('You must inform a valid key file'); } diff --git a/test/unit/Signer/KeyTest.php b/test/unit/Signer/KeyTest.php index 0f75589d..58dd8e82 100644 --- a/test/unit/Signer/KeyTest.php +++ b/test/unit/Signer/KeyTest.php @@ -23,7 +23,10 @@ public function configureRootDir() vfsStream::setup( 'root', null, - ['test.pem' => 'testing'] + [ + 'test.pem' => 'testing', + 'emptyFolder' => [] + ] ); } @@ -70,6 +73,20 @@ public function constructShouldRaiseExceptionWhenFileDoesNotExists() new Key('file://' . vfsStream::url('root/test2.pem')); } + /** + * @test + * + * @expectedException \InvalidArgumentException + * + * @covers Lcobucci\JWT\Signer\Key::__construct + * @covers Lcobucci\JWT\Signer\Key::setContent + * @covers Lcobucci\JWT\Signer\Key::readFile + */ + public function constructShouldRaiseExceptionWhenFileGetContentsFailed() + { + new Key('file://' . vfsStream::url('root/emptyFolder')); + } + /** * @test *