diff --git a/.gitignore b/.gitignore index af1f417..8560273 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +.phpunit.result.cache composer.lock /vendor diff --git a/composer.json b/composer.json index 7533371..d5a35e3 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,12 @@ "require": { "php": "^7.4 || ^8.0", "lib-openssl": "*", - "composer/ca-bundle": "^1.2" + "composer/ca-bundle": "^1.2", + "ext-openssl": "*" }, "require-dev": { - "phpunit/phpunit": "^5", + "phpunit/phpunit": "^9.0", "php-vfs/php-vfs": "^1.3" }, diff --git a/phpunit.xml b/phpunit.xml index c0377f3..8b22088 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,8 @@ - + tests/ - - - src - - - \ No newline at end of file + diff --git a/src/Punkstar/Ssl/Certificate.php b/src/Punkstar/Ssl/Certificate.php index 6fa8699..a802287 100644 --- a/src/Punkstar/Ssl/Certificate.php +++ b/src/Punkstar/Ssl/Certificate.php @@ -156,6 +156,10 @@ public function signedBy(Certificate $cert): bool protected function extractCertData($certificate): array { + if (null === $certificate) { + throw new Exception("Unable to extract data from certificate.", Exception::MALFORMED_CERTIFICATE); + } + $parsedData = openssl_x509_parse($certificate); if ($parsedData === false) { diff --git a/src/Punkstar/Ssl/Exception.php b/src/Punkstar/Ssl/Exception.php index 8d327d3..21a58b6 100644 --- a/src/Punkstar/Ssl/Exception.php +++ b/src/Punkstar/Ssl/Exception.php @@ -9,4 +9,4 @@ class Exception extends \Exception const MALFORMED_CERTIFICATE = 2001; const CONNECTION_PROBLEM = 3001; -} \ No newline at end of file +} diff --git a/tests/Punkstar/SslTest/IntegrationTest.php b/tests/Punkstar/SslTest/IntegrationTest.php index b21b860..f94147a 100644 --- a/tests/Punkstar/SslTest/IntegrationTest.php +++ b/tests/Punkstar/SslTest/IntegrationTest.php @@ -16,15 +16,15 @@ public function testExampleCerts($certFileName) $reader = new Reader(); $cert = $reader->readFromFile($certFileName); - $this->assertInternalType('string', $cert->certName()); - $this->assertInternalType('string', $cert->toString()); - $this->assertInternalType('string', (string) $cert); + $this->assertIsString($cert->certName()); + $this->assertIsString($cert->toString()); + $this->assertIsString((string) $cert); $this->assertInstanceOf('DateTime', $cert->validTo()); $this->assertInstanceOf('DateTime', $cert->validFrom()); - $this->assertInternalType('array', $cert->subject()); - $this->assertInternalType('array', $cert->issuer()); - $this->assertInternalType('array', $cert->sans()); - $this->assertInternalType('string', $cert->signatureAlgorithm()); + $this->assertIsArray($cert->subject()); + $this->assertIsArray($cert->issuer()); + $this->assertIsArray($cert->sans()); + $this->assertIsString($cert->signatureAlgorithm()); } /** diff --git a/tests/Punkstar/SslTest/Parser/SanParserTest.php b/tests/Punkstar/SslTest/Parser/SanParserTest.php index 77fbe0c..eb85d9f 100644 --- a/tests/Punkstar/SslTest/Parser/SanParserTest.php +++ b/tests/Punkstar/SslTest/Parser/SanParserTest.php @@ -80,7 +80,7 @@ public function testParse() $sanParser = new SanParser(); $result = $sanParser->parse($input); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertCount(count($output), $result); foreach ($output as $outputItem) { diff --git a/tests/Punkstar/SslTest/ReaderTest.php b/tests/Punkstar/SslTest/ReaderTest.php index 161a241..97a847d 100644 --- a/tests/Punkstar/SslTest/ReaderTest.php +++ b/tests/Punkstar/SslTest/ReaderTest.php @@ -3,6 +3,7 @@ namespace Punkstar\SslTest; use PHPUnit\Framework\TestCase; +use Punkstar\Ssl\Exception; use Punkstar\Ssl\Reader; use VirtualFileSystem\FileSystem; @@ -10,26 +11,28 @@ class ReaderTest extends TestCase { /** * @test - * @expectedException \Punkstar\Ssl\Exception - * @expectedExceptionCode 1001 */ public function testFileNotFound() { + $this->expectException(Exception::class); + $this->expectExceptionCode(1001); + $reader = new Reader(); $reader->readFromFile("idontexist.tstst.stst.stst"); } /** * @test - * @expectedException \Punkstar\Ssl\Exception - * @expectedExceptionCode 2001 */ public function testJunkCert() { + $this->expectException(Exception::class); + $this->expectExceptionCode(2001); + $fs = new FileSystem(); $fs->createFile("/junk.crt", "junk-content"); $reader = new Reader(); $reader->readFromFile($fs->path("/junk.crt")); } -} \ No newline at end of file +}