Skip to content

Function file must be loaded manually to function_exists to work + remove dependency on deprecated easy-testing package #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2025
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
name: 'Tests'
run: vendor/bin/phpunit

-
name: 'Dependency Analysis'
run: vendor/bin/composer-dependency-analyser

-
name: 'Check Active Classes'
run: vendor/bin/class-leak check src --ansi --skip-type="\Symplify\PhpConfigPrinter\Contract\Converter\ServiceOptionsKeyYamlToPhpFactoryInterface" --skip-type="\Symplify\PhpConfigPrinter\Contract\RoutingCaseConverterInterface" --skip-type="\Symplify\PhpConfigPrinter\Contract\CaseConverterInterface"
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
composer.lock

.phpunit.cache

# symfony kernel cache dir
/var
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Downloads total](https://img.shields.io/packagist/dt/symplify/php-config-printer.svg?style=flat-square)](https://packagist.org/packages/symplify/php-config-printer/stats)

Print Symfony services array with configuration to to plain PHP file format thanks to this simple php-parser wrapper
Print Symfony services array with configuration to to plain PHP file format using [nikic/php-parser](https://github.com/nikic/PHP-Parser)

## Install

Expand Down
16 changes: 16 additions & 0 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;

// include ref() function
// require __DIR__ . '/vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php';

$configuration = new Configuration();

// can be used conditionally, based on project context
$configuration->ignoreErrorsOnPackage('myclabs/php-enum', [ErrorType::DEV_DEPENDENCY_IN_PROD]);

return $configuration;
20 changes: 13 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
"license": "MIT",
"require": {
"php": ">=8.2",
"nette/utils": "^3.2",
"nikic/php-parser": "^5.3",
"symfony/yaml": "^6.4"
"ext-ctype": "*",
"nette/utils": "^4.0",
"nikic/php-parser": "^5.5",
"symfony/dependency-injection": "^6.4|^7.3",
"symfony/service-contracts": "^3.6",
"symfony/yaml": "^6.4",
"webmozart/assert": "^1.11"
},
"require-dev": {
"symfony/config": "^6.4|^7.3",
"symfony/http-kernel": "^6.4|^7.3",
"myclabs/php-enum": "^1.8",
"phpecs/phpecs": "^2.1",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^10.5",
"rector/rector": "^2.0",
"phpecs/phpecs": "^2.0",
"symplify/easy-testing": "^11.1",
"phpunit/phpunit": "^11.5",
"rector/rector": "^2.1",
"shipmonk/composer-dependency-analyser": "^1.8",
"symplify/phpstan-extensions": "^12.0",
"tomasvotruba/class-leak": "^2.0"
},
Expand Down
1 change: 0 additions & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
__DIR__ . '/../src/RoutingCaseConverter'
)->tag(RoutingCaseConverterInterface::class);


$services->load(
'Symplify\\PhpConfigPrinter\\ServiceOptionConverter\\',
__DIR__ . '/../src/ServiceOptionConverter'
Expand Down
1 change: 1 addition & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

return ECSConfig::configure()
->withPaths([
__DIR__ . '/config',
__DIR__ . '/src',
__DIR__ . '/tests',
])
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ parameters:

# unclear what to do
- '#Parameter \#1 \$items of class PhpParser\\Node\\Expr\\Array_ constructor expects array<PhpParser\\Node\\ArrayItem>, array<PhpParser\\Node\\Arg> given#'

# runs also on older PHP versions, like 7.4+
-
message: '#Right side of && is always true#'
path: src/NodeFactory/ArgsNodeFactory.php
1 change: 0 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@

// old value is needed
\Rector\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector::class,

]);
7 changes: 7 additions & 0 deletions src/Naming/ReferenceFunctionNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ final class ReferenceFunctionNameResolver
*/
public static function resolve(): string
{
$symfonyFunctionsFile = getcwd() . '/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php';

if (file_exists($symfonyFunctionsFile)) {
// this file must be included manually, as composer will only load it once function called
require_once $symfonyFunctionsFile;
}

if (function_exists(FunctionName::REF)) {
return FunctionName::REF;
}
Expand Down
36 changes: 36 additions & 0 deletions tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Symplify\PhpConfigPrinter\Tests;

use PHPUnit\Framework\TestCase;
use Symplify\PhpConfigPrinter\Tests\HttpKernel\TestKernel;

abstract class AbstractTestCase extends TestCase
{
private \Symfony\Component\DependencyInjection\ContainerInterface $container;

protected function setUp(): void
{
$testKernel = new TestKernel('test', true);
$testKernel->boot();

$this->container = $testKernel->getContainer();
}

/**
* @template TType as object
*
* @param class-string<TType> $type
* @return TType
*/
public function getService(string $type): object
{
if (! $this->container->has($type)) {
throw new \RuntimeException(sprintf('Service "%s" not found in container.', $type));
}

return $this->container->get($type);
}
}
21 changes: 0 additions & 21 deletions tests/HttpKernel/PhpConfigPrinterKernel.php

This file was deleted.

24 changes: 24 additions & 0 deletions tests/HttpKernel/TestKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Symplify\PhpConfigPrinter\Tests\HttpKernel;

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

/**
* This config is needed for tests to run
*/
final class TestKernel extends Kernel
{
public function registerBundles(): iterable
{
return [];
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__ . '/../../config/config.php');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Symplify\PackageBuilder\Testing\AbstractKernelTestCase;
use Symplify\PhpConfigPrinter\Printer\SmartPhpConfigPrinter;
use Symplify\PhpConfigPrinter\Tests\HttpKernel\PhpConfigPrinterKernel;
use Symplify\PhpConfigPrinter\Tests\AbstractTestCase;
use Symplify\PhpConfigPrinter\Tests\Printer\SmartPhpConfigPrinter\Source\ClassWithConstants;
use Symplify\PhpConfigPrinter\Tests\Printer\SmartPhpConfigPrinter\Source\FirstClass;
use Symplify\PhpConfigPrinter\Tests\Printer\SmartPhpConfigPrinter\Source\SecondClass;

final class SmartPhpConfigPrinterTest extends AbstractKernelTestCase
final class SmartPhpConfigPrinterTest extends AbstractTestCase
{
private SmartPhpConfigPrinter $smartPhpConfigPrinter;

protected function setUp(): void
{
$this->bootKernel(PhpConfigPrinterKernel::class);
parent::setUp();

$this->smartPhpConfigPrinter = $this->getService(SmartPhpConfigPrinter::class);
}

Expand Down