Skip to content

Commit fb010ef

Browse files
committed
Refactor StoreTest to use attributes for test annotations, update PHPUnit configuration and improve code type hints. Adjust .gitignore for PHPUnit cache directory and add ext-mongodb requirement in composer.json.
1 parent 8e89319 commit fb010ef

File tree

5 files changed

+27
-35
lines changed

5 files changed

+27
-35
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/vendor/
22
composer.lock
3-
.phpunit.result.cache
3+
.phpunit.cache

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"mongodb/laravel-mongodb": "^4.1"
1010
},
1111
"require-dev": {
12-
"orchestra/testbench": "^8.0"
12+
"orchestra/testbench": "^8.0",
13+
"ext-mongodb": "*"
1314
},
1415
"license": "MIT",
1516
"authors": [

phpunit.xml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
bootstrap="vendor/autoload.php"
4-
backupGlobals="false"
5-
backupStaticAttributes="false"
6-
colors="true"
7-
verbose="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
processIsolation="false"
12-
stopOnFailure="false"
13-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
14-
>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false"
3+
colors="true" processIsolation="false" stopOnFailure="false"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache"
5+
backupStaticProperties="false">
156
<testsuites>
167
<testsuite name="MongoDB Cache Test Suite">
178
<directory>tests</directory>

tests/StoreTest.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
use ForFit\Mongodb\Cache\MongoTaggedCache;
66
use ForFit\Mongodb\Cache\Store;
77
use Illuminate\Support\Carbon;
8+
use PHPUnit\Framework\Attributes\Test;
89
use Tests\Models\Cache;
910

1011
class StoreTest extends TestCase
1112
{
12-
protected $store;
13+
protected Store $store;
1314

1415
protected function setUp(): void
1516
{
@@ -21,8 +22,8 @@ protected function setUp(): void
2122
Carbon::setTestNow(now());
2223
}
2324

24-
/** @test */
25-
public function it_stores_an_item_in_the_cache_for_given_time()
25+
#[Test]
26+
public function it_stores_an_item_in_the_cache_for_given_time(): void
2627
{
2728
// Act
2829
$sut = $this->store->put('test-key', 'test-value', 3);
@@ -37,8 +38,8 @@ public function it_stores_an_item_in_the_cache_for_given_time()
3738
]);
3839
}
3940

40-
/** @test */
41-
public function it_updates_an_item_in_the_cache_for_given_time()
41+
#[Test]
42+
public function it_updates_an_item_in_the_cache_for_given_time(): void
4243
{
4344
Cache::create([
4445
'key' => 'test-key',
@@ -58,8 +59,8 @@ public function it_updates_an_item_in_the_cache_for_given_time()
5859
]);
5960
}
6061

61-
/** @test */
62-
public function it_retrieves_value_from_the_cache_by_given_key()
62+
#[Test]
63+
public function it_retrieves_value_from_the_cache_by_given_key(): void
6364
{
6465
// Arrange
6566
Cache::create([
@@ -75,8 +76,8 @@ public function it_retrieves_value_from_the_cache_by_given_key()
7576
$this->assertEquals('test-value', $sut);
7677
}
7778

78-
/** @test */
79-
public function it_returns_null_if_key_does_not_exist()
79+
#[Test]
80+
public function it_returns_null_if_key_does_not_exist(): void
8081
{
8182
// Act
8283
$sut = $this->store->get('test-key');
@@ -85,8 +86,8 @@ public function it_returns_null_if_key_does_not_exist()
8586
$this->assertNull($sut);
8687
}
8788

88-
/** @test */
89-
public function it_sets_the_tags_to_be_used()
89+
#[Test]
90+
public function it_sets_the_tags_to_be_used(): void
9091
{
9192
// Act
9293
$sut = $this->store->tags(['tag1', 'tag2']);
@@ -96,8 +97,8 @@ public function it_sets_the_tags_to_be_used()
9697
$this->assertPropertySame(['tag1', 'tag2'], 'tags', $sut);
9798
}
9899

99-
/** @test */
100-
public function it_deletes_all_records_with_the_given_tag()
100+
#[Test]
101+
public function it_deletes_all_records_with_the_given_tag(): void
101102
{
102103
// Arrange
103104
Cache::create([
@@ -126,8 +127,8 @@ public function it_deletes_all_records_with_the_given_tag()
126127
]);
127128
}
128129

129-
/** @test */
130-
public function it_retrieves_an_items_expiration_time_by_given_key()
130+
#[Test]
131+
public function it_retrieves_an_items_expiration_time_by_given_key(): void
131132
{
132133
// Arrange
133134
Cache::create([

tests/TestCase.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
abstract class TestCase extends Orchestra
1212
{
13-
private $table = 'cache_test';
13+
private string $table = 'cache_test';
1414
private $connectionInterface;
1515

1616
/**
@@ -41,7 +41,7 @@ protected function getPackageProviders($app): array
4141
*
4242
* @param \Illuminate\Foundation\Application $app
4343
*/
44-
protected function getEnvironmentSetUp($app)
44+
protected function getEnvironmentSetUp($app): void
4545
{
4646
$app['config']->set('cache.stores.mongodb', [
4747
'driver' => 'mongodb',
@@ -78,7 +78,7 @@ protected function table(): string
7878
*
7979
* @param \Illuminate\Foundation\Application $app
8080
*/
81-
protected function setUpDatabase($app)
81+
protected function setUpDatabase($app): void
8282
{
8383
$app['db']->connection()->getSchemaBuilder()->create($this->table, function (Blueprint $table) {
8484
$table->increments('_id');
@@ -112,11 +112,10 @@ protected function initializeConnection()
112112
* @return void
113113
* @throws \ReflectionException
114114
*/
115-
protected function assertPropertySame($expected, $property, $object, string $message = '')
115+
protected function assertPropertySame($expected, $property, $object, string $message = ''): void
116116
{
117117
$reflectedClass = new \ReflectionClass($object);
118118
$reflection = $reflectedClass->getProperty($property);
119-
$reflection->setAccessible(true);
120119

121120
$this->assertSame($expected, $reflection->getValue($object), $message);
122121
}

0 commit comments

Comments
 (0)