Skip to content

Commit

Permalink
Merge pull request #189 from Yoast/feature/2.x/add-attributes-for-ann…
Browse files Browse the repository at this point in the history
…otations

2.x | Tests: add attributes for annotations
  • Loading branch information
hellofromtonya authored Sep 6, 2024
2 parents da0bf11 + 5cecae1 commit eb2db84
Show file tree
Hide file tree
Showing 41 changed files with 209 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/TestCases/XTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Yoast\PHPUnitPolyfills\TestCases;

use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\Attributes\AfterClass;
use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\Attributes\BeforeClass;
use PHPUnit\Framework\TestCase as PHPUnit_TestCase;
use Yoast\PHPUnitPolyfills\Helpers\AssertAttributeHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;
Expand Down Expand Up @@ -55,6 +59,7 @@ abstract class XTestCase extends PHPUnit_TestCase {
*
* @return void
*/
#[BeforeClass]
public static function setUpFixturesBeforeClass() {
parent::setUpBeforeClass();
}
Expand All @@ -68,6 +73,7 @@ public static function setUpFixturesBeforeClass() {
*
* @return void
*/
#[Before]
protected function setUpFixtures() {
parent::setUp();
}
Expand All @@ -81,6 +87,7 @@ protected function setUpFixtures() {
*
* @return void
*/
#[After]
protected function tearDownFixtures() {
parent::tearDown();
}
Expand All @@ -94,6 +101,7 @@ protected function tearDownFixtures() {
*
* @return void
*/
#[AfterClass]
public static function tearDownFixturesAfterClass() {
parent::tearDownAfterClass();
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Exceptions/InvalidComparisonMethodExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Yoast\PHPUnitPolyfills\Tests\Exceptions;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\Exceptions\InvalidComparisonMethodException;

Expand All @@ -10,6 +11,7 @@
*
* @covers \Yoast\PHPUnitPolyfills\Exceptions\InvalidComparisonMethodException
*/
#[CoversClass( InvalidComparisonMethodException::class )]
final class InvalidComparisonMethodExceptionTest extends TestCase {

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/Helpers/AssertAttributesHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Yoast\PHPUnitPolyfills\Tests\Helpers;

use PHPUnit\Framework\Attributes\CoversClass;
use ReflectionException;
use Yoast\PHPUnitPolyfills\Helpers\AssertAttributeHelper;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
use Yoast\PHPUnitPolyfills\Tests\Helpers\Fixtures\ClassWithProperties;

Expand All @@ -11,6 +13,7 @@
*
* @covers \Yoast\PHPUnitPolyfills\Helpers\AssertAttributeHelper
*/
#[CoversClass( AssertAttributeHelper::class )]
final class AssertAttributesHelperTest extends TestCase {

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Polyfills/AssertClosedResourceBzip2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -15,6 +18,9 @@
*
* @requires extension bz2
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
#[RequiresPhpExtension( 'bz2' )]
final class AssertClosedResourceBzip2Test extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
8 changes: 8 additions & 0 deletions tests/Polyfills/AssertClosedResourceCurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -19,6 +23,10 @@
* @requires extension curl
* @requires PHP < 8.0
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
#[RequiresPhp( '< 8.0' )]
#[RequiresPhpExtension( 'curl' )]
final class AssertClosedResourceCurlTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
4 changes: 4 additions & 0 deletions tests/Polyfills/AssertClosedResourceDirTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -13,6 +15,8 @@
* @covers \Yoast\PHPUnitPolyfills\Helpers\ResourceHelper
* @covers \Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
final class AssertClosedResourceDirTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
8 changes: 8 additions & 0 deletions tests/Polyfills/AssertClosedResourceEnchantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -22,6 +26,10 @@
* @phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated
* @phpcs:disable PHPCompatibility.FunctionUse.RemovedFunctions.enchant_broker_freeDeprecated
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
#[RequiresPhp( '< 8.0' )]
#[RequiresPhpExtension( 'enchant' )]
final class AssertClosedResourceEnchantTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
4 changes: 4 additions & 0 deletions tests/Polyfills/AssertClosedResourceFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -13,6 +15,8 @@
* @covers \Yoast\PHPUnitPolyfills\Helpers\ResourceHelper
* @covers \Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
final class AssertClosedResourceFileTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
8 changes: 8 additions & 0 deletions tests/Polyfills/AssertClosedResourceFinfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -19,6 +23,10 @@
* @requires extension finfo
* @requires PHP < 8.1
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
#[RequiresPhp( '< 8.1' )]
#[RequiresPhpExtension( 'finfo' )]
final class AssertClosedResourceFinfoTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
8 changes: 8 additions & 0 deletions tests/Polyfills/AssertClosedResourceGdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -19,6 +23,10 @@
* @requires extension gd
* @requires PHP < 8.0
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
#[RequiresPhp( '< 8.0' )]
#[RequiresPhpExtension( 'gd' )]
final class AssertClosedResourceGdTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
8 changes: 8 additions & 0 deletions tests/Polyfills/AssertClosedResourceNotResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_AssertionFailedError;
use stdClass;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;

Expand All @@ -15,6 +18,8 @@
* @covers \Yoast\PHPUnitPolyfills\Helpers\ResourceHelper
* @covers \Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
final class AssertClosedResourceNotResourceTest extends TestCase {

use AssertClosedResource;
Expand All @@ -30,6 +35,7 @@ final class AssertClosedResourceNotResourceTest extends TestCase {
*
* @return void
*/
#[DataProvider( 'dataNotResource' )]
public function testAssertIsClosedResource( $value ) {
$pattern = '`^Failed asserting that .+? is of type ["]?resource \(closed\)["]?`s';

Expand Down Expand Up @@ -64,6 +70,7 @@ public function testAssertIsClosedResourceFailsWithCustomMessage() {
*
* @return void
*/
#[DataProvider( 'dataNotResource' )]
public function testAssertIsNotClosedResource( $value ) {
self::assertIsNotClosedResource( $value );
}
Expand Down Expand Up @@ -95,6 +102,7 @@ public function testAssertIsNotClosedResourceFailsWithCustomMessage() {
*
* @return void
*/
#[DataProvider( 'dataNotResource' )]
public function testShouldClosedResourceAssertionBeSkipped( $value ) {
$this->assertFalse( self::shouldClosedResourceAssertionBeSkipped( $value ) );
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Polyfills/AssertClosedResourceProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -13,6 +15,8 @@
* @covers \Yoast\PHPUnitPolyfills\Helpers\ResourceHelper
* @covers \Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
final class AssertClosedResourceProcessTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
8 changes: 8 additions & 0 deletions tests/Polyfills/AssertClosedResourceShmopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -24,6 +28,9 @@
* @phpcs:disable Generic.PHP.DeprecatedFunctions.Deprecated
* @phpcs:disable PHPCompatibility.FunctionUse.RemovedFunctions.shmop_closeDeprecated
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
#[RequiresPhpExtension( 'shmop' )]
final class AssertClosedResourceShmopTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand All @@ -38,6 +45,7 @@ final class AssertClosedResourceShmopTest extends AssertClosedResourceTestCase {
*
* @return void
*/
#[Before]
protected function skipOnIncompatiblePHP() {
if ( \PHP_VERSION_ID < 70000 || \PHP_VERSION_ID >= 80000 ) {
$this->markTestSkipped( 'This test requires PHP 7.x.' );
Expand Down
8 changes: 8 additions & 0 deletions tests/Polyfills/AssertClosedResourceWddxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -22,6 +26,10 @@
* @phpcs:disable PHPCompatibility.FunctionUse.RemovedFunctions.wddx_packet_startRemoved
* @phpcs:disable PHPCompatibility.FunctionUse.RemovedFunctions.wddx_packet_endRemoved
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
#[RequiresPhp( '< 7.4' )]
#[RequiresPhpExtension( 'wddx' )]
final class AssertClosedResourceWddxTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
7 changes: 7 additions & 0 deletions tests/Polyfills/AssertClosedResourceXmlParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

Expand All @@ -20,6 +23,10 @@
* @requires extension libxml
* @requires PHP < 8.0
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
#[RequiresPhp( '< 8.0' )]
#[RequiresPhpExtension( 'libxml' )]
final class AssertClosedResourceXmlParserTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
6 changes: 6 additions & 0 deletions tests/Polyfills/AssertClosedResourceZipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -23,6 +26,9 @@
* @phpcs:disable PHPCompatibility.FunctionUse.RemovedFunctions.zip_closeDeprecated
* @phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
#[RequiresPhpExtension( 'zip' )]
final class AssertClosedResourceZipTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
6 changes: 6 additions & 0 deletions tests/Polyfills/AssertClosedResourceZlibTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Yoast\PHPUnitPolyfills\Tests\Polyfills;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;
use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;

/**
Expand All @@ -15,6 +18,9 @@
*
* @requires extension zlib
*/
#[CoversClass( AssertClosedResource::class )]
#[CoversClass( ResourceHelper::class )]
#[RequiresPhpExtension( 'zlib' )]
final class AssertClosedResourceZlibTest extends AssertClosedResourceTestCase {

use AssertClosedResource;
Expand Down
Loading

0 comments on commit eb2db84

Please sign in to comment.