Skip to content

Commit b0239f0

Browse files
authored
Various fixes (#190)
- Do not execute the tests twice when generating the coverage - Fix prefixing of string literals with methods (as a method argument or passed as a parameter) - Fix static property calls: the class was not prefixed - Prefix Composer use statement: there is no reason not to anymore
1 parent 3749c1c commit b0239f0

17 files changed

+2070
-12
lines changed

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ tc: vendor/bin/phpunit vendor-bin/covers-validator/vendor
5959
$(COVERS_VALIDATOR)
6060
phpdbg -qrr -d zend.enable_gc=0 $(PHPUNIT) --coverage-html=dist/coverage --coverage-text --coverage-clover=clover.xml --coverage-xml=dist/infection-coverage/coverage-xml --log-junit=dist/infection-coverage/phpunit.junit.xml
6161

62-
php -d zend.enable_gc=0 $(PHPUNIT)
63-
6462
tm: ## Run Infection (Mutation Testing)
6563
tm: vendor/bin/phpunit
6664
$(MAKE) e2e_020
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
return [
16+
'meta' => [
17+
'title' => 'Class static property 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+
'whitelist' => [],
21+
],
22+
23+
[
24+
'spec' => <<<'SPEC'
25+
Constant call on a aliased class which is imported via an aliased use statement and which belongs to the global namespace:
26+
- prefix the use statement (cf. class belonging to the global scope tests)
27+
- prefix the constant
28+
SPEC
29+
,
30+
'payload' => <<<'PHP'
31+
<?php
32+
33+
class Foo {}
34+
35+
use Foo as X;
36+
37+
X::$mainStaticProp;
38+
----
39+
<?php
40+
41+
namespace Humbug;
42+
43+
class Foo
44+
{
45+
}
46+
use Humbug\Foo as X;
47+
\Humbug\Foo::$mainStaticProp;
48+
49+
PHP
50+
],
51+
52+
[
53+
'spec' => <<<'SPEC'
54+
FQ constant call on a aliased class which is imported via an aliased use statement and which belongs to the global namespace:
55+
- do not prefix the class (cf. class belonging to the global scope tests)
56+
- do nothing
57+
SPEC
58+
,
59+
'payload' => <<<'PHP'
60+
<?php
61+
62+
class Foo {}
63+
class X {}
64+
65+
use Foo as X;
66+
67+
\X::$mainStaticProp;
68+
----
69+
<?php
70+
71+
namespace Humbug;
72+
73+
class Foo
74+
{
75+
}
76+
class X
77+
{
78+
}
79+
use Humbug\Foo as X;
80+
\Humbug\X::$mainStaticProp;
81+
82+
PHP
83+
],
84+
85+
[
86+
'spec' => <<<'SPEC'
87+
Constant call on a whitelisted class which is imported via an aliased use statement and which belongs to the global namespace:
88+
- prefix the use statement (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in global whitelisted classes)
89+
- transform the call into a FQ call
90+
SPEC
91+
,
92+
'payload' => <<<'PHP'
93+
<?php
94+
95+
use Reflector as X;
96+
97+
X::$mainStaticProp;
98+
----
99+
<?php
100+
101+
namespace Humbug;
102+
103+
use Reflector as X;
104+
\Reflector::$mainStaticProp;
105+
106+
PHP
107+
],
108+
109+
[
110+
'spec' => <<<'SPEC'
111+
FQ constant call on a whitelisted class which is imported via an aliased use statement and which belongs to the global namespace:
112+
- prefix the use statement (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in global whitelisted classes)
113+
- do nothing
114+
SPEC
115+
,
116+
'payload' => <<<'PHP'
117+
<?php
118+
119+
class X {}
120+
121+
use Reflector as X;
122+
123+
\X::$mainStaticProp;
124+
----
125+
<?php
126+
127+
namespace Humbug;
128+
129+
class X
130+
{
131+
}
132+
use Reflector as X;
133+
\Humbug\X::$mainStaticProp;
134+
135+
PHP
136+
],
137+
];
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
return [
16+
'meta' => [
17+
'title' => 'Class static property 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+
'whitelist' => [],
21+
],
22+
23+
[
24+
'spec' => <<<'SPEC'
25+
Constant call on a class which is imported via a use statement and which belongs to the global namespace:
26+
- do not prefix the use statement (cf. class belonging to the global scope tests)
27+
- transforms the call into a FQ call
28+
SPEC
29+
,
30+
'payload' => <<<'PHP'
31+
<?php
32+
33+
class Command {}
34+
35+
use Command;
36+
37+
Command::$mainStaticProp;
38+
----
39+
<?php
40+
41+
namespace Humbug;
42+
43+
class Command
44+
{
45+
}
46+
use Humbug\Command;
47+
\Humbug\Command::$mainStaticProp;
48+
49+
PHP
50+
],
51+
52+
[
53+
'spec' => <<<'SPEC'
54+
FQ constant call on a class which is imported via a use statement and which belongs to the global namespace:
55+
- do not prefix the use statement (cf. class belonging to the global scope tests)
56+
- do nothing
57+
SPEC
58+
,
59+
'payload' => <<<'PHP'
60+
<?php
61+
62+
class Command {}
63+
64+
use Command;
65+
66+
\Command::$mainStaticProp;
67+
----
68+
<?php
69+
70+
namespace Humbug;
71+
72+
class Command
73+
{
74+
}
75+
use Humbug\Command;
76+
\Humbug\Command::$mainStaticProp;
77+
78+
PHP
79+
],
80+
81+
[
82+
'spec' => <<<'SPEC'
83+
Constant call on a whitelisted class which is imported via a use statement and which belongs to the global namespace:
84+
- transform the call in a FQ call (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in
85+
global whitelisted classes)
86+
SPEC
87+
,
88+
'payload' => <<<'PHP'
89+
<?php
90+
91+
use Reflector;
92+
93+
Reflector::$mainStaticProp;
94+
----
95+
<?php
96+
97+
namespace Humbug;
98+
99+
use Reflector;
100+
\Reflector::$mainStaticProp;
101+
102+
PHP
103+
],
104+
105+
[
106+
'spec' => <<<'SPEC'
107+
FQ constant call on a whitelisted class which is imported via a use statement and which belongs to the global namespace:
108+
- prefix the class (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in global
109+
whitelisted classes)
110+
SPEC
111+
,
112+
'payload' => <<<'PHP'
113+
<?php
114+
115+
use Reflector;
116+
117+
\Reflector::$mainStaticProp;
118+
----
119+
<?php
120+
121+
namespace Humbug;
122+
123+
use Reflector;
124+
\Reflector::$mainStaticProp;
125+
126+
PHP
127+
],
128+
];
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
return [
16+
'meta' => [
17+
'title' => 'Class static property call in the global scope',
18+
// Default values. If not specified will be the one used
19+
'prefix' => 'Humbug',
20+
'whitelist' => [],
21+
],
22+
23+
[
24+
'spec' => <<<'SPEC'
25+
Constant call on a class belonging to the global namespace:
26+
- do not prefix the class (cf. class belonging to the global scope tests)
27+
- transforms the call into a FQ call to avoid autoloading issues
28+
SPEC
29+
,
30+
'payload' => <<<'PHP'
31+
<?php
32+
33+
class Command {}
34+
35+
Command::$mainStaticProp;
36+
----
37+
<?php
38+
39+
namespace Humbug;
40+
41+
class Command
42+
{
43+
}
44+
\Humbug\Command::$mainStaticProp;
45+
46+
PHP
47+
],
48+
49+
[
50+
'spec' => <<<'SPEC'
51+
FQ constant call on a class belonging to the global namespace:
52+
- do not prefix the class (cf. class belonging to the global scope tests)
53+
- do not touch the call
54+
SPEC
55+
,
56+
'payload' => <<<'PHP'
57+
<?php
58+
59+
class Command {}
60+
61+
\Command::$mainStaticProp;
62+
----
63+
<?php
64+
65+
namespace Humbug;
66+
67+
class Command
68+
{
69+
}
70+
\Humbug\Command::$mainStaticProp;
71+
72+
PHP
73+
],
74+
75+
[
76+
'spec' => <<<'SPEC'
77+
Constant call on a whitelisted class belonging to the global namespace:
78+
- prefix the class (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in global whitelisted classes)
79+
- transforms the call into a FQ call to avoid autoloading issues
80+
SPEC
81+
,
82+
'payload' => <<<'PHP'
83+
<?php
84+
85+
Reflector::$mainStaticProp;
86+
----
87+
<?php
88+
89+
namespace Humbug;
90+
91+
\Reflector::$mainStaticProp;
92+
93+
PHP
94+
],
95+
96+
[
97+
'spec' => <<<'SPEC'
98+
FQ constant call on a whitelisted class belonging to the global namespace:
99+
- prefix the class (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in global whitelisted classes)
100+
- transforms the call into a FQ call to avoid autoloading issues
101+
SPEC
102+
,
103+
'payload' => <<<'PHP'
104+
<?php
105+
106+
\Reflector::$mainStaticProp;
107+
----
108+
<?php
109+
110+
namespace Humbug;
111+
112+
\Reflector::$mainStaticProp;
113+
114+
PHP
115+
],
116+
];

0 commit comments

Comments
 (0)