Skip to content

Commit

Permalink
Various fixes (#190)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
theofidry authored Mar 4, 2018
1 parent 3749c1c commit b0239f0
Show file tree
Hide file tree
Showing 17 changed files with 2,070 additions and 12 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ tc: vendor/bin/phpunit vendor-bin/covers-validator/vendor
$(COVERS_VALIDATOR)
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

php -d zend.enable_gc=0 $(PHPUNIT)

tm: ## Run Infection (Mutation Testing)
tm: vendor/bin/phpunit
$(MAKE) e2e_020
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?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' => 'Class static property call of a class imported with an aliased use statement in the global scope',
// Default values. If not specified will be the one used
'prefix' => 'Humbug',
'whitelist' => [],
],

[
'spec' => <<<'SPEC'
Constant call on a aliased class which is imported via an aliased use statement and which belongs to the global namespace:
- prefix the use statement (cf. class belonging to the global scope tests)
- prefix the constant
SPEC
,
'payload' => <<<'PHP'
<?php
class Foo {}
use Foo as X;
X::$mainStaticProp;
----
<?php
namespace Humbug;
class Foo
{
}
use Humbug\Foo as X;
\Humbug\Foo::$mainStaticProp;

PHP
],

[
'spec' => <<<'SPEC'
FQ constant call on a aliased class which is imported via an aliased use statement and which belongs to the global namespace:
- do not prefix the class (cf. class belonging to the global scope tests)
- do nothing
SPEC
,
'payload' => <<<'PHP'
<?php
class Foo {}
class X {}
use Foo as X;
\X::$mainStaticProp;
----
<?php
namespace Humbug;
class Foo
{
}
class X
{
}
use Humbug\Foo as X;
\Humbug\X::$mainStaticProp;

PHP
],

[
'spec' => <<<'SPEC'
Constant call on a whitelisted class which is imported via an aliased use statement and which belongs to the global namespace:
- prefix the use statement (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in global whitelisted classes)
- transform the call into a FQ call
SPEC
,
'payload' => <<<'PHP'
<?php
use Reflector as X;
X::$mainStaticProp;
----
<?php
namespace Humbug;
use Reflector as X;
\Reflector::$mainStaticProp;

PHP
],

[
'spec' => <<<'SPEC'
FQ constant call on a whitelisted class which is imported via an aliased use statement and which belongs to the global namespace:
- prefix the use statement (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in global whitelisted classes)
- do nothing
SPEC
,
'payload' => <<<'PHP'
<?php
class X {}
use Reflector as X;
\X::$mainStaticProp;
----
<?php
namespace Humbug;
class X
{
}
use Reflector as X;
\Humbug\X::$mainStaticProp;

PHP
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?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' => 'Class static property call of a class imported with a use statement in the global scope',
// Default values. If not specified will be the one used
'prefix' => 'Humbug',
'whitelist' => [],
],

[
'spec' => <<<'SPEC'
Constant call on a class which is imported via a use statement and which belongs to the global namespace:
- do not prefix the use statement (cf. class belonging to the global scope tests)
- transforms the call into a FQ call
SPEC
,
'payload' => <<<'PHP'
<?php
class Command {}
use Command;
Command::$mainStaticProp;
----
<?php
namespace Humbug;
class Command
{
}
use Humbug\Command;
\Humbug\Command::$mainStaticProp;

PHP
],

[
'spec' => <<<'SPEC'
FQ constant call on a class which is imported via a use statement and which belongs to the global namespace:
- do not prefix the use statement (cf. class belonging to the global scope tests)
- do nothing
SPEC
,
'payload' => <<<'PHP'
<?php
class Command {}
use Command;
\Command::$mainStaticProp;
----
<?php
namespace Humbug;
class Command
{
}
use Humbug\Command;
\Humbug\Command::$mainStaticProp;

PHP
],

[
'spec' => <<<'SPEC'
Constant call on a whitelisted class which is imported via a use statement and which belongs to the global namespace:
- transform the call in a FQ call (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in
global whitelisted classes)
SPEC
,
'payload' => <<<'PHP'
<?php
use Reflector;
Reflector::$mainStaticProp;
----
<?php
namespace Humbug;
use Reflector;
\Reflector::$mainStaticProp;

PHP
],

[
'spec' => <<<'SPEC'
FQ constant call on a whitelisted class which is imported via a use statement and which belongs to the global namespace:
- prefix the class (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in global
whitelisted classes)
SPEC
,
'payload' => <<<'PHP'
<?php
use Reflector;
\Reflector::$mainStaticProp;
----
<?php
namespace Humbug;
use Reflector;
\Reflector::$mainStaticProp;

PHP
],
];
116 changes: 116 additions & 0 deletions specs/class-static-prop/global-scope-single-level.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?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' => 'Class static property call in the global scope',
// Default values. If not specified will be the one used
'prefix' => 'Humbug',
'whitelist' => [],
],

[
'spec' => <<<'SPEC'
Constant call on a class belonging to the global namespace:
- do not prefix the class (cf. class belonging to the global scope tests)
- transforms the call into a FQ call to avoid autoloading issues
SPEC
,
'payload' => <<<'PHP'
<?php
class Command {}
Command::$mainStaticProp;
----
<?php
namespace Humbug;
class Command
{
}
\Humbug\Command::$mainStaticProp;

PHP
],

[
'spec' => <<<'SPEC'
FQ constant call on a class belonging to the global namespace:
- do not prefix the class (cf. class belonging to the global scope tests)
- do not touch the call
SPEC
,
'payload' => <<<'PHP'
<?php
class Command {}
\Command::$mainStaticProp;
----
<?php
namespace Humbug;
class Command
{
}
\Humbug\Command::$mainStaticProp;

PHP
],

[
'spec' => <<<'SPEC'
Constant call on a whitelisted class belonging to the global namespace:
- prefix the class (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in global whitelisted classes)
- transforms the call into a FQ call to avoid autoloading issues
SPEC
,
'payload' => <<<'PHP'
<?php
Reflector::$mainStaticProp;
----
<?php
namespace Humbug;
\Reflector::$mainStaticProp;

PHP
],

[
'spec' => <<<'SPEC'
FQ constant call on a whitelisted class belonging to the global namespace:
- prefix the class (cf. class belonging to the global scope tests and `scope.inc.php` for the built-in global whitelisted classes)
- transforms the call into a FQ call to avoid autoloading issues
SPEC
,
'payload' => <<<'PHP'
<?php
\Reflector::$mainStaticProp;
----
<?php
namespace Humbug;
\Reflector::$mainStaticProp;

PHP
],
];
Loading

0 comments on commit b0239f0

Please sign in to comment.