Skip to content

[BC break] Update the default config #710

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 3 commits into from
Nov 6, 2022
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
2 changes: 2 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ parameters:
path: 'src/Scoper/Symfony/YamlScoper.php'
- message: '#Scoper::scope\(\) expects string\, mixed given\.#'
path: 'src/Scoper/SymfonyScoper.php'
- message: '#Class Isolated\\Symfony\\Component\\Finder\\Finder not found\.#'
path: 'tests/Configuration/DefaultConfigurationTest.php'
7 changes: 4 additions & 3 deletions src/Configuration/SymbolsConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

final class SymbolsConfiguration
{
// To keep in sync with the default configuration set in src/scoper.inc.php.tpl
public static function create(
bool $exposeGlobalConstants = false,
bool $exposeGlobalClasses = false,
bool $exposeGlobalFunctions = false,
bool $exposeGlobalConstants = true,
bool $exposeGlobalClasses = true,
bool $exposeGlobalFunctions = true,
?NamespaceRegistry $excludedNamespaces = null,
// Does not contain the list of excluded symbols which go to the
// Reflector (which has no notion of namespaces)
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/SymbolsConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function createSymbolsConfiguration(array $config): SymbolsConfiguration
private static function retrieveExposeGlobalSymbol(array $config, string $key): bool
{
if (!array_key_exists($key, $config)) {
return false;
return true;
}

$value = $config[$key];
Expand Down
4 changes: 3 additions & 1 deletion src/scoper.inc.php.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ return [
//
// For more see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#finders-and-paths
'finders' => [
/*
Finder::create()->files()->in('src'),
Finder::create()
->files()
Expand All @@ -43,14 +44,15 @@ return [
Finder::create()->append([
'composer.json',
]),
*/
],

// List of excluded files, i.e. files for which the content will be left untouched.
// Paths are relative to the configuration file unless if they are already absolute
//
// For more see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#patchers
'exclude-files' => [
'src/a-whitelisted-file.php',
// 'src/a-whitelisted-file.php',
],

// When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,33 @@ public static function configProvider(): iterable
[
ConfigurationKeys::EXPOSE_GLOBAL_CONSTANTS_KEYWORD => true,
],
SymbolsConfiguration::create(),
];

yield 'do not expose global constants' => [
[
ConfigurationKeys::EXPOSE_GLOBAL_CONSTANTS_KEYWORD => false,
],
SymbolsConfiguration::create(
true,
false,
),
];

// TODO: named parameters would be handy here
yield 'expose global classes' => [
yield 'do not expose global classes' => [
[
ConfigurationKeys::EXPOSE_GLOBAL_CLASSES_KEYWORD => true,
ConfigurationKeys::EXPOSE_GLOBAL_CLASSES_KEYWORD => false,
],
SymbolsConfiguration::create(
false,
true,
exposeGlobalClasses: false,
),
];

yield 'expose global functions' => [
yield 'do not expose global functions' => [
[
ConfigurationKeys::EXPOSE_GLOBAL_FUNCTIONS_KEYWORD => true,
ConfigurationKeys::EXPOSE_GLOBAL_FUNCTIONS_KEYWORD => false,
],
SymbolsConfiguration::create(
false,
false,
true,
exposeGlobalFunctions: false,
),
];

Expand All @@ -93,10 +96,7 @@ public static function configProvider(): iterable
],
],
SymbolsConfiguration::create(
false,
false,
false,
NamespaceRegistry::create(
excludedNamespaces: NamespaceRegistry::create(
['PHPUnit\Runner'],
),
),
Expand All @@ -109,10 +109,7 @@ public static function configProvider(): iterable
],
],
SymbolsConfiguration::create(
false,
false,
false,
NamespaceRegistry::create(
excludedNamespaces: NamespaceRegistry::create(
[],
['~^PHPUnit\\Runner(\\.*)?$~i'],
),
Expand All @@ -126,14 +123,9 @@ public static function configProvider(): iterable
],
],
SymbolsConfiguration::create(
false,
false,
false,
null,
null,
SymbolRegistry::create(['Acme\Foo']),
SymbolRegistry::create(['Acme\Foo']),
SymbolRegistry::createForConstants(['Acme\Foo']),
exposedClasses: SymbolRegistry::create(['Acme\Foo']),
exposedFunctions: SymbolRegistry::create(['Acme\Foo']),
exposedConstants: SymbolRegistry::createForConstants(['Acme\Foo']),
),
];

Expand All @@ -147,10 +139,7 @@ public static function configProvider(): iterable
],
],
SymbolsConfiguration::create(
false,
false,
false,
NamespaceRegistry::create(
excludedNamespaces: NamespaceRegistry::create(
[
'PHPUnit\Internal',
'PHPUnit\Runner',
Expand All @@ -161,9 +150,9 @@ public static function configProvider(): iterable

yield 'nominal' => [
[
ConfigurationKeys::EXPOSE_GLOBAL_CONSTANTS_KEYWORD => true,
ConfigurationKeys::EXPOSE_GLOBAL_CLASSES_KEYWORD => true,
ConfigurationKeys::EXPOSE_GLOBAL_FUNCTIONS_KEYWORD => true,
ConfigurationKeys::EXPOSE_GLOBAL_CONSTANTS_KEYWORD => false,
ConfigurationKeys::EXPOSE_GLOBAL_CLASSES_KEYWORD => false,
ConfigurationKeys::EXPOSE_GLOBAL_FUNCTIONS_KEYWORD => false,
ConfigurationKeys::EXCLUDE_NAMESPACES_KEYWORD => [
'PHPUnit\Internal',
'~^PHPUnit\\Runner(\\.*)?$~',
Expand All @@ -174,9 +163,9 @@ public static function configProvider(): iterable
],
],
SymbolsConfiguration::create(
true,
true,
true,
false,
false,
false,
NamespaceRegistry::create(
[
'PHPUnit\Internal',
Expand Down
56 changes: 56 additions & 0 deletions tests/Configuration/DefaultConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <[email protected]>,
* Pádraic Brady <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Humbug\PhpScoper\Configuration;

use Humbug\PhpScoper\Container;
use Isolated\Symfony\Component\Finder\Finder as IsolatedFinder;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Finder;
use function class_alias;
use function class_exists;

/**
* @coversNothing
* @group integration
*
* @internal
*/
final class DefaultConfigurationTest extends TestCase
{
private ConfigurationFactory $configurationFactory;

protected function setUp(): void
{
$this->configurationFactory = (new Container())->getConfigurationFactory();

if (!class_exists(IsolatedFinder::class)) {
class_alias(Finder::class, IsolatedFinder::class);
}
}

public function test_the_template_file_is_in_sync_with_the_default_configuration(): void
{
$templateConfiguration = $this->configurationFactory->create(
__DIR__.'/../../src/scoper.inc.php.tpl',
);

$defaultConfiguration = $this->configurationFactory->create();

self::assertEquals(
$templateConfiguration->getSymbolsConfiguration(),
$defaultConfiguration->getSymbolsConfiguration(),
);
}
}