Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate phpunit metadata to attributes
Browse files Browse the repository at this point in the history
tvdijen committed Mar 19, 2024

Unverified

This user has not yet uploaded their public signing key.
1 parent de6b335 commit bc43479
Showing 54 changed files with 245 additions and 144 deletions.
8 changes: 3 additions & 5 deletions tests/Backend/OpenSSLTest.php
Original file line number Diff line number Diff line change
@@ -200,11 +200,9 @@ public function testEncryptOAEPDecryptRSA15(): void
self::$backend->setCipher(C::KEY_TRANSPORT_OAEP);
$ciphertext = self::$backend->encrypt(self::$pubKey, 'Plaintext');
self::$backend->setCipher(C::KEY_TRANSPORT_RSA_1_5);
// As of March 2024 the openssl_decrypt function no longer throws an exception
// $this->expectException(RuntimeException::class);
// $this->expectExceptionMessageMatches('/^Cannot decrypt data:/');
$plaintext = self::$backend->decrypt(self::$privKey, $ciphertext);
$this->assertNotEquals('Plaintext', $plaintext);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessageMatches('/^Cannot decrypt data:/');
self::$backend->decrypt(self::$privKey, $ciphertext);
}


29 changes: 11 additions & 18 deletions tests/CryptoEncoding/PEMBundleTest.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
namespace SimpleSAML\XMLSecurity\Test\CryptoEncoding;

use LogicException;
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XMLSecurity\CryptoEncoding\PEM;
use SimpleSAML\XMLSecurity\CryptoEncoding\PEMBundle;
@@ -14,10 +16,9 @@
use function dirname;

/**
* @group pem
*
* @internal
*/
#[Group('pem')]
class PEMBundleTest extends TestCase
{
private static string $baseDir;
@@ -43,21 +44,19 @@ public function testBundle(): PEMBundle


/**
* @depends testBundle
*
* @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEMBundle $bundle
*/
#[Depends('testBundle')]
public function testAll(PEMBundle $bundle): void
{
$this->assertContainsOnlyInstancesOf(PEM::class, $bundle->all());
}


/**
* @depends testBundle
*
* @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEMBundle $bundle
*/
#[Depends('testBundle')]
public function testFirst(PEMBundle $bundle): void
{
$this->assertInstanceOf(PEM::class, $bundle->first());
@@ -66,10 +65,9 @@ public function testFirst(PEMBundle $bundle): void


/**
* @depends testBundle
*
* @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEMBundle $bundle
*/
#[Depends('testBundle')]
public function testLast(PEMBundle $bundle): void
{
$this->assertInstanceOf(PEM::class, $bundle->last());
@@ -78,21 +76,19 @@ public function testLast(PEMBundle $bundle): void


/**
* @depends testBundle
*
* @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEMBundle $bundle
*/
#[Depends('testBundle')]
public function testCount(PEMBundle $bundle): void
{
$this->assertCount(150, $bundle);
}


/**
* @depends testBundle
*
* @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEMBundle $bundle
*/
#[Depends('testBundle')]
public function testIterator(PEMBundle $bundle): void
{
$values = [];
@@ -104,21 +100,19 @@ public function testIterator(PEMBundle $bundle): void


/**
* @depends testBundle
*
* @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEMBundle $bundle
*/
#[Depends('testBundle')]
public function testString(PEMBundle $bundle): void
{
$this->assertIsString($bundle->string());
}


/**
* @depends testBundle
*
* @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEMBundle $bundle
*/
#[Depends('testBundle')]
public function testToString(PEMBundle $bundle): void
{
$this->assertIsString(strval($bundle));
@@ -168,10 +162,9 @@ public function testLastEmptyFail(): void


/**
* @depends testBundle
*
* @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEMBundle $bundle
*/
#[Depends('testBundle')]
public function testWithPEMs(PEMBundle $bundle): void
{
$bundle = $bundle->withPEMs(new PEM('TEST', 'data'));
14 changes: 6 additions & 8 deletions tests/CryptoEncoding/PEMTest.php
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@

namespace SimpleSAML\XMLSecurity\Test\CryptoEncoding;

use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use SimpleSAML\XMLSecurity\CryptoEncoding\PEM;
@@ -14,10 +16,9 @@
use function file_get_contents;

/**
* @group pem
*
* @internal
*/
#[Group('pem')]
class PEMTest extends TestCase
{
private static string $baseDir;
@@ -51,10 +52,9 @@ public function testFromFile(): PEM


/**
* @depends testFromFile
*
* @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEM $pem
*/
#[Depends('testFromFile')]
public function testType(PEM $pem): void
{
$this->assertEquals(PEM::TYPE_PUBLIC_KEY, $pem->type());
@@ -101,21 +101,19 @@ public function testInvalidFile(): void


/**
* @depends testFromFile
*
* @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEM $pem
*/
#[Depends('testFromFile')]
public function testString(PEM $pem): void
{
$this->assertIsString($pem->string());
}


/**
* @depends testFromFile
*
* @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEM $pem
*/
#[Depends('testFromFile')]
public function testToString(PEM $pem): void
{
$this->assertIsString(strval($pem));
19 changes: 8 additions & 11 deletions tests/Utils/CertificateTest.php
Original file line number Diff line number Diff line change
@@ -4,20 +4,21 @@

namespace SimpleSAML\XMLSecurity\Test\Utils;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
use SimpleSAML\XMLSecurity\Utils\Certificate;

/**
* @covers \SimpleSAML\XMLSecurity\Utils\Certificate
* @package simplesamlphp/xml-security
*/
#[Group('utilities')]
#[CoversClass(Certificate::class)]
final class CertificateTest extends TestCase
{
/**
* @group utilities
* @test
*/
#[Test]
public function testValidStructure(): void
{
$result = Certificate::hasValidStructure(
@@ -32,10 +33,7 @@ public function testValidStructure(): void
}


/**
* @group utilities
* @test
*/
#[Test]
public function testConvertToCertificate(): void
{
$result = Certificate::convertToCertificate(PEMCertificatesMock::getPlainCertificateContents());
@@ -44,8 +42,7 @@ public function testConvertToCertificate(): void
}


/**
*/
#[Test]
public function testParseIssuer(): void
{
// Test string input
3 changes: 2 additions & 1 deletion tests/XML/CustomSignableTest.php
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

namespace SimpleSAML\XMLSecurity\Test\XML;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
@@ -15,9 +16,9 @@
/**
* Class \SimpleSAML\XMLSecurity\Test\XML\CustomSignableTest
*
* @covers \SimpleSAML\XMLSecurity\Test\XML\CustomSignable
* @package simplesamlphp/xml-security
*/
#[CoversClass(CustomSignable::class)]
final class CustomSignableTest extends TestCase
{
use SerializableElementTestTrait;
11 changes: 7 additions & 4 deletions tests/XML/EncryptedCustomTest.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
namespace SimpleSAML\XMLSecurity\Test\XML;

use DOMElement;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmFactory;
@@ -13,19 +14,21 @@
use SimpleSAML\XMLSecurity\Key\PrivateKey;
use SimpleSAML\XMLSecurity\Key\PublicKey;
use SimpleSAML\XMLSecurity\Key\SymmetricKey;
use SimpleSAML\XMLSecurity\Test\XML\EncryptedCustom;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait;
use SimpleSAML\XMLSecurity\XML\EncryptedElementTrait;

use function dirname;

/**
* Class \SimpleSAML\XMLSecurity\Test\XML\EncryptedCustomTest
*
* @covers \SimpleSAML\XMLSecurity\XML\EncryptableElementTrait
* @covers \SimpleSAML\XMLSecurity\XML\EncryptedElementTrait
* @covers \SimpleSAML\XMLSecurity\Test\XML\EncryptedCustom
*
* @package simplesamlphp/xml-security
*/
#[CoversClass(EncryptableElementTrait::class)]
#[CoversClass(EncryptedElementTrait::class)]
#[CoversClass(EncryptedCustom::class)]
class EncryptedCustomTest extends TestCase
{
/** @var \DOMElement */
5 changes: 3 additions & 2 deletions tests/XML/SignableElementTest.php
Original file line number Diff line number Diff line change
@@ -5,13 +5,15 @@
namespace SimpleSAML\XMLSecurity\Test\XML;

use DOMDocument;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\Exception\RuntimeException;
use SimpleSAML\XMLSecurity\Key\PrivateKey;
use SimpleSAML\XMLSecurity\Test\XML\CustomSignable;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
use SimpleSAML\XMLSecurity\XML\ds\KeyInfo;
use SimpleSAML\XMLSecurity\XML\ds\X509Certificate;
@@ -28,10 +30,9 @@
/**
* Class \SimpleSAML\XMLSecurity\Test\XML\SignableElementTest
*
* @covers \SimpleSAML\XMLSecurity\Test\XML\CustomSignable
*
* @package simplesamlphp/xml-security
*/
#[CoversClass(CustomSignable::class)]
final class SignableElementTest extends TestCase
{
use SerializableElementTestTrait;
8 changes: 5 additions & 3 deletions tests/XML/SignedElementTest.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
namespace SimpleSAML\XMLSecurity\Test\XML;

use DOMElement;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
@@ -13,20 +14,21 @@
use SimpleSAML\XMLSecurity\Exception\RuntimeException;
use SimpleSAML\XMLSecurity\Key\PublicKey;
use SimpleSAML\XMLSecurity\Key\X509Certificate;
use SimpleSAML\XMLSecurity\Test\XML\CustomSignable;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
use SimpleSAML\XMLSecurity\XML\ds\Signature;
use SimpleSAML\XMLSecurity\XML\SignedElementTrait;

use function dirname;
use function strval;

/**
* Class \SimpleSAML\XMLSecurity\Test\XML\SignedElementTest
*
* @covers \SimpleSAML\XMLSecurity\XML\SignedElementTrait
* @covers \SimpleSAML\XMLSecurity\Test\XML\CustomSignable
*
* @package simplesamlphp/xml-security
*/
#[CoversClass(SignedElementTrait::class)]
#[CoversClass(CustomSignable::class)]
final class SignedElementTest extends TestCase
{
/** @var \SimpleSAML\XMLSecurity\CryptoEncoding\PEM */
7 changes: 4 additions & 3 deletions tests/XML/ds/CanonicalizationMethodTest.php
Original file line number Diff line number Diff line change
@@ -4,23 +4,24 @@

namespace SimpleSAML\XMLSecurity\Test\XML\ds;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
use SimpleSAML\XMLSecurity\XML\ds\CanonicalizationMethod;

use function dirname;

/**
* Class \SimpleSAML\XMLSecurity\Test\XML\ds\CanonicalizationMethodTest
*
* @covers \SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement
* @covers \SimpleSAML\XMLSecurity\XML\ds\CanonicalizationMethod
*
* @package simplesamlphp/xml-security
*/
#[CoversClass(AbstractDsElement::class)]
#[CoversClass(CanonicalizationMethod::class)]
final class CanonicalizationMethodTest extends TestCase
{
use SchemaValidationTestTrait;
Loading

0 comments on commit bc43479

Please sign in to comment.