Skip to content

Commit 133ae89

Browse files
committed
replace doctrine annotation by php attribute for PHPUnit
1 parent e660a8c commit 133ae89

19 files changed

Lines changed: 226 additions & 81 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Changed
1212
- add required #\[RunTestsInSeparateProcesses] attribute on Kernel, Functional and FunctionalJavascript tests
13+
- replace doctrine annotation by php attribute for PHPUnit
1314

1415
## [6.0.6] - 2026-01-26
1516
### Added

tests/src/Functional/BambooTwigCacheableTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22

33
namespace Drupal\Tests\bamboo_twig\Functional;
44

5+
use Drupal\bamboo_twig_cacheable\TwigExtension\BubbleMetadata;
6+
use PHPUnit\Framework\Attributes\CoversClass;
7+
use PHPUnit\Framework\Attributes\CoversMethod;
58
use PHPUnit\Framework\Attributes\Group;
69
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
710

811
/**
912
* Tests Cacheable twig filters and functions.
13+
*
14+
* @group bamboo_twig
15+
* @group bamboo_twig_functional
1016
*/
17+
#[CoversClass(BubbleMetadata::class)]
18+
#[CoversMethod(BubbleMetadata::class, 'attachCacheableMetadata')]
1119
#[Group('bamboo_twig')]
1220
#[Group('bamboo_twig_functional')]
1321
#[Group('bamboo_twig_cacheable')]
@@ -25,7 +33,7 @@ class BambooTwigCacheableTest extends BambooTwigTestBase {
2533
];
2634

2735
/**
28-
* @covers Drupal\bamboo_twig_cacheable\TwigExtension\BubbleMetadata::attachCacheableMetadata
36+
* Tests attachCacheableMetadata() propagates cache contexts to the response.
2937
*/
3038
public function testCacheableContexts() {
3139
$this->drupalGet('/bamboo-twig-cacheable');
@@ -35,7 +43,7 @@ public function testCacheableContexts() {
3543
}
3644

3745
/**
38-
* @covers Drupal\bamboo_twig_cacheable\TwigExtension\BubbleMetadata::attachCacheableMetadata
46+
* Tests attachCacheableMetadata() propagates cache tags to the response.
3947
*/
4048
public function testCacheableTags() {
4149
$this->drupalGet('/bamboo-twig-cacheable');
@@ -45,7 +53,7 @@ public function testCacheableTags() {
4553
}
4654

4755
/**
48-
* @covers Drupal\bamboo_twig_cacheable\TwigExtension\BubbleMetadata::attachCacheableMetadata
56+
* Tests attachCacheableMetadata() propagates max-age to the response.
4957
*/
5058
public function testCacheableMaxAge() {
5159
$this->drupalGet('/bamboo-twig-cacheable');

tests/src/Functional/BambooTwigConfigTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22

33
namespace Drupal\Tests\bamboo_twig\Functional;
44

5+
use Drupal\bamboo_twig_config\TwigExtension\Config;
6+
use PHPUnit\Framework\Attributes\CoversClass;
7+
use PHPUnit\Framework\Attributes\CoversMethod;
8+
use PHPUnit\Framework\Attributes\Group;
59
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
610

711
/**
812
* Tests Config twig filters and functions.
913
*
1014
* @group bamboo_twig
1115
* @group bamboo_twig_functional
12-
* @group bamboo_twig_config
1316
*/
17+
#[CoversClass(Config::class)]
18+
#[CoversMethod(Config::class, 'getSettings')]
19+
#[CoversMethod(Config::class, 'getConfig')]
20+
#[CoversMethod(Config::class, 'getState')]
21+
#[Group('bamboo_twig')]
22+
#[Group('bamboo_twig_functional')]
23+
#[Group('bamboo_twig_config')]
1424
#[RunTestsInSeparateProcesses]
1525
class BambooTwigConfigTest extends BambooTwigTestBase {
1626

@@ -42,7 +52,7 @@ public function setUp(): void {
4252
}
4353

4454
/**
45-
* @covers Drupal\bamboo_twig_config\TwigExtension\Config::getSettings
55+
* Tests getSettings() exposes PHP settings values in templates.
4656
*/
4757
public function testGetSettings() {
4858
$this->drupalGet('/bamboo-twig-config');
@@ -52,7 +62,7 @@ public function testGetSettings() {
5262
}
5363

5464
/**
55-
* @covers Drupal\bamboo_twig_config\TwigExtension\Config::getConfig
65+
* Tests getConfig() exposes Drupal configuration values in templates.
5666
*/
5767
public function testGetConfig() {
5868
$this->drupalGet('/bamboo-twig-config');
@@ -62,7 +72,7 @@ public function testGetConfig() {
6272
}
6373

6474
/**
65-
* @covers Drupal\bamboo_twig_config\TwigExtension\Config::getState
75+
* Tests getState() exposes Drupal state values in templates.
6676
*/
6777
public function testGetState() {
6878
$now = time();

tests/src/Functional/BambooTwigExtensionsI18nTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44

55
use Drupal\Component\Gettext\PoItem;
66
use Drupal\language\Entity\ConfigurableLanguage;
7+
use PHPUnit\Framework\Attributes\Group;
78
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
89

910
/**
1011
* Tests Extensions i18n of twig filters and functions.
1112
*
1213
* @group bamboo_twig
1314
* @group bamboo_twig_functional
14-
* @group bamboo_twig_extensions
15-
* @group bamboo_twig_extensions_i18n
1615
*/
16+
#[Group('bamboo_twig')]
17+
#[Group('bamboo_twig_functional')]
18+
#[Group('bamboo_twig_extensions')]
19+
#[Group('bamboo_twig_extensions_i18n')]
1720
#[RunTestsInSeparateProcesses]
1821
class BambooTwigExtensionsI18nTest extends BambooTwigTestBase {
1922

tests/src/Functional/BambooTwigExtensionsTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
namespace Drupal\Tests\bamboo_twig\Functional;
44

5+
use PHPUnit\Framework\Attributes\Group;
56
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
67

78
/**
89
* Tests Extensions twig filters and functions.
910
*
1011
* @group bamboo_twig
1112
* @group bamboo_twig_functional
12-
* @group bamboo_twig_extensions
1313
*/
14+
#[Group('bamboo_twig')]
15+
#[Group('bamboo_twig_functional')]
16+
#[Group('bamboo_twig_extensions')]
1417
#[RunTestsInSeparateProcesses]
1518
class BambooTwigExtensionsTest extends BambooTwigTestBase {
1619

tests/src/Functional/BambooTwigFileTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22

33
namespace Drupal\Tests\bamboo_twig\Functional;
44

5+
use Drupal\bamboo_twig_file\TwigExtension\File;
6+
use PHPUnit\Framework\Attributes\CoversClass;
7+
use PHPUnit\Framework\Attributes\CoversMethod;
8+
use PHPUnit\Framework\Attributes\Group;
59
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
610

711
/**
812
* Tests File twig filters and functions.
913
*
1014
* @group bamboo_twig
1115
* @group bamboo_twig_functional
12-
* @group bamboo_twig_file
1316
*/
17+
#[CoversClass(File::class)]
18+
#[CoversMethod(File::class, 'extensionGuesser')]
19+
#[CoversMethod(File::class, 'UrlAbsolute')]
20+
#[Group('bamboo_twig')]
21+
#[Group('bamboo_twig_functional')]
22+
#[Group('bamboo_twig_file')]
1423
#[RunTestsInSeparateProcesses]
1524
class BambooTwigFileTest extends BambooTwigTestBase {
1625

@@ -25,7 +34,7 @@ class BambooTwigFileTest extends BambooTwigTestBase {
2534
];
2635

2736
/**
28-
* @covers Drupal\bamboo_twig_file\TwigExtension\File::extensionGuesser
37+
* Tests extensionGuesser() returns the correct extension for various files.
2938
*/
3039
public function testExtensionGuesser() {
3140
$this->drupalGet('/bamboo-twig-file');
@@ -44,7 +53,7 @@ public function testExtensionGuesser() {
4453
}
4554

4655
/**
47-
* @covers Drupal\bamboo_twig_file\TwigExtension\File::UrlAbsolute
56+
* Tests UrlAbsolute() returns relative and absolute file URLs.
4857
*/
4958
public function testUrlAbsolute() {
5059
$this->drupalGet('/bamboo-twig-file');

tests/src/Functional/BambooTwigI18nTest.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@
22

33
namespace Drupal\Tests\bamboo_twig\Functional;
44

5+
use Drupal\bamboo_twig_i18n\TwigExtension\I18n;
6+
use Drupal\bamboo_twig_loader\TwigExtension\Loader;
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\Attributes\CoversMethod;
9+
use PHPUnit\Framework\Attributes\Group;
510
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
611

712
/**
813
* Tests I18n twig filters and functions.
914
*
1015
* @group bamboo_twig
1116
* @group bamboo_twig_functional
12-
* @group bamboo_twig_i18n
1317
*/
18+
#[CoversClass(I18n::class)]
19+
#[CoversClass(Loader::class)]
20+
#[CoversMethod(I18n::class, 'getCurrentLanguage')]
21+
#[CoversMethod(I18n::class, 'formatDate')]
22+
#[CoversMethod(I18n::class, 'getTranslation')]
23+
#[CoversMethod(Loader::class, 'loadEntity')]
24+
#[Group('bamboo_twig')]
25+
#[Group('bamboo_twig_functional')]
26+
#[Group('bamboo_twig_i18n')]
1427
#[RunTestsInSeparateProcesses]
1528
class BambooTwigI18nTest extends BambooTwigTestBase {
1629

@@ -87,7 +100,7 @@ protected function setUpTranslations() {
87100
}
88101

89102
/**
90-
* @covers Drupal\bamboo_twig_i18n\TwigExtension\I18n::getCurrentLanguage
103+
* Tests getCurrentLanguage() returns the active language code.
91104
*/
92105
public function testCurrentLang() {
93106
$this->drupalGet('/bamboo-twig-i18n');
@@ -100,7 +113,7 @@ public function testCurrentLang() {
100113
}
101114

102115
/**
103-
* @covers Drupal\bamboo_twig_i18n\TwigExtension\I18n::formatDate
116+
* Tests formatDate() formats dates with locale-aware translations.
104117
*/
105118
public function testFormatDate() {
106119
$this->drupalGet('/bamboo-twig-i18n');
@@ -145,7 +158,7 @@ public function testFormatDate() {
145158
}
146159

147160
/**
148-
* @covers Drupal\bamboo_twig_i18n\TwigExtension\I18n::getTranslation
161+
* Tests getTranslation() returns the entity in the requested language.
149162
*/
150163
public function testGetTranslation() {
151164
$this->drupalGet('/bamboo-twig-i18n');
@@ -187,8 +200,7 @@ public function testGetTranslation() {
187200
}
188201

189202
/**
190-
* @covers Drupal\bamboo_twig_i18n\TwigExtension\I18n::getTranslation
191-
* @covers Drupal\bamboo_twig_loader\TwigExtension\Loader::loadEntity
203+
* Tests getTranslation() with loadEntity() on entity reference fields.
192204
*/
193205
public function testGetTranslationReferencedField() {
194206
$this->drupalGet('/bamboo-twig-i18n');

tests/src/Functional/BambooTwigLoaderTest.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@
22

33
namespace Drupal\Tests\bamboo_twig\Functional;
44

5+
use Drupal\bamboo_twig_loader\TwigExtension\Loader;
56
use Drupal\Core\StreamWrapper\PublicStream;
67
use Drupal\file\FileInterface;
78
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
9+
use PHPUnit\Framework\Attributes\CoversClass;
10+
use PHPUnit\Framework\Attributes\CoversMethod;
11+
use PHPUnit\Framework\Attributes\Group;
812
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
913

1014
/**
1115
* Tests Loaders twig filters and functions.
1216
*
1317
* @group bamboo_twig
1418
* @group bamboo_twig_functional
15-
* @group bamboo_twig_loader
1619
*/
20+
#[CoversClass(Loader::class)]
21+
#[CoversMethod(Loader::class, 'loadCurrentUser')]
22+
#[CoversMethod(Loader::class, 'loadEntity')]
23+
#[CoversMethod(Loader::class, 'loadEntityRevision')]
24+
#[CoversMethod(Loader::class, 'loadField')]
25+
#[CoversMethod(Loader::class, 'loadImage')]
26+
#[Group('bamboo_twig')]
27+
#[Group('bamboo_twig_functional')]
28+
#[Group('bamboo_twig_loader')]
1729
#[RunTestsInSeparateProcesses]
1830
class BambooTwigLoaderTest extends BambooTwigTestBase {
1931
use TaxonomyTestTrait;
@@ -98,7 +110,7 @@ public function setUp(): void {
98110
}
99111

100112
/**
101-
* @covers Drupal\bamboo_twig_loader\TwigExtension\Loader::loadCurrentUser
113+
* Tests loadCurrentUser() loads the current user in templates.
102114
*/
103115
public function testCurrentUser() {
104116
$this->drupalGet('/bamboo-twig-loader');
@@ -114,7 +126,7 @@ public function testCurrentUser() {
114126
}
115127

116128
/**
117-
* @covers Drupal\bamboo_twig_loader\TwigExtension\Loader::loadEntity
129+
* Tests loadEntity() loads nodes, taxonomy terms, files, and users.
118130
*/
119131
public function testEntity() {
120132
$this->drupalGet('/bamboo-twig-loader');
@@ -222,7 +234,7 @@ public function testEntity() {
222234
}
223235

224236
/**
225-
* @covers Drupal\bamboo_twig_loader\TwigExtension\Loader::loadEntityRevision
237+
* Tests loadEntityRevision() loads specific revisions of entities.
226238
*/
227239
public function testEntityRevision() {
228240
$this->drupalGet('/bamboo-twig-loader-revision');
@@ -252,8 +264,7 @@ public function testEntityRevision() {
252264
}
253265

254266
/**
255-
* @covers Drupal\bamboo_twig_loader\TwigExtension\Loader::loadEntity
256-
* @covers Drupal\bamboo_twig_loader\TwigExtension\Loader::loadEntityRevision
267+
* Tests loadEntity() and loadEntityRevision() load entities from route.
257268
*/
258269
public function testEntityFromRoutes() {
259270
// Accessing unpublished revision page required to be authenticated.
@@ -287,7 +298,7 @@ public function testEntityFromRoutes() {
287298
}
288299

289300
/**
290-
* @covers Drupal\bamboo_twig_loader\TwigExtension\Loader::loadField
301+
* Tests loadField() loads individual field values from entities.
291302
*/
292303
public function testField() {
293304
$this->drupalGet('/bamboo-twig-loader');
@@ -391,7 +402,7 @@ public function testField() {
391402
}
392403

393404
/**
394-
* @covers Drupal\bamboo_twig_loader\TwigExtension\Loader::loadImage
405+
* Tests loadImage() loads an image by URI and by module path.
395406
*/
396407
public function testImage() {
397408
$this->drupalGet('/bamboo-twig-loader');

tests/src/Functional/BambooTwigPathTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22

33
namespace Drupal\Tests\bamboo_twig\Functional;
44

5+
use Drupal\bamboo_twig_path\TwigExtension\Path;
6+
use PHPUnit\Framework\Attributes\CoversClass;
7+
use PHPUnit\Framework\Attributes\CoversMethod;
8+
use PHPUnit\Framework\Attributes\Group;
59
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
610

711
/**
812
* Tests Path twig filters and functions.
913
*
1014
* @group bamboo_twig
1115
* @group bamboo_twig_functional
12-
* @group bamboo_twig_path
1316
*/
17+
#[CoversClass(Path::class)]
18+
#[CoversMethod(Path::class, 'getSystemPath')]
19+
#[Group('bamboo_twig')]
20+
#[Group('bamboo_twig_functional')]
21+
#[Group('bamboo_twig_path')]
1422
#[RunTestsInSeparateProcesses]
1523
class BambooTwigPathTest extends BambooTwigTestBase {
1624

@@ -24,7 +32,7 @@ class BambooTwigPathTest extends BambooTwigTestBase {
2432
];
2533

2634
/**
27-
* @covers Drupal\bamboo_twig_path\TwigExtension\Path::getSystemPath
35+
* Tests getSystemPath() resolves theme, profile, and module paths.
2836
*/
2937
public function testPathSystem() {
3038
$this->drupalGet('/bamboo-twig-path');

0 commit comments

Comments
 (0)