Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions doc/Infection.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,48 @@ this script collects the paths defined in your CODEOWNERS file for given codeown

this script accepts a list of files and intersects them with the paths defined in your CODEOWNERS file for given codeowner. the intersected result is printed as comma separated list which can be used as a filter value for, for example, php infection.

> [!CAUTION]
> the `stdin2codeowner-filter.pl` script requires either an optimised or an authoritative classmap file so make sure to generate one of those in your configuration (see example below).

### example config

> gitlab-ci-yml
> ```yaml
> php-infection:
> stage: test
> rules:
> - <your code owner run conditions>
> needs:
> - phpunit-coverage
> variables:
> DEV_TEAM: '@team-awesome'
> EXCLUDE_PATHS: '/old,/legacy'
> MIN_COVERED_MSI: '98.00'
> MIN_MSI: '95.00'
> before_script:
> - composer dump-autoload --optimize --ignore-platform-reqs
> - git fetch --depth=1 origin $CI_MERGE_REQUEST_DIFF_BASE_SHA
> - export INFECTION_FILTER=$(git diff $CI_MERGE_REQUEST_DIFF_BASE_SHA..$CI_COMMIT_SHA --diff-filter=AMR --name-only -- '***.php' | .stdin2codeowner-filter.pl)
> script:
> - ./vendor/bin/infection -j$(nproc) --filter=$INFECTION_FILTER --min-msi=$MIN_MSI --min-covered-msi=$MIN_COVERED_MSI --coverage=./coverage --skip-initial-tests
> ```


## stdin2classtype-filter

this script accepts a list of files and intersects them with the paths defined in your CODEOWNERS file for given codeowner.
after which a given list of class types are excluded from that list. possible types are `class`, `interface`, `trait`, `enum`, `method_enum`.

### assumptions

this script assumes the presence of the CODEOWNERS file in the root directory of you project.
though configurable in the `stdin2codeowner-filter.pl` file, for now no plans to make that configurable or accept it as input parameter.
this script assumes the presence of the `PHP_EXCLUDE_TYPES` environment variable and should contain a comma separated list of class types to exclude.

> [!CAUTION]
> the `stdin2codeowner-filter.pl` script requires either an optimised or an authoritative classmap file so make sure to generate one of those in your configuration (see example below).
> the `stdin2classtype-filter.pl` script requires either an optimised or an authoritative classmap file so make sure to generate one of those in your configuration (see example below).
also the classes are expected to be conform PSR-4 standards (i.e. the filename matches the classname).

> [!NOTE]
> enum class types are differentiated as `enum` and `method_enum` where the later is an enumeration containing methods (for which typically mutants _can_ be generated).


### example config
Expand All @@ -58,10 +93,11 @@ though configurable in the `stdin2codeowner-filter.pl` file, for now no plans to
> EXCLUDE_PATHS: '/old,/legacy'
> MIN_COVERED_MSI: '98.00'
> MIN_MSI: '95.00'
> PHP_EXCLUDE_TYPES: 'interface,enum'
> before_script:
> - composer dump-autoload --optimize --ignore-platform-reqs
> - git fetch --depth=1 origin $CI_MERGE_REQUEST_DIFF_BASE_SHA
> - export INFECTION_FILTER=$(git diff $CI_MERGE_REQUEST_DIFF_BASE_SHA..$CI_COMMIT_SHA --diff-filter=AMR --name-only -- '***.php' | .stdin2codeowner-filter.pl)
> - export INFECTION_FILTER=$(git diff $CI_MERGE_REQUEST_DIFF_BASE_SHA..$CI_COMMIT_SHA --diff-filter=AMR --name-only -- '***.php' | .stdin2classtype-filter.pl)
> script:
> - ./vendor/bin/infection -j$(nproc) --filter=$INFECTION_FILTER --min-msi=$MIN_MSI --min-covered-msi=$MIN_COVERED_MSI --coverage=./coverage --skip-initial-tests
> ```
Expand Down Expand Up @@ -91,3 +127,4 @@ this script assumes both `MIN_MSI` and `MIN_COVERED_MSI` are configured.
> - set +e
> - ./vendor/bin/infection | infection2escapee-warning.pl
> ```

2 changes: 1 addition & 1 deletion lib/GPH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package GPH;
use strict;
use warnings FATAL => 'all';

our $VERSION = '1.1.3';
our $VERSION = '1.2.0';

1;

Expand Down
4 changes: 2 additions & 2 deletions lib/GPH/PHPMD.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strict;
use warnings FATAL => 'all';

use XML::LibXML;
use GPH::XMLHelper;
use GPH::Util::XMLHelper;

sub new {
my ($class, %args) = @_;
Expand All @@ -14,7 +14,7 @@ sub new {
my $self = {
owner => $args{owner},
cycloLevel => $args{cyclo_level},
generator => GPH::XMLHelper->new(),
generator => GPH::Util::XMLHelper->new(),
};

bless $self, $class;
Expand Down
4 changes: 2 additions & 2 deletions lib/GPH/Psalm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strict;
use warnings FATAL => 'all';

use XML::LibXML;
use GPH::XMLHelper;
use GPH::Util::XMLHelper;

sub new {
my ($class, %args) = @_;
Expand All @@ -23,7 +23,7 @@ sub new {
baseline_check => $args{baseline_check} || 'true',
cache_dir => $args{cache_dir} || './psalm',
plugins => $plugins,
generator => GPH::XMLHelper->new(),
generator => GPH::Util::XMLHelper->new(),
};

bless $self, $class;
Expand Down
2 changes: 1 addition & 1 deletion lib/GPH/XMLHelper.pm → lib/GPH/Util/XMLHelper.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package GPH::XMLHelper;
package GPH::Util::XMLHelper;

use strict;
use warnings FATAL => 'all';
Expand Down
2 changes: 1 addition & 1 deletion t/unit/GPH/PHPMD.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe "class `$CLASS`" => sub {
field owner => '@teams/alpha';
field cycloLevel => 3;
field generator => object {
prop blessed => 'GPH::XMLHelper';
prop blessed => 'GPH::Util::XMLHelper';
};
end;
},
Expand Down
2 changes: 1 addition & 1 deletion t/unit/GPH/Psalm.t
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe 'configuration options' => sub {
field cache_dir => $expected_cache_dir;
field plugins => $expected_plugins;
field generator => object {
prop blessed => 'GPH::XMLHelper';
prop blessed => 'GPH::Util::XMLHelper';
};
etc;
},
Expand Down
4 changes: 2 additions & 2 deletions t/unit/GPH/XMLHelper.t → t/unit/GPH/Util/XMLHelper.t
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/perl
package t::unit::GPH::XMLHelper;
package t::unit::GPH::Util::XMLHelper;

use strict;
use warnings;

use Test2::V0 -target => 'GPH::XMLHelper';
use Test2::V0 -target => 'GPH::Util::XMLHelper';
use Test2::Tools::Spec;
use Data::Dumper;

Expand Down