Skip to content

Commit 90375ab

Browse files
authored
test: Introduce a Meta object to replace the spec associative array (#985)
At the time the specs were written, there were much less configuration settings and I wanted a clear view of the default settings, not having them declared in an less obvious place (e.g. the spec test case). Now with the advent of readonly classes, promoted properties and named parameters, I think it is time to reconsider this. This will also make it easier to introduce new settings like needed for #981.
1 parent e76c65d commit 90375ab

File tree

174 files changed

+2522
-4967
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+2522
-4967
lines changed

specs/binary/simple.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,12 @@
1212
* file that was distributed with this source code.
1313
*/
1414

15+
use Humbug\PhpScoper\Scoper\Spec\Meta;
16+
1517
return [
16-
'meta' => [
17-
'title' => 'Excerpts of code used for executable PHP files (e.g. for PHPUnit)',
18-
// Default values. If not specified will be the one used
19-
'prefix' => 'Humbug',
20-
21-
'expose-global-constants' => false,
22-
'expose-global-classes' => false,
23-
'expose-global-functions' => false,
24-
'expose-namespaces' => [],
25-
'expose-constants' => [],
26-
'expose-classes' => [],
27-
'expose-functions' => [],
28-
29-
'exclude-namespaces' => [],
30-
'exclude-constants' => [],
31-
'exclude-classes' => [],
32-
'exclude-functions' => [],
33-
34-
'expected-recorded-classes' => [],
35-
'expected-recorded-functions' => [],
36-
],
18+
'meta' => new Meta(
19+
title: 'Excerpts of code used for executable PHP files (e.g. for PHPUnit)',
20+
),
3721

3822
'Some statements made directly in the global namespace' => <<<'PHP'
3923
<?php declare(strict_types=1);

specs/class-const/global-scope-single-level-with-single-level-use-statement-and-alias.php

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,13 @@
1212
* file that was distributed with this source code.
1313
*/
1414

15+
use Humbug\PhpScoper\Scoper\Spec\Meta;
16+
use Humbug\PhpScoper\Scoper\Spec\SpecWithConfig;
17+
1518
return [
16-
'meta' => [
17-
'title' => 'Class constant call of a class imported with an aliased use statement in the global scope',
18-
// Default values. If not specified will be the one used
19-
'prefix' => 'Humbug',
20-
21-
'expose-global-constants' => false,
22-
'expose-global-classes' => false,
23-
'expose-global-functions' => false,
24-
'expose-namespaces' => [],
25-
'expose-constants' => [],
26-
'expose-classes' => [],
27-
'expose-functions' => [],
28-
29-
'exclude-namespaces' => [],
30-
'exclude-constants' => [],
31-
'exclude-classes' => [],
32-
'exclude-functions' => [],
33-
34-
'expected-recorded-classes' => [],
35-
'expected-recorded-functions' => [],
36-
],
19+
'meta' => new Meta(
20+
title: 'Class constant call of a class imported with an aliased use statement in the global scope',
21+
),
3722

3823
'Constant call on a aliased class which is imported via an aliased use statement and which belongs to the global namespace' => <<<'PHP'
3924
<?php
@@ -118,9 +103,9 @@ class X
118103

119104
PHP,
120105

121-
'Constant call on an exposed class which is imported via an aliased use statement and which belongs to the global namespace' => [
122-
'expose-classes' => ['Foo'],
123-
'payload' => <<<'PHP'
106+
'Constant call on an exposed class which is imported via an aliased use statement and which belongs to the global namespace' => SpecWithConfig::create(
107+
exposeClasses: ['Foo'],
108+
spec: <<<'PHP'
124109
<?php
125110
126111
use Foo as X;
@@ -135,11 +120,11 @@ class X
135120
X::MAIN_CONST;
136121

137122
PHP,
138-
],
123+
),
139124

140-
'FQ constant call on an excluded class which is imported via an aliased use statement and which belongs to the global namespace' => [
141-
'expose-classes' => ['Foo'],
142-
'payload' => <<<'PHP'
125+
'FQ constant call on an excluded class which is imported via an aliased use statement and which belongs to the global namespace' => SpecWithConfig::create(
126+
exposeClasses: ['Foo'],
127+
spec: <<<'PHP'
143128
<?php
144129
145130
class X {}
@@ -159,5 +144,5 @@ class X
159144
\Humbug\X::MAIN_CONST;
160145

161146
PHP,
162-
],
147+
),
163148
];

specs/class-const/global-scope-single-level-with-single-level-use-statement.php

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,13 @@
1212
* file that was distributed with this source code.
1313
*/
1414

15+
use Humbug\PhpScoper\Scoper\Spec\Meta;
16+
use Humbug\PhpScoper\Scoper\Spec\SpecWithConfig;
17+
1518
return [
16-
'meta' => [
17-
'title' => 'Class constant call of a class imported with a use statement in the global scope',
18-
// Default values. If not specified will be the one used
19-
'prefix' => 'Humbug',
20-
21-
'expose-global-constants' => false,
22-
'expose-global-classes' => false,
23-
'expose-global-functions' => false,
24-
'expose-namespaces' => [],
25-
'expose-constants' => [],
26-
'expose-classes' => [],
27-
'expose-functions' => [],
28-
29-
'exclude-namespaces' => [],
30-
'exclude-constants' => [],
31-
'exclude-classes' => [],
32-
'exclude-functions' => [],
33-
34-
'expected-recorded-classes' => [],
35-
'expected-recorded-functions' => [],
36-
],
19+
'meta' => new Meta(
20+
title: 'Class constant call of a class imported with a use statement in the global scope',
21+
),
3722

3823
'Constant call on a class which is imported via a use statement and which belongs to the global namespace' => <<<'PHP'
3924
<?php
@@ -109,9 +94,9 @@ class Command
10994

11095
PHP,
11196

112-
'Constant call on an exposed class which is imported via a use statement and which belongs to the global namespace' => [
113-
'expose-classes' => ['Foo'],
114-
'payload' => <<<'PHP'
97+
'Constant call on an exposed class which is imported via a use statement and which belongs to the global namespace' => SpecWithConfig::create(
98+
exposeClasses: ['Foo'],
99+
spec: <<<'PHP'
115100
<?php
116101
117102
use Foo;
@@ -126,11 +111,11 @@ class Command
126111
Foo::MAIN_CONST;
127112

128113
PHP,
129-
],
114+
),
130115

131-
'FQ constant call on an exposed class which is imported via a use statement and which belongs to the global namespace' => [
132-
'expose-classes' => ['Foo'],
133-
'payload' => <<<'PHP'
116+
'FQ constant call on an exposed class which is imported via a use statement and which belongs to the global namespace' => SpecWithConfig::create(
117+
exposeClasses: ['Foo'],
118+
spec: <<<'PHP'
134119
<?php
135120
136121
use Foo;
@@ -145,5 +130,5 @@ class Command
145130
\Humbug\Foo::MAIN_CONST;
146131

147132
PHP,
148-
],
133+
),
149134
];

specs/class-const/global-scope-single-level.php

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,13 @@
1212
* file that was distributed with this source code.
1313
*/
1414

15+
use Humbug\PhpScoper\Scoper\Spec\Meta;
16+
use Humbug\PhpScoper\Scoper\Spec\SpecWithConfig;
17+
1518
return [
16-
'meta' => [
17-
'title' => 'Class constant call in the global scope',
18-
// Default values. If not specified will be the one used
19-
'prefix' => 'Humbug',
20-
21-
'expose-global-constants' => false,
22-
'expose-global-classes' => false,
23-
'expose-global-functions' => false,
24-
'expose-namespaces' => [],
25-
'expose-constants' => [],
26-
'expose-classes' => [],
27-
'expose-functions' => [],
28-
29-
'exclude-namespaces' => [],
30-
'exclude-constants' => [],
31-
'exclude-classes' => [],
32-
'exclude-functions' => [],
33-
34-
'expected-recorded-classes' => [],
35-
'expected-recorded-functions' => [],
36-
],
19+
'meta' => new Meta(
20+
title: 'Class constant call in the global scope',
21+
),
3722

3823
'Constant call on a class belonging to the global namespace' => <<<'PHP'
3924
<?php
@@ -53,12 +38,12 @@ class Command
5338

5439
PHP,
5540

56-
'Constant call on a class belonging to the global namespace which is excluded' => [
57-
'exclude-namespaces' => ['/^$/'],
58-
'expected-recorded-classes' => [
41+
'Constant call on a class belonging to the global namespace which is excluded' => SpecWithConfig::create(
42+
excludeNamespaces: ['/^$/'],
43+
expectedRecordedClasses: [
5944
['Command', 'Humbug\Command'],
6045
],
61-
'payload' => <<<'PHP'
46+
spec: <<<'PHP'
6247
<?php
6348
6449
class Command {}
@@ -76,7 +61,7 @@ class Command
7661
}
7762

7863
PHP,
79-
],
64+
),
8065

8166
'FQ constant call on a class belonging to the global namespace' => <<<'PHP'
8267
<?php
@@ -122,9 +107,9 @@ class Command
122107

123108
PHP,
124109

125-
'Constant call on an exposed class belonging to the global namespace' => [
126-
'expose-classes' => ['Foo'],
127-
'payload' => <<<'PHP'
110+
'Constant call on an exposed class belonging to the global namespace' => SpecWithConfig::create(
111+
exposeClasses: ['Foo'],
112+
spec: <<<'PHP'
128113
<?php
129114
130115
Foo::MAIN_CONST;
@@ -136,11 +121,11 @@ class Command
136121
\Humbug\Foo::MAIN_CONST;
137122

138123
PHP,
139-
],
124+
),
140125

141-
'FQ constant call on an exposed class belonging to the global namespace' => [
142-
'expose-classes' => ['Foo'],
143-
'payload' => <<<'PHP'
126+
'FQ constant call on an exposed class belonging to the global namespace' => SpecWithConfig::create(
127+
exposeClasses: ['Foo'],
128+
spec: <<<'PHP'
144129
<?php
145130
146131
\Foo::MAIN_CONST;
@@ -152,5 +137,5 @@ class Command
152137
\Humbug\Foo::MAIN_CONST;
153138

154139
PHP,
155-
],
140+
),
156141
];

specs/class-const/global-scope-two-level-with-single-level-use-and-alias.php

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,13 @@
1212
* file that was distributed with this source code.
1313
*/
1414

15+
use Humbug\PhpScoper\Scoper\Spec\Meta;
16+
use Humbug\PhpScoper\Scoper\Spec\SpecWithConfig;
17+
1518
return [
16-
'meta' => [
17-
'title' => 'Class constant call of a namespaced class imported with an aliased use statement in the global scope',
18-
// Default values. If not specified will be the one used
19-
'prefix' => 'Humbug',
20-
21-
'expose-global-constants' => false,
22-
'expose-global-classes' => false,
23-
'expose-global-functions' => false,
24-
'expose-namespaces' => [],
25-
'expose-constants' => [],
26-
'expose-classes' => [],
27-
'expose-functions' => [],
28-
29-
'exclude-namespaces' => [],
30-
'exclude-constants' => [],
31-
'exclude-classes' => [],
32-
'exclude-functions' => [],
33-
34-
'expected-recorded-classes' => [],
35-
'expected-recorded-functions' => [],
36-
],
19+
'meta' => new Meta(
20+
title: 'Class constant call of a namespaced class imported with an aliased use statement in the global scope',
21+
),
3722

3823
'Constant call on a namespaced class partially imported with an aliased use statement' => <<<'PHP'
3924
<?php
@@ -134,12 +119,12 @@ class Bar
134119

135120
PHP,
136121

137-
'FQ Constant call on an exposed namespaced class partially imported with an aliased use statement' => [
138-
'expose-classes' => ['Foo\Bar'],
139-
'expected-recorded-classes' => [
122+
'FQ Constant call on an exposed namespaced class partially imported with an aliased use statement' => SpecWithConfig::create(
123+
exposeClasses: ['Foo\Bar'],
124+
expectedRecordedClasses: [
140125
['Foo\Bar', 'Humbug\Foo\Bar'],
141126
],
142-
'payload' => <<<'PHP'
127+
spec: <<<'PHP'
143128
<?php
144129
145130
namespace {
@@ -175,11 +160,11 @@ class Bar
175160
X\Bar::MAIN_CONST;
176161

177162
PHP,
178-
],
163+
),
179164

180-
'FQ constant call on an exposed namespaced class imported with an aliased use statement' => [
181-
'expose-classes' => ['Foo\Bar'],
182-
'payload' => <<<'PHP'
165+
'FQ constant call on an exposed namespaced class imported with an aliased use statement' => SpecWithConfig::create(
166+
exposeClasses: ['Foo\Bar'],
167+
spec: <<<'PHP'
183168
<?php
184169
185170
namespace {
@@ -214,5 +199,5 @@ class Bar
214199
\Humbug\X\Bar::MAIN_CONST;
215200

216201
PHP,
217-
],
202+
),
218203
];

0 commit comments

Comments
 (0)