Skip to content

Commit

Permalink
Add more tests to show that exclude has priority over exposing (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Nov 13, 2022
1 parent 6f053d6 commit 3dc5aa3
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ With this in mind, know that excluding a symbol may not be done the way you
expect it to. More details about the internal work, which will be necessary
if you need to delve into the scoped code, can be found bellow.

**Note: If a symbol is excluded _and_ exposed, the exclusion will take precedence.**


### Exposing classes

Expand Down
30 changes: 30 additions & 0 deletions specs/const/const-declaration-with-global-exposed.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,36 @@
PHP,
],

'Excluded constants declaration in the global namespace' => [
'exclude-constants' => [
'FOO_CONST',
'BAR_CONST',
'Acme\BAR_CONST',
],
'payload' => <<<'PHP'
<?php
const FOO_CONST = foo();
define('BAR_CONST', foo());
define('Acme\BAR_CONST', foo());
define(FOO_CONST, foo());
define(\FOO_CONST, foo());
define(\Acme\BAR_CONST, foo());
----
<?php
namespace Humbug;
\define('FOO_CONST', foo());
\define('BAR_CONST', foo());
\define('Acme\\BAR_CONST', foo());
\define(\FOO_CONST, foo());
\define(\FOO_CONST, foo());
\define(\Acme\BAR_CONST, foo());

PHP,
],

'Constants declaration in a namespace' => <<<'PHP'
<?php
Expand Down
103 changes: 103 additions & 0 deletions specs/misc/exclude-expose-priority.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?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.
*/

return [
'meta' => [
'title' => 'Excluding a symbol/namespace should have precedence over exposing a symbol/namespace',
// Default values. If not specified will be the one used
'prefix' => 'Humbug',

'expose-global-constants' => false,
'expose-global-classes' => false,
'expose-global-functions' => false,
'expose-namespaces' => [],
'expose-constants' => [],
'expose-classes' => [],
'expose-functions' => [],

'exclude-namespaces' => [],
'exclude-constants' => [],
'exclude-classes' => [],
'exclude-functions' => [],

'expected-recorded-classes' => [],
'expected-recorded-functions' => [],
],

'namespace' => [
'exclude-namespaces' => [
'Acme',
],
'expose-namespaces' => [
'Acme',
],
'payload' => <<<'PHP'
<?php
namespace Acme {
class X {}
}
namespace {
new \Acme\X();
}
----
<?php
namespace Acme;
class X
{
}
namespace Humbug;
new \Acme\X();

PHP,
],

'symbol' => [
'exclude-classes' => [
'Acme\X',
],
'expose-classes' => [
'Acme\X',
],
'payload' => <<<'PHP'
<?php
namespace Acme {
class X {}
}
namespace {
new \Acme\X();
}
----
<?php
namespace Humbug\Acme;
class X
{
}
namespace Humbug;
new \Acme\X();

PHP,
],
];

0 comments on commit 3dc5aa3

Please sign in to comment.