Skip to content

Commit

Permalink
File key get contents test
Browse files Browse the repository at this point in the history
  • Loading branch information
misantron authored and lcobucci committed Jul 29, 2018
1 parent 92a07a1 commit 8ba278b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Signer/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
19 changes: 18 additions & 1 deletion test/unit/Signer/KeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public function configureRootDir()
vfsStream::setup(
'root',
null,
['test.pem' => 'testing']
[
'test.pem' => 'testing',
'emptyFolder' => []
]
);
}

Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 8ba278b

Please sign in to comment.