Skip to content

Commit

Permalink
ensure compatibility with PHPUnit 12
Browse files Browse the repository at this point in the history
The @after, @before and @dataProvider annotations are deprecated since
PHPUnit 11. Since PHPUnit 10 one can use attributes to configure metadata
instead.
  • Loading branch information
xabbuh committed Sep 5, 2024
1 parent 824633c commit c2bbdc5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/CachePoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

namespace Cache\IntegrationTests;

use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
Expand All @@ -35,6 +39,7 @@ abstract public function createCachePool();
/**
* @before
*/
#[Before]
public function setupService()
{
$this->cache = $this->createCachePool();
Expand All @@ -43,6 +48,7 @@ public function setupService()
/**
* @after
*/
#[After]
public function tearDownService()
{
if ($this->cache !== null) {
Expand Down Expand Up @@ -488,6 +494,7 @@ public function testCommit()
/**
* @medium
*/
#[Group('medium')]
public function testExpiration()
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand Down Expand Up @@ -567,6 +574,7 @@ public function testKeyLength()
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testGetItemInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -580,6 +588,7 @@ public function testGetItemInvalidKeys($key)
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testGetItemsInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -593,6 +602,7 @@ public function testGetItemsInvalidKeys($key)
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testHasItemInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -606,6 +616,7 @@ public function testHasItemInvalidKeys($key)
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testDeleteItemInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -619,6 +630,7 @@ public function testDeleteItemInvalidKeys($key)
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testDeleteItemsInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand Down Expand Up @@ -857,6 +869,7 @@ public function testSavingObject()
/**
* @medium
*/
#[Group('medium')]
public function testHasItemReturnsFalseWhenDeferredItemIsExpired()
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand Down
4 changes: 4 additions & 0 deletions src/HierarchicalCachePoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Cache\IntegrationTests;

use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemPoolInterface;

Expand All @@ -37,6 +39,7 @@ abstract public function createCachePool();
/**
* @before
*/
#[Before]
public function setupService()
{
$this->cache = $this->createCachePool();
Expand All @@ -45,6 +48,7 @@ public function setupService()
/**
* @after
*/
#[After]
public function tearDownService()
{
if ($this->cache !== null) {
Expand Down
21 changes: 21 additions & 0 deletions src/SimpleCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

namespace Cache\IntegrationTests;

use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Psr\SimpleCache\CacheInterface;

Expand Down Expand Up @@ -49,6 +53,7 @@ public function advanceTime($seconds)
/**
* @before
*/
#[Before]
public function setupService()
{
$this->cache = $this->createSimpleCache();
Expand All @@ -57,6 +62,7 @@ public function setupService()
/**
* @after
*/
#[After]
public function tearDownService()
{
if ($this->cache !== null) {
Expand Down Expand Up @@ -171,6 +177,7 @@ public function testSet()
/**
* @medium
*/
#[Group('medium')]
public function testSetTtl()
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand Down Expand Up @@ -269,6 +276,7 @@ public function testSetMultipleWithIntegerArrayKey()
/**
* @medium
*/
#[Group('medium')]
public function testSetMultipleTtl()
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand Down Expand Up @@ -441,6 +449,7 @@ public function testBasicUsageWithLongKey()
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testGetInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -454,6 +463,7 @@ public function testGetInvalidKeys($key)
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testGetMultipleInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -477,6 +487,7 @@ public function testGetMultipleNoIterable()
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testSetInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -490,6 +501,7 @@ public function testSetInvalidKeys($key)
/**
* @dataProvider invalidArrayKeys
*/
#[DataProvider('invalidArrayKeys')]
public function testSetMultipleInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand Down Expand Up @@ -518,6 +530,7 @@ public function testSetMultipleNoIterable()
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testHasInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -531,6 +544,7 @@ public function testHasInvalidKeys($key)
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testDeleteInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -544,6 +558,7 @@ public function testDeleteInvalidKeys($key)
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testDeleteMultipleInvalidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -567,6 +582,7 @@ public function testDeleteMultipleNoIterable()
/**
* @dataProvider invalidTtl
*/
#[DataProvider('invalidTtl')]
public function testSetInvalidTtl($ttl)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -580,6 +596,7 @@ public function testSetInvalidTtl($ttl)
/**
* @dataProvider invalidTtl
*/
#[DataProvider('invalidTtl')]
public function testSetMultipleInvalidTtl($ttl)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand Down Expand Up @@ -699,6 +716,7 @@ public function testBinaryData()
/**
* @dataProvider validKeys
*/
#[DataProvider('validKeys')]
public function testSetValidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -712,6 +730,7 @@ public function testSetValidKeys($key)
/**
* @dataProvider validKeys
*/
#[DataProvider('validKeys')]
public function testSetMultipleValidKeys($key)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -732,6 +751,7 @@ public function testSetMultipleValidKeys($key)
/**
* @dataProvider validData
*/
#[DataProvider('validData')]
public function testSetValidData($data)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand All @@ -745,6 +765,7 @@ public function testSetValidData($data)
/**
* @dataProvider validData
*/
#[DataProvider('validData')]
public function testSetMultipleValidData($data)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand Down
6 changes: 6 additions & 0 deletions src/TaggableCachePoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
namespace Cache\IntegrationTests;

use Cache\TagInterop\TaggableCacheItemPoolInterface;
use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -37,6 +40,7 @@ abstract public function createCachePool();
/**
* @before
*/
#[Before]
public function setupService()
{
$this->cache = $this->createCachePool();
Expand All @@ -45,6 +49,7 @@ public function setupService()
/**
* @after
*/
#[After]
public function tearDownService()
{
if ($this->cache !== null) {
Expand Down Expand Up @@ -133,6 +138,7 @@ public function testTagAccessorWithEmptyTag()
/**
* @dataProvider invalidKeys
*/
#[DataProvider('invalidKeys')]
public function testTagAccessorWithInvalidTag($tag)
{
if (isset($this->skippedTests[__FUNCTION__])) {
Expand Down

0 comments on commit c2bbdc5

Please sign in to comment.