Skip to content

Commit 4c0b9ef

Browse files
committed
Convert PHPUnit annotations to attributes
1 parent d5ea567 commit 4c0b9ef

File tree

2 files changed

+29
-44
lines changed

2 files changed

+29
-44
lines changed

tests/NotModified/Attribute/ReplaceWithNotModifiedResponseTest.php

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
namespace Webfactory\HttpCacheBundle\Tests\NotModified\Attribute;
1111

1212
use DateTime;
13+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
14+
use PHPUnit\Framework\Attributes\Group;
15+
use PHPUnit\Framework\Attributes\Test;
1316
use PHPUnit\Framework\MockObject\MockObject;
1417
use PHPUnit\Framework\TestCase;
1518
use RuntimeException;
@@ -23,30 +26,23 @@
2326
*/
2427
final class ReplaceWithNotModifiedResponseTest extends TestCase
2528
{
26-
/**
27-
* @test
28-
*/
29+
#[Test]
2930
public function lastModifiedDescriptionsCannotBeEmpty()
3031
{
3132
$this->expectException(RuntimeException::class);
3233
$attribute = new ReplaceWithNotModifiedResponse([]);
3334
$attribute->determineLastModified(new Request());
3435
}
3536

36-
/**
37-
* @test
38-
*
39-
* @doesNotPerformAssertions
40-
*/
37+
#[Test]
38+
#[DoesNotPerformAssertions]
4139
public function stringAsSimpleLastModifiedDescription()
4240
{
4341
$attribute = new ReplaceWithNotModifiedResponse([MyLastModifedDeterminator::class]);
4442
$attribute->determineLastModified(new Request());
4543
}
4644

47-
/**
48-
* @test
49-
*/
45+
#[Test]
5046
public function serviceNameAsLastModifiedDescription()
5147
{
5248
/** @var ContainerInterface|MockObject $container */
@@ -62,32 +58,24 @@ public function serviceNameAsLastModifiedDescription()
6258
$attribute->determineLastModified(new Request());
6359
}
6460

65-
/**
66-
* @test
67-
*
68-
* @doesNotPerformAssertions
69-
*/
61+
#[Test]
62+
#[DoesNotPerformAssertions]
7063
public function arrayAslastModifiedDeterminatorDescriptionWithConstructorArguments()
7164
{
7265
$attribute = new ReplaceWithNotModifiedResponse([[MyLastModifedDeterminator::class => new DateTime('2000-01-01')]]);
7366
$attribute->determineLastModified(new Request());
7467
}
7568

76-
/**
77-
* @test
78-
*/
69+
#[Test]
7970
public function lastModifiedDeterminatorsHaveToImplementInterface()
8071
{
8172
$this->expectException(RuntimeException::class);
8273
$attribute = new ReplaceWithNotModifiedResponse([FakeLastModifiedDeterminatorWithoutInterface::class]);
8374
$attribute->determineLastModified(new Request());
8475
}
8576

86-
/**
87-
* @test
88-
*
89-
* @group time-sensitive
90-
*/
77+
#[Group('time-sensitive')]
78+
#[Test]
9179
public function determineLastModifiedDeterminesLastModifiedOfOneDeterminator()
9280
{
9381
$attribute = new ReplaceWithNotModifiedResponse([MyLastModifedDeterminator::class]);
@@ -97,9 +85,7 @@ public function determineLastModifiedDeterminesLastModifiedOfOneDeterminator()
9785
self::assertEquals(DateTime::createFromFormat('U', time()), $lastModified);
9886
}
9987

100-
/**
101-
* @test
102-
*/
88+
#[Test]
10389
public function determineLastModifiedDeterminesLastModifiedOfMultipleDeterminators()
10490
{
10591
$attribute = new ReplaceWithNotModifiedResponse([

tests/NotModified/EventListenerTest.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Closure;
1313
use DateTime;
1414
use Error;
15+
use PHPUnit\Framework\Attributes\Group;
16+
use PHPUnit\Framework\Attributes\Test;
1517
use PHPUnit\Framework\MockObject\MockObject;
1618
use PHPUnit\Framework\TestCase;
1719
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -27,9 +29,8 @@
2729

2830
/**
2931
* Tests for the EventListener.
30-
*
31-
* @group time-sensitive
3232
*/
33+
#[Group('time-sensitive')]
3334
final class EventListenerTest extends TestCase
3435
{
3536
/**
@@ -53,31 +54,31 @@ protected function setUp(): void
5354
$this->eventListener = new EventListener($this->container);
5455
}
5556

56-
/** @test */
57+
#[Test]
5758
public function onKernelControllerDoesNoHarmForMissingAnnotation(): void
5859
{
5960
$this->exerciseOnKernelController([DummyController::class, 'plainAction']);
6061

6162
$this->assertRegularControllerResponse();
6263
}
6364

64-
/** @test */
65+
#[Test]
6566
public function onKernelControllerDoesNoHarmForNoDeterminedLastModified(): void
6667
{
6768
$this->exerciseOnKernelController([DummyController::class, 'abstainingLastModifiedAction']);
6869

6970
$this->assertRegularControllerResponse();
7071
}
7172

72-
/** @test */
73+
#[Test]
7374
public function onKernelControllerDoesNoHarmIfNotModifiedSinceHeaderIsNotInRequest(): void
7475
{
7576
$this->exerciseOnKernelController([DummyController::class, 'oneDayAgoModifiedLastModifiedAction']);
7677

7778
$this->assertRegularControllerResponse();
7879
}
7980

80-
/** @test */
81+
#[Test]
8182
public function onKernelControllerSkipsToModifiedResponseIfLastModifiedIsSmallerThanIfNotModifiedSinceHeader(): void
8283
{
8384
$this->request->headers->set('If-Modified-Since', '-1 hour');
@@ -87,7 +88,7 @@ public function onKernelControllerSkipsToModifiedResponseIfLastModifiedIsSmaller
8788
$this->assertNotModifiedResponse();
8889
}
8990

90-
/** @test */
91+
#[Test]
9192
public function onKernelControllerAlwaysRunsControllerInKernelDebugMode(): void
9293
{
9394
$this->eventListener = new EventListener($this->container, true);
@@ -98,7 +99,7 @@ public function onKernelControllerAlwaysRunsControllerInKernelDebugMode(): void
9899
$this->assertRegularControllerResponse();
99100
}
100101

101-
/** @test */
102+
#[Test]
102103
public function onKernelControllerSkipsToNotModifiedResponseIfLastModifiedIsEqualToIfNotModifiedSinceHeader(): void
103104
{
104105
$this->request->headers->set('If-Modified-Since', '2000-01-01');
@@ -108,7 +109,7 @@ public function onKernelControllerSkipsToNotModifiedResponseIfLastModifiedIsEqua
108109
$this->assertNotModifiedResponse();
109110
}
110111

111-
/** @test */
112+
#[Test]
112113
public function onKernelControllerDoesNotReplaceDeterminedControllerIfLastModifiedIsGreaterThanIfNotModifiedSinceHeader(): void
113114
{
114115
$this->request->headers->set('If-Modified-Since', '-2 day');
@@ -118,9 +119,7 @@ public function onKernelControllerDoesNotReplaceDeterminedControllerIfLastModifi
118119
$this->assertRegularControllerResponse();
119120
}
120121

121-
/**
122-
* @test
123-
*/
122+
#[Test]
124123
public function onKernelResponseSetsLastModifiedHeaderToResponseIfAvailable(): void
125124
{
126125
$this->exerciseOnKernelController([DummyController::class, 'oneDayAgoModifiedLastModifiedAction']);
@@ -131,7 +130,7 @@ public function onKernelResponseSetsLastModifiedHeaderToResponseIfAvailable(): v
131130
self::assertEquals(DateTime::createFromFormat('U', time() - 86400), $this->response->getLastModified());
132131
}
133132

134-
/** @test */
133+
#[Test]
135134
public function onKernelResponseDoesNotSetLastModifiedHeaderToResponseIfNotAvailable(): void
136135
{
137136
$this->exerciseOnKernelController([DummyController::class, 'abstainingLastModifiedAction']);
@@ -142,7 +141,7 @@ public function onKernelResponseDoesNotSetLastModifiedHeaderToResponseIfNotAvail
142141
self::assertNull($this->response->getLastModified());
143142
}
144143

145-
/** @test */
144+
#[Test]
146145
public function eventListenerDifferentiatesBetweenMultipleRequests(): void
147146
{
148147
$this->exerciseOnKernelController([DummyController::class, 'oneDayAgoModifiedLastModifiedAction']);
@@ -160,7 +159,7 @@ public function eventListenerDifferentiatesBetweenMultipleRequests(): void
160159
self::assertNull($anotherResponse->getLastModified());
161160
}
162161

163-
/** @test */
162+
#[Test]
164163
public function onKernelControllerSearchesEventInsteadOfControllerForAttribute(): void
165164
{
166165
// setup an event that should lead to a NotModified response
@@ -186,7 +185,7 @@ function () {
186185
self::assertNotModifiedResponse();
187186
}
188187

189-
/** @test */
188+
#[Test]
190189
public function onKernelControllerSavesOriginalControllerAttributesWhenReplacingTheController(): void
191190
{
192191
$this->request->headers->set('If-Modified-Since', '-1 hour');
@@ -196,7 +195,7 @@ public function onKernelControllerSavesOriginalControllerAttributesWhenReplacing
196195
self::assertNotEmpty($this->filterControllerEvent->getAttributes());
197196
}
198197

199-
/** @test */
198+
#[Test]
200199
public function onKernelControllerThrowsExceptionIfAttributeIsFoundMoreThanOnce(): void
201200
{
202201
self::expectException(Error::class);

0 commit comments

Comments
 (0)