Skip to content

Commit

Permalink
Migrate phpunit metadata to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Mar 19, 2024
1 parent 3ebbf83 commit 9f44944
Show file tree
Hide file tree
Showing 22 changed files with 88 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
run: composer install --no-progress --prefer-dist --optimize-autoloader

- name: Check code for hard dependencies missing in composer.json
run: composer-require-checker check composer.json
run: composer-require-checker check --config-file=tools/composer-require-checker.json composer.json

- name: Check code for unused dependencies in composer.json
run: composer-unused
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"simplesamlphp/assert": "^1.1"
},
"require-dev": {
"simplesamlphp/simplesamlphp-test-framework": "^1.5"
"simplesamlphp/simplesamlphp-test-framework": "^1.6"
},
"support": {
"issues": "https://github.com/simplesamlphp/xml-common/issues",
Expand Down
4 changes: 2 additions & 2 deletions src/TestUtils/SchemaValidationTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DOMDocument;
use Exception;
use LibXMLError; // Officially spelled with a lower-case `l`, but that breaks composer-require-checker
use PHPUnit\Framework\Attributes\Depends;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\SchemaViolationException;
use XMLReader;
Expand Down Expand Up @@ -37,9 +38,8 @@ trait SchemaValidationTestTrait

/**
* Test schema validation.
*
* @depends testSerialization
*/
#[Depends('testSerialization')]
public function testSchemaValidation(): void
{
if (!class_exists(self::$testedClass)) {
Expand Down
6 changes: 3 additions & 3 deletions src/TestUtils/SerializableElementTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace SimpleSAML\XML\TestUtils;

use DOMDocument;
use PHPUnit\Framework\Attributes\Depends;

use function class_exists;

Expand Down Expand Up @@ -56,10 +57,9 @@ public function testUnmarshalling(): void

/**
* Test serialization / unserialization.
*
* @depends testMarshalling
* @depends testUnmarshalling
*/
#[Depends('testMarshalling')]
#[Depends('testUnmarshalling')]
public function testSerialization(): void
{
if (!class_exists(self::$testedClass)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Utils/RandomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace SimpleSAML\Test\XML\Utils;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\Utils\Random;

use function strlen;

/**
* Tests for SimpleSAML\XML\Utils\Random.
*
* @covers \SimpleSAML\XML\Utils\Random
*/
#[CoversClass(Random::class)]
class RandomTest extends TestCase
{
/**
Expand Down
7 changes: 4 additions & 3 deletions tests/XML/AbstractElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace SimpleSAML\Test\XML;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Test\XML\Element;
use SimpleSAML\XML\AbstractElement;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\Exception\MissingAttributeException;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
Expand All @@ -16,11 +18,10 @@
/**
* Class \SimpleSAML\XML\AbstractElementTest
*
* @covers \SimpleSAML\XML\TestUtils\SerializableElementTestTrait
* @covers \SimpleSAML\XML\AbstractElement
*
* @package simplesamlphp\xml-common
*/
#[CoversClass(SerializableElementTestTrait::class)]
#[CoversClass(AbstractElement::class)]
final class AbstractElementTest extends TestCase
{
use SerializableElementTestTrait;
Expand Down
6 changes: 3 additions & 3 deletions tests/XML/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace SimpleSAML\Test\XML;

use DOMDocument;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\Attribute;
use SimpleSAML\XML\DOMDocumentFactory;
Expand All @@ -13,11 +14,10 @@
/**
* Class \SimpleSAML\XML\AttributeTest
*
* @covers \SimpleSAML\XML\Attribute
* @covers \SimpleSAML\XML\TestUtils\ArrayizableElementTestTrait
*
* @package simplesamlphp\xml-common
*/
#[CoversClass(ArrayizableElementTestTrait::class)]
#[CoversClass(Attribute::class)]
final class AttributeTest extends TestCase
{
use ArrayizableElementTestTrait;
Expand Down
15 changes: 9 additions & 6 deletions tests/XML/Base64ElementTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

namespace SimpleSAML\Test\XML;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Test\XML\XMLDumper;
use SimpleSAML\XML\Base64ElementTrait;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\StringElementTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;

use function dirname;
Expand All @@ -15,13 +19,12 @@
/**
* Class \SimpleSAML\XML\Base64ElementTraitTest
*
* @covers \SimpleSAML\XML\TestUtils\SerializableElementTestTrait
* @covers \SimpleSAML\XML\Base64ElementTrait
* @covers \SimpleSAML\XML\StringElementTrait
* @covers \SimpleSAML\XML\AbstractElement
*
* @package simplesamlphp\xml-common
*/
#[CoversClass(SerializableElementTestTrait::class)]
#[CoversClass(Base64ElementTrait::class)]
#[CoversClass(StringElementTrait::class)]
#[CoversClass(AbstractElement::class)]
final class Base64ElementTraitTest extends TestCase
{
use SerializableElementTestTrait;
Expand Down Expand Up @@ -65,8 +68,8 @@ public function testUnmarshalling(): void

/**
* @param non-empty-string $xml
* @dataProvider provideBase64Cases
*/
#[DataProvider('provideBase64Cases')]
public function testBase64Cases(string $xml): void
{
$xmlRepresentation = DOMDocumentFactory::fromString($xml);
Expand Down
9 changes: 5 additions & 4 deletions tests/XML/BooleanElementTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace SimpleSAML\Test\XML;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Test\XML\BooleanElement;
use SimpleSAML\XML\BooleanElementTrait;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;

Expand All @@ -15,12 +17,11 @@
/**
* Class \SimpleSAML\XML\BooleanElementTraitTest
*
* @covers \SimpleSAML\XML\TestUtils\SerializableElementTestTrait
* @covers \SimpleSAML\XML\BooleanElementTrait
* @covers \SimpleSAML\XML\AbstractElement
*
* @package simplesamlphp\xml-common
*/
#[CoversClass(SerializableElementTestTrait::class)]
#[CoversClass(BooleanElementTrait::class)]
#[CoversClass(AbstractElement::class)]
final class BooleanElementTraitTest extends TestCase
{
use SerializableElementTestTrait;
Expand Down
6 changes: 3 additions & 3 deletions tests/XML/ChunkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SimpleSAML\Test\XML;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\DOMDocumentFactory;
Expand All @@ -16,11 +17,10 @@
/**
* Class \SimpleSAML\XML\ChunkTest
*
* @covers \SimpleSAML\XML\TestUtils\SerializableElementTestTrait
* @covers \SimpleSAML\XML\Chunk
*
* @package simplesamlphp\xml-common
*/
#[CoversClass(SerializableElementTestTrait::class)]
#[CoversClass(Chunk::class)]
final class ChunkTest extends TestCase
{
use SerializableElementTestTrait;
Expand Down
31 changes: 4 additions & 27 deletions tests/XML/DOMDocumentFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace SimpleSAML\Test\XML;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use SimpleSAML\Assert\AssertionFailedException;
Expand All @@ -13,24 +15,19 @@
use function strval;

/**
* @covers \SimpleSAML\XML\DOMDocumentFactory
* @package simplesamlphp\xml-common
*/
#[CoversClass(DOMDocumentFactory::class)]
#[Group('domdocument')]
final class DOMDocumentFactoryTest extends TestCase
{
/**
* @group domdocument
*/
public function testNotXmlStringRaisesAnException(): void
{
$this->expectException(UnparseableXMLException::class);
DOMDocumentFactory::fromString('this is not xml');
}


/**
* @group domdocument
*/
public function testXmlStringIsCorrectlyLoaded(): void
{
$xml = '<root/>';
Expand All @@ -41,8 +38,6 @@ public function testXmlStringIsCorrectlyLoaded(): void
}


/**
*/
public function testFileThatDoesNotExistIsNotAccepted(): void
{
$this->expectException(RuntimeException::class);
Expand All @@ -51,19 +46,13 @@ public function testFileThatDoesNotExistIsNotAccepted(): void
}


/**
* @group domdocument
*/
public function testFileThatDoesNotContainXMLCannotBeLoaded(): void
{
$this->expectException(RuntimeException::class);
DOMDocumentFactory::fromFile('resources/xml/domdocument_invalid_xml.xml');
}


/**
* @group domdocument
*/
public function testFileWithValidXMLCanBeLoaded(): void
{
$file = 'resources/xml/domdocument_valid_xml.xml';
Expand All @@ -73,9 +62,6 @@ public function testFileWithValidXMLCanBeLoaded(): void
}


/**
* @group domdocument
*/
public function testFileThatContainsDocTypeIsNotAccepted(): void
{
$file = 'resources/xml/domdocument_doctype.xml';
Expand All @@ -87,9 +73,6 @@ public function testFileThatContainsDocTypeIsNotAccepted(): void
}


/**
* @group domdocument
*/
public function testStringThatContainsDocTypeIsNotAccepted(): void
{
$xml = '<!DOCTYPE foo [<!ELEMENT foo ANY > <!ENTITY xxe SYSTEM "file:///dev/random" >]><foo />';
Expand All @@ -101,9 +84,6 @@ public function testStringThatContainsDocTypeIsNotAccepted(): void
}


/**
* @group domdocument
*/
public function testEmptyFileIsNotValid(): void
{
$file = 'resources/xml/domdocument_empty.xml';
Expand All @@ -113,9 +93,6 @@ public function testEmptyFileIsNotValid(): void
}


/**
* @group domdocument
*/
public function testEmptyStringIsNotValid(): void
{
$this->expectException(AssertionFailedException::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/XML/Exception/IOExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace SimpleSAML\Test\XML;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\Exception\IOException;

/**
* Empty shell class for testing IOException.
*
* @package simplesaml/xml-security
*
* @covers \SimpleSAML\XML\Exception\IOException
*/
#[CoversClass(IOException::class)]
final class IOExceptionTest extends TestCase
{
/**
Expand Down
4 changes: 2 additions & 2 deletions tests/XML/Exception/UnparseableXMLExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
namespace SimpleSAML\Test\XML;

use LibXMLError;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\Exception\UnparseableXMLException;

/**
* Empty shell class for testing UnparseableXMLException.
*
* @package simplesaml/xml-security
*
* @covers \SimpleSAML\XML\Exception\UnparseableXMLException
*/
#[CoversClass(UnparseableXMLException::class)]
final class UnparseableXMLExceptionTest extends TestCase
{
/** @var \LibXMLError $libxmlerror */
Expand Down
6 changes: 3 additions & 3 deletions tests/XML/ExtendableAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SimpleSAML\Test\XML;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Test\XML\ExtendableAttributesElement;
use SimpleSAML\XML\Attribute;
Expand All @@ -16,11 +17,10 @@
/**
* Class \SimpleSAML\XML\ExtendableAttributesTest
*
* @covers \SimpleSAML\XML\TestUtils\SchemaValidationTestTrait
* @covers \SimpleSAML\XML\TestUtils\SerializableElementTestTrait
*
* @package simplesamlphp\xml-common
*/
#[CoversClass(SchemaValidationTestTrait::class)]
#[CoversClass(SerializableElementTestTrait::class)]
final class ExtendableAttributesTest extends TestCase
{
use SchemaValidationTestTrait;
Expand Down
Loading

0 comments on commit 9f44944

Please sign in to comment.