Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: PHP CI

on: [pull_request, push]
on:
pull_request:
push:
branches: ["main"]

jobs:
build-test:
Expand Down Expand Up @@ -59,6 +62,30 @@ jobs:
- { php-version: "8.4", symfony-version: "7.1", phpunit-version: "10" }
- { php-version: "8.4", symfony-version: "7.2", phpunit-version: "10" }

#- { php-version: "8.3", symfony-version: "6.1", phpunit-version: "11" } # Apparently conflicts with nikic/php-parser
#- { php-version: "8.3", symfony-version: "6.2", phpunit-version: "11" } # Apparently conflicts with nikic/php-parser
- { php-version: "8.3", symfony-version: "6.3", phpunit-version: "11" }
- { php-version: "8.3", symfony-version: "6.4", phpunit-version: "11" }
- { php-version: "8.3", symfony-version: "7.0", phpunit-version: "11" }
- { php-version: "8.3", symfony-version: "7.1", phpunit-version: "11" }
- { php-version: "8.3", symfony-version: "7.2", phpunit-version: "11" }

- { php-version: "8.4", symfony-version: "7.0", phpunit-version: "11" }
- { php-version: "8.4", symfony-version: "7.1", phpunit-version: "11" }
- { php-version: "8.4", symfony-version: "7.2", phpunit-version: "11" }

#- { php-version: "8.3", symfony-version: "6.1", phpunit-version: "12" } # Apparently conflicts with nikic/php-parser
#- { php-version: "8.3", symfony-version: "6.2", phpunit-version: "12" } # Apparently conflicts with nikic/php-parser
- { php-version: "8.3", symfony-version: "6.3", phpunit-version: "12" }
- { php-version: "8.3", symfony-version: "6.4", phpunit-version: "12" }
- { php-version: "8.3", symfony-version: "7.0", phpunit-version: "12" }
- { php-version: "8.3", symfony-version: "7.1", phpunit-version: "12" }
- { php-version: "8.3", symfony-version: "7.2", phpunit-version: "12" }

- { php-version: "8.4", symfony-version: "7.0", phpunit-version: "12" }
- { php-version: "8.4", symfony-version: "7.1", phpunit-version: "12" }
- { php-version: "8.4", symfony-version: "7.2", phpunit-version: "12" }

name: PHP ${{ matrix.php-version }}, Symfony ${{ matrix.symfony-version }}, PHPUnit ${{ matrix.phpunit-version }}
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"symfony/framework-bundle": "^6.1|^7.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6|^10.0",
"phpunit/phpunit": "^9.6|^10.0|^11|^12",
"symfony/maker-bundle": "^1.43"
}
}
4 changes: 2 additions & 2 deletions fixture-app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"symfony/yaml": "^6.1|^7.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5|^10.0",
"phpunit/phpunit": "^9.6|^10.0|^11|^12",
"symfony/browser-kit": "^6.1|^7.0",
"symfony/css-selector": "^6.1|^7.0",
"symfony/maker-bundle": "^1.43",
Expand Down Expand Up @@ -70,7 +70,7 @@
"extra": {
"symfony": {
"allow-contrib": false,
"require": "6.1.*"
"require": "6.4.*"
}
}
}
7 changes: 0 additions & 7 deletions fixture-app/src/Controller/TestRoutesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@

class TestRoutesController extends AbstractController
{
/** @Route("/param/{id}", name="get_param_without_default", methods={"GET"}) */
#[Route("/param/{id}", name: "get_param_without_default", methods: ["GET"])]
public function getParameterWithoutDefault(string $id): Response
{
return new Response("Content: $id");
}

/** @Route("/other_param/{id}", name="get_param_with_default", defaults={"id": "default_value"}, methods={"GET"}) */
#[Route("/other_param/{id}", name: "get_param_with_default", defaults: ["id" => "default_value"], methods: ["GET"])]
public function getParameterWithDefault(string $id): Response
Expand Down
21 changes: 13 additions & 8 deletions fixture-app/tests/FunctionalSmokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class FunctionalSmokeTest extends WebTestCase
{
use FunctionalSmokeTester;

public function testGetParameterWithoutDefault(): void
{
$this->runFunctionalTest(
FunctionalTestData::withUrl("/param")
->expectStatusCode(404)
);
$this->runFunctionalTest(
FunctionalTestData::withUrl("/param/")
->expectStatusCode(404)
);
try {
$this->runFunctionalTest(
FunctionalTestData::withUrl("/param")
->expectStatusCode(404),
);
$this->runFunctionalTest(
FunctionalTestData::withUrl("/param/")
->expectStatusCode(404),
);
} catch (NotFoundHttpException) {
$this->assertTrue(true);
}
}

public function testGetParameterWithDefault(): void
Expand Down
2 changes: 1 addition & 1 deletion phpunit-10.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
<server name="SYMFONY_PHPUNIT_VERSION" value="10.5" />
</php>

<testsuites>
Expand Down
33 changes: 33 additions & 0 deletions phpunit-11.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
executionOrder="depends,defects"
failOnRisky="true"
failOnWarning="true"
cacheDirectory=".phpunit.cache"
>

<php>
<server name="KERNEL_CLASS" value="App\Kernel" />
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="11.5" />
</php>

<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
33 changes: 33 additions & 0 deletions phpunit-12.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
executionOrder="depends,defects"
failOnRisky="true"
failOnWarning="true"
cacheDirectory=".phpunit.cache"
>

<php>
<server name="KERNEL_CLASS" value="App\Kernel" />
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="12.0" />
</php>

<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion phpunit-9.6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.6" />
</php>

<testsuites>
Expand Down
14 changes: 7 additions & 7 deletions src/Maker/Resources/FunctionalSmokeTest.attributes.tpl.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<?php declare(strict_types=1);
echo "<?php\n"; ?>

namespace <?php echo $namespace; ?>;
namespace <?php echo $namespace ?? 'UndefinedNamespace'; ?>;

use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\TestWith;
<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
use Pierstoval\SmokeTesting\FunctionalSmokeTester;
use Pierstoval\SmokeTesting\FunctionalTestData;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
<?php endif; ?>
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class <?php echo $class_name; ?> extends WebTestCase
class <?php echo $class_name ?? 'UndefinedClassName' ?> extends WebTestCase
{
<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
use FunctionalSmokeTester;
<?php endif; ?>

<?php foreach ($routes as $route){
<?php foreach ($routes ?? [] as $route){
if (str_starts_with($route['routePath'], '/_')) { continue; } ?>
#[TestWith(['<?php echo $route['httpMethod']; ?>', '<?php echo $route['routePath']; ?>', '<?php echo $route['routeName']; ?>'])]
<?php } ?>
#[TestDox('$method $url ($route)')]
public function testRoute(string $method, string $url, string $route): void
{
<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
$this->runFunctionalTest(
FunctionalTestData::withUrl($url)
->withMethod($method)
Expand All @@ -47,7 +47,7 @@ public function testRoute(string $method, string $url, string $route): void
<?php endif; ?>
}

<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
public function assertStatusCodeLessThan500(string $method, string $url): \Closure
{
return static function (KernelBrowser $browser) use ($method, $url) {
Expand Down
50 changes: 30 additions & 20 deletions src/Maker/Resources/FunctionalSmokeTest.provider.tpl.php
Original file line number Diff line number Diff line change
@@ -1,57 +1,67 @@
<?php declare(strict_types=1);
echo "<?php\n"; ?>

namespace <?php echo $namespace; ?>;
namespace <?php echo $namespace ?? 'UndefinedNamespace'; ?>;

use PHPUnit\Framework\Attributes\DataProvider;
<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
use Pierstoval\SmokeTesting\FunctionalSmokeTester;
use Pierstoval\SmokeTesting\FunctionalTestData;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
<?php endif; ?>
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class <?php echo $class_name; ?> extends WebTestCase
class <?php echo $class_name ?? 'UndefinedClassName' ?> extends WebTestCase
{
<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
use FunctionalSmokeTester;
<?php endif; ?>

public static function provideRoutes(): \Generator
{
<?php foreach ($routes as $route): ?>
<?php if (str_starts_with($route['routePath'], '/_')) continue;
?> yield '<?php echo $route['httpMethod']; ?> <?php echo $route['routePath']; ?>' => ['<?php echo $route['httpMethod']; ?>', '<?php echo $route['routePath']; ?>','<?php echo $route['routeName']; ?>'];
<?php endforeach; ?>
<?php foreach ($routes ?? [] as $route) {
if (\str_starts_with($route['routePath'], '/_')) {
continue;
}
echo \sprintf(
"yield '%s %s' => ['%s', '%s', '%s'];\n ",
$route['httpMethod'],
$route['routePath'],
$route['httpMethod'],
$route['routePath'],
$route['routeName']
);
} ?>

}

#[DataProvider('provideRoutes')]
public function testRoute(string $method, string $url, string $route): void
{
<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
$this->runFunctionalTest(
FunctionalTestData::withUrl($url)
->withMethod($method)
->expectRouteName($route)
->appendCallableExpectation($this->assertStatusCodeLessThan500($method, $url))
);
<?php else: ?>
$client = static::createClient();
$client->request($method, $url);
$client = static::createClient();
$client->request($method, $url);

static::assertLessThan(
500,
$client->getResponse()->getStatusCode(),
\sprintf(
'Request "%s %s" for route "%s" returned an internal error.',
$method, $url, $route
),
);
static::assertLessThan(
500,
$client->getResponse()->getStatusCode(),
\sprintf(
'Request "%s %s" for route "%s" returned an internal error.',
$method, $url, $route
),
);
<?php endif; ?>

}

<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
public function assertStatusCodeLessThan500(string $method, string $url): \Closure
{
return static function (KernelBrowser $browser) use ($method, $url) {
Expand Down
14 changes: 7 additions & 7 deletions src/Maker/Resources/FunctionalSmokeTest.tpl.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?php declare(strict_types=1);
echo "<?php\n"; ?>

namespace <?php echo $namespace; ?>;
namespace <?php echo $namespace ?? 'UndefinedNamespace'; ?>;

<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
use Pierstoval\SmokeTesting\FunctionalSmokeTester;
use Pierstoval\SmokeTesting\FunctionalTestData;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
<?php endif; ?>
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class <?php echo $class_name; ?> extends WebTestCase
class <?php echo $class_name ?? 'UndefinedClassName' ?> extends WebTestCase
{
<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
use FunctionalSmokeTester;
<?php endif; ?>
<?php foreach ($routes as $route): ?>
<?php foreach ($routes ?? [] as $route): ?>

public function testRoute<?php echo ucfirst(preg_replace_callback('~_([a-z0-9])~isUu', function($matches) {return strtoupper($matches[1]);}, $route['routeName'])).'WithMethod'.ucfirst(strtolower($route['httpMethod'])); ?>(): void
{
<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
$this->runFunctionalTest(
FunctionalTestData::withUrl('<?php echo $route['routePath']; ?>')
->withMethod('<?php echo $route['httpMethod']; ?>')
Expand All @@ -39,7 +39,7 @@ public function testRoute<?php echo ucfirst(preg_replace_callback('~_([a-z0-9])~
}
<?php endforeach; ?>

<?php if ($with_dto): ?>
<?php if ($with_dto ?? false): ?>
public function assertStatusCodeLessThan500(string $method, string $url): \Closure
{
return static function (KernelBrowser $browser) use ($method, $url) {
Expand Down
Loading
Loading