-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The methods set, expiresAt and expiresAfter of NullCacheItem must return the item itself.
- Loading branch information
David Weichert
committed
Mar 12, 2024
1 parent
2181db8
commit afd879f
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Metasyntactical\Psr\Cache; | ||
|
||
use DateInterval; | ||
use DateTime; | ||
use DateTimeImmutable; | ||
use DateTimeInterface; | ||
use DateTimeZone; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use Traversable; | ||
|
||
class NullCacheItemTest extends TestCase | ||
{ | ||
public function testGetKey(): void | ||
{ | ||
$object = new NullCacheItem('key'); | ||
self::assertSame('key', $object->getKey()); | ||
} | ||
|
||
public function testGet(): void | ||
{ | ||
$object = new NullCacheItem('key'); | ||
self::assertEquals(null, $object->get()); | ||
} | ||
|
||
public function testIsHit(): void | ||
{ | ||
$object = new NullCacheItem('key'); | ||
self::assertFalse($object->isHit()); | ||
} | ||
|
||
public function testSet(): void | ||
{ | ||
$object = new NullCacheItem('key'); | ||
self::assertSame($object, $object->set('value')); | ||
} | ||
|
||
#[DataProvider('provideExpiresAt')] | ||
public function testExpiresAt( | ||
DateTimeInterface|null $value, | ||
): void { | ||
$object = new NullCacheItem('key'); | ||
self::assertSame($object, $object->expiresAt($value)); | ||
} | ||
|
||
public static function provideExpiresAt(): Traversable | ||
{ | ||
yield 'null' => ['value' => null]; | ||
yield 'DateTime' => ['value' => DateTime::createFromFormat('Y-m-d', '2024-03-12', new DateTimeZone('UTC'))]; | ||
yield 'DateTimeImmutable' => ['value' => DateTimeImmutable::createFromFormat('Y-m-d', '2024-03-12', new DateTimeZone('UTC'))]; | ||
} | ||
|
||
#[DataProvider('provideExpiresAfter')] | ||
public function testExpiresAfter( | ||
DateInterval|int|null $value, | ||
): void { | ||
$object = new NullCacheItem('key'); | ||
self::assertSame($object, $object->expiresAfter($value)); | ||
} | ||
|
||
public static function provideExpiresAfter(): Traversable | ||
{ | ||
yield 'null' => ['value' => null]; | ||
yield 'int' => ['value' => 42]; | ||
yield 'DateIterval' => ['value' => DateInterval::createFromDateString('1 day')]; | ||
} | ||
} |