Skip to content

Commit a75021c

Browse files
authored
test: Ensure assert cannot be accidentally exposed (#1014)
1 parent 6cff52b commit a75021c

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

specs/misc/assert.php

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the humbug/php-scoper package.
7+
*
8+
* Copyright (c) 2017 Théo FIDRY <[email protected]>,
9+
* Pádraic Brady <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
use Humbug\PhpScoper\SpecFramework\Config\Meta;
16+
use Humbug\PhpScoper\SpecFramework\Config\SpecWithConfig;
17+
18+
return [
19+
'meta' => new Meta(
20+
title: 'Ensures the function `assert()` cannot be exposed in any way (it is a reserved symbol).',
21+
),
22+
23+
'usage in the global namespace' => <<<'PHP'
24+
<?php
25+
26+
assert();
27+
\assert();
28+
29+
----
30+
<?php
31+
32+
namespace Humbug;
33+
34+
\assert();
35+
\assert();
36+
37+
PHP,
38+
39+
'usage in the global namespace whilst exposed' => SpecWithConfig::create(
40+
exposeFunctions: ['assert'],
41+
spec: <<<'PHP'
42+
<?php
43+
44+
assert();
45+
\assert();
46+
47+
----
48+
<?php
49+
50+
namespace Humbug;
51+
52+
\assert();
53+
\assert();
54+
55+
PHP,
56+
),
57+
58+
'usage in the global namespace whilst excluded' => SpecWithConfig::create(
59+
excludeFunctions: ['assert'],
60+
spec: <<<'PHP'
61+
<?php
62+
63+
assert();
64+
\assert();
65+
66+
----
67+
<?php
68+
69+
namespace Humbug;
70+
71+
\assert();
72+
\assert();
73+
74+
PHP,
75+
),
76+
77+
'usage in a namespace' => <<<'PHP'
78+
<?php
79+
80+
namespace Box;
81+
82+
assert();
83+
\assert();
84+
85+
namespace PhpScoper;
86+
87+
use function assert;
88+
89+
assert();
90+
\assert();
91+
92+
----
93+
<?php
94+
95+
namespace Humbug\Box;
96+
97+
assert();
98+
\assert();
99+
namespace Humbug\PhpScoper;
100+
101+
use function assert;
102+
assert();
103+
\assert();
104+
105+
PHP,
106+
107+
'usage in a namespace whilst exposed' => SpecWithConfig::create(
108+
exposeFunctions: ['assert'],
109+
spec: <<<'PHP'
110+
<?php
111+
112+
namespace Box;
113+
114+
assert();
115+
\assert();
116+
117+
namespace PhpScoper;
118+
119+
use function assert;
120+
121+
assert();
122+
\assert();
123+
124+
----
125+
<?php
126+
127+
namespace Humbug\Box;
128+
129+
assert();
130+
\assert();
131+
namespace Humbug\PhpScoper;
132+
133+
use function assert;
134+
assert();
135+
\assert();
136+
137+
PHP,
138+
),
139+
140+
'usage in a namespace whilst excluded' => SpecWithConfig::create(
141+
excludeFunctions: ['assert'],
142+
spec: <<<'PHP'
143+
<?php
144+
145+
namespace Box;
146+
147+
assert();
148+
\assert();
149+
150+
namespace PhpScoper;
151+
152+
use function assert;
153+
154+
assert();
155+
\assert();
156+
157+
----
158+
<?php
159+
160+
namespace Humbug\Box;
161+
162+
assert();
163+
\assert();
164+
namespace Humbug\PhpScoper;
165+
166+
use function assert;
167+
assert();
168+
\assert();
169+
170+
PHP,
171+
),
172+
];

0 commit comments

Comments
 (0)