Skip to content

Commit c013d23

Browse files
authored
Use attributes for PHPUnit configuration (#45)
1 parent 6e5b963 commit c013d23

File tree

7 files changed

+38
-64
lines changed

7 files changed

+38
-64
lines changed

tests/DependencyInjection/Compiler/ShortcodeCompilerPassTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Webfactory\ShortcodeBundle\Tests\DependencyInjection\Compiler;
44

5+
use PHPUnit\Framework\Attributes\Test;
56
use PHPUnit\Framework\MockObject\MockObject;
67
use PHPUnit\Framework\TestCase;
78
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -31,7 +32,7 @@ protected function setUp(): void
3132
->getMock();
3233
}
3334

34-
/** @test */
35+
#[Test]
3536
public function tagged_services_are_added_as_handlers_to_handler_container(): void
3637
{
3738
$this->containerBuilder->expects($this->once())
@@ -63,7 +64,7 @@ public function tagged_services_are_added_as_handlers_to_handler_container(): vo
6364
$this->compilerPass->process($this->containerBuilder);
6465
}
6566

66-
/** @test */
67+
#[Test]
6768
public function no_tagged_services_do_no_harm(): void
6869
{
6970
$this->containerBuilder->expects($this->once())
@@ -73,7 +74,7 @@ public function no_tagged_services_do_no_harm(): void
7374
$this->compilerPass->process($this->containerBuilder);
7475
}
7576

76-
/** @test */
77+
#[Test]
7778
public function shortcode_guide_service_gets_configured_if_set(): void
7879
{
7980
$this->containerBuilder->expects($this->once())
@@ -116,7 +117,7 @@ public function shortcode_guide_service_gets_configured_if_set(): void
116117
$this->compilerPass->process($this->containerBuilder);
117118
}
118119

119-
/** @test */
120+
#[Test]
120121
public function missing_shortcode_guide_service_does_no_harm(): void
121122
{
122123
$this->containerBuilder->expects($this->once())

tests/DependencyInjection/ConfigurationTest.php

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

33
namespace Webfactory\ShortcodeBundle\Tests\DependencyInjection;
44

5+
use PHPUnit\Framework\Attributes\Test;
56
use PHPUnit\Framework\TestCase;
67
use Symfony\Component\Config\Definition\Processor;
78
use Webfactory\ShortcodeBundle\DependencyInjection\Configuration;
89

910
class ConfigurationTest extends TestCase
1011
{
11-
/**
12-
* @test
13-
*/
12+
#[Test]
1413
public function configure_shortcode_with_controller_reference_only(): void
1514
{
1615
$processedConfig = $this->processSingleConfig(['shortcodes' => ['test-1' => 'Foo::bar']]);
@@ -19,19 +18,15 @@ public function configure_shortcode_with_controller_reference_only(): void
1918
self::assertSame('Foo::bar', $processedConfig['shortcodes']['test-1']['controller']);
2019
}
2120

22-
/**
23-
* @test
24-
*/
21+
#[Test]
2522
public function configure_shortcode_with_controller_as_key(): void
2623
{
2724
$processedConfig = $this->processSingleConfig(['shortcodes' => ['test-1' => ['controller' => 'Foo::bar']]]);
2825

2926
self::assertSame('Foo::bar', $processedConfig['shortcodes']['test-1']['controller']);
3027
}
3128

32-
/**
33-
* @test
34-
*/
29+
#[Test]
3530
public function configure_shortcode_with_method(): void
3631
{
3732
$processedConfig = $this->processSingleConfig(['shortcodes' => ['test-1' => ['controller' => 'Foo::bar', 'method' => 'esi']]]);

tests/Functional/EmbeddedShortcodeHandlerTest.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Generator;
66
use InvalidArgumentException;
7+
use PHPUnit\Framework\Attributes\DataProvider;
8+
use PHPUnit\Framework\Attributes\Test;
79
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
810
use Symfony\Component\HttpFoundation\Request;
911
use Symfony\Component\HttpFoundation\RequestStack;
@@ -18,23 +20,20 @@
1820
*/
1921
class EmbeddedShortcodeHandlerTest extends KernelTestCase
2022
{
21-
/** @test */
23+
#[Test]
2224
public function paragraphs_wrapping_shortcodes_get_removed(): void
2325
{
2426
self::assertSame('test', $this->processShortcodes('<p>[test-config-inline]</p>'));
2527
}
2628

27-
/** @test */
29+
#[Test]
2830
public function content_without_shortcodes_wont_be_changed(): void
2931
{
3032
self::assertSame('<p>Content without shortcode</p>', $this->processShortcodes('<p>Content without shortcode</p>'));
3133
}
3234

33-
/**
34-
* @test
35-
*
36-
* @dataProvider provideShortcodeNames
37-
*/
35+
#[DataProvider('provideShortcodeNames')]
36+
#[Test]
3837
public function expand_shortcodes_registered_in_different_ways(string $shortcodeName): void
3938
{
4039
// All shortcodes are set up as fixtures and use ShortcodeTestController
@@ -49,11 +48,8 @@ public static function provideShortcodeNames(): Generator
4948
yield 'ESI-based shortcode defined in service definitions' => ['test-service-esi'];
5049
}
5150

52-
/**
53-
* @test
54-
*
55-
* @dataProvider provideEsiShortcodes
56-
*/
51+
#[DataProvider('provideEsiShortcodes')]
52+
#[Test]
5753
public function processing_with_esi_fragments(string $shortcodeName): void
5854
{
5955
$request = new Request([], [], [], [], [], ['SCRIPT_URL' => '/', 'HTTP_HOST' => 'localhost']);
@@ -68,17 +64,14 @@ public static function provideEsiShortcodes(): Generator
6864
yield 'ESI-based shortcode defined in service configuration' => ['test-service-esi'];
6965
}
7066

71-
/** @test */
67+
#[Test]
7268
public function invokable_controller_can_be_used(): void
7369
{
7470
self::assertSame('invokable-controller-response', $this->processShortcodes('<p>[test-config-invokable]</p>'));
7571
}
7672

77-
/**
78-
* @test
79-
*
80-
* @dataProvider provideControllerNames
81-
*/
73+
#[DataProvider('provideControllerNames')]
74+
#[Test]
8275
public function throws_exception_on_invalid_controller_names(string $controllerName): void
8376
{
8477
$this->expectException(InvalidArgumentException::class);

tests/Functional/EndToEndTest.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Webfactory\ShortcodeBundle\Tests\Functional;
44

55
use Generator;
6+
use PHPUnit\Framework\Attributes\DataProvider;
7+
use PHPUnit\Framework\Attributes\Test;
68
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
79
use Symfony\Component\HttpFoundation\Request;
810
use Symfony\Component\HttpFoundation\RequestStack;
@@ -13,7 +15,7 @@
1315
*/
1416
final class EndToEndTest extends KernelTestCase
1517
{
16-
/** @test */
18+
#[Test]
1719
public function paragraphs_wrapping_shortcodes_get_removed(): void
1820
{
1921
$this->assertEquals(
@@ -22,7 +24,7 @@ public function paragraphs_wrapping_shortcodes_get_removed(): void
2224
);
2325
}
2426

25-
/** @test */
27+
#[Test]
2628
public function content_without_shortcodes_wont_be_changed(): void
2729
{
2830
$this->assertEquals(
@@ -31,11 +33,8 @@ public function content_without_shortcodes_wont_be_changed(): void
3133
);
3234
}
3335

34-
/**
35-
* @test
36-
*
37-
* @dataProvider provideShortcodeNames
38-
*/
36+
#[DataProvider('provideShortcodeNames')]
37+
#[Test]
3938
public function expand_shortcode_in__twig(string $shortcodeName): void
4039
{
4140
$result = $this->renderTwig('{{ content | shortcodes }}', ['content' => "[$shortcodeName foo=bar]"]);
@@ -51,11 +50,8 @@ public static function provideShortcodeNames(): Generator
5150
yield 'ESI-based shortcode defined in service definitions' => ['test-service-esi'];
5251
}
5352

54-
/**
55-
* @test
56-
*
57-
* @dataProvider provideEsiShortcodes
58-
*/
53+
#[DataProvider('provideEsiShortcodes')]
54+
#[Test]
5955
public function uses_esi_fragments(string $shortcodeName): void
6056
{
6157
$request = new Request([], [], [], [], [], ['SCRIPT_URL' => '/', 'HTTP_HOST' => 'localhost']);

tests/Functional/ShortcodeDefinitionTestHelperTest.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Webfactory\ShortcodeBundle\Tests\Functional;
44

5+
use PHPUnit\Framework\Attributes\Test;
56
use RuntimeException;
67
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
78
use Thunder\Shortcode\Handler\PlaceholderHandler;
@@ -21,35 +22,27 @@ protected function setUp(): void
2122
$this->helper = static::getContainer()->get(ShortcodeDefinitionTestHelper::class);
2223
}
2324

24-
/**
25-
* @test
26-
*/
25+
#[Test]
2726
public function throws_exception_for_handlers_that_do_not_use_controllers(): void
2827
{
2928
self::expectException(RuntimeException::class);
3029
$this->helper->resolveShortcodeController('placeholder'); // uses the \Thunder\Shortcode\Handler\PlaceholderHandler handler class directly
3130
}
3231

33-
/**
34-
* @test
35-
*/
32+
#[Test]
3633
public function can_test_whether_shortcode_is_defined(): void
3734
{
3835
self::assertTrue($this->helper->hasShortcode('placeholder'));
3936
self::assertFalse($this->helper->hasShortcode('unknown-shortcode'));
4037
}
4138

42-
/**
43-
* @test
44-
*/
39+
#[Test]
4540
public function can_retrieve_handler(): void
4641
{
4742
self::assertInstanceOf(PlaceholderHandler::class, $this->helper->getHandler('placeholder'));
4843
}
4944

50-
/**
51-
* @test
52-
*/
45+
#[Test]
5346
public function can_be_used_to_assert_controller_class_and_method(): void
5447
{
5548
$controller = $this->helper->resolveShortcodeController('test-config-inline');

tests/Functional/ShortcodeExtensionTest.php

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

33
namespace Webfactory\ShortcodeBundle\Tests\Functional;
44

5+
use PHPUnit\Framework\Attributes\Test;
56
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
67

78
/**
89
* Test that integration with Twig works as expected.
910
*/
1011
class ShortcodeExtensionTest extends KernelTestCase
1112
{
12-
/**
13-
* @test
14-
*/
13+
#[Test]
1514
public function resolve_placeholder_shortcode_in_twig(): void
1615
{
1716
self::assertSame('News from year 1970.', $this->renderTemplate('{% apply shortcodes %}[placeholder year=1970]News from year %year%.[/placeholder]{% endapply %}'));
1817
}
1918

20-
/**
21-
* @test
22-
*/
19+
#[Test]
2320
public function filter_returns_safe_html(): void
2421
{
2522
self::assertSame('<p>HTML</p>', $this->renderTemplate('{{ "<p>HTML</p>" | shortcodes }}'));

tests/Functional/ShortcodeGuideTest.php

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

33
namespace Webfactory\ShortcodeBundle\Tests\Functional;
44

5+
use PHPUnit\Framework\Attributes\Test;
56
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
67

78
class ShortcodeGuideTest extends WebTestCase
89
{
9-
/**
10-
* @test
11-
*/
10+
#[Test]
1211
public function shortcode_guide_contains_test_entry(): void
1312
{
1413
$client = static::createClient();

0 commit comments

Comments
 (0)