Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functional tests #14

Merged
merged 1 commit into from
Feb 17, 2024
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
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ WriteMakefile(
"Test2::Tools::Spec" => 0,
"Data::Dumper" => 0,
"Readonly" => 0,
"File::Temp" => 0,
},
'test' => {
TESTS => 't/unit/GPH/*.t t/unit/GPH/*/*.t'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ these scripts rely on a couple of environment variables.
the following environment variables are used by all scripts
- `DEV_TEAM`: owner as defined in the `CODEOWNERS` file
- `EXCLUDE_PATHS`: (optional): comma seperated list of paths to exclude while defined in the `CODEOWNERS` file for owner `DEV_TEAM`. defaults to empty string.
- `CODEOWNERS`: (optional): path to codeowners file, defaults to `./CODEOWNERS`

## details

Expand Down
3 changes: 2 additions & 1 deletion codeowner2commaseparatedlist.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my @excludes = split /,/, ($ENV{'EXCLUDE_PATHS'} || '');
my $codeonwers = $ENV{'CODEOWNERS'} || './CODEOWNERS';

my %config = (
owner => $owner,
codeowners => './CODEOWNERS',
codeowners => $codeonwers,
excludes => \@excludes,
);

Expand Down
7 changes: 4 additions & 3 deletions codeowner2phpstan.pl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my @excludes = split /,/, ($ENV{'EXCLUDE_PATHS'} || '');
my $codeonwers = $ENV{'CODEOWNERS'} || './CODEOWNERS';

my %gitlabConfig = (
owner => $owner,
codeowners => './CODEOWNERS',
codeowners => $codeonwers,
excludes => \@excludes,
);

Expand All @@ -22,13 +23,13 @@
my @includes = split /,/, ($ENV{'PHPSTAN_INCLUDES'} || './phpstan.ci.neon');
my @ignored = split /,/, ($ENV{'PHPSTAN_IGNORED_DIRS'} || '');

@ignored = (@ignored, $gitlab->getBlacklistPaths()); # merge ignored dirs with blacklist
@ignored = (@ignored, @{$gitlab->getBlacklistPaths()}); # merge ignored dirs with blacklist

my %config = (
level => $ENV{'PHPSTAN_LEVEL'} || 6,
paths => $gitlab->getPaths(),
baseline => $ENV{'PHPSTAN_BASELINE'},
ignoredDirectories => @ignored,
ignoredDirectories => \@ignored,
cacheDir => $ENV{'PHPSTAN_CACHE_DIR'},
includes => \@includes,
threads => $ENV{'PHPSTAN_THREADS'}
Expand Down
6 changes: 4 additions & 2 deletions codeowner2psalm.pl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my @excludes = split /,/, ($ENV{'EXCLUDE_PATHS'} || '');
my $codeonwers = $ENV{'CODEOWNERS'} || './CODEOWNERS';

my %gitlabConfig = (
owner => $owner,
codeowners => './CODEOWNERS',
codeowners => $codeonwers,
excludes => \@excludes,
);

Expand All @@ -40,8 +41,9 @@

if ($clone eq 1) {
my @blacklist = split /,/, ($ENV{'PSALM_EXCLUDE_HANDLERS'} || '');
my $base = $ENV{'PSALM_BASE_CONFIG'} || './psalm.xml';

print $psalm->getConfigWithIssueHandlers('./psalm.xml', @blacklist);
print $psalm->getConfigWithIssueHandlers($base, @blacklist);
}
else {
print $psalm->getConfig();
Expand Down
11 changes: 7 additions & 4 deletions coverage2codeowner.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

use GPH::PHPUnit;

my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my @excludes = split /,/, ($ENV{'EXCLUDE_PATHS'} || '');
my $codeonwers = $ENV{'CODEOWNERS'} || './CODEOWNERS';
my $classmap = $ENV{'CLASSMAP'} || './vendor/composer/autoload_classmap.php';

my %config = (
owner => $owner,
classmap => './vendor/composer/autoload_classmap.php',
codeowners => './CODEOWNERS',
threshold => $ENV{'MIN_COVERAGE'},
classmap => $classmap,
codeowners => $codeonwers,
threshold => $ENV{'MIN_COVERAGE'},
excludes => \@excludes,
baseline => $ENV{'PHPUNIT_BASELINE'}
);
Expand Down
5 changes: 0 additions & 5 deletions doc/Infection.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ several ways to interact with infection, here are some...

this script collects the paths defined in your CODEOWNERS file for given codeowner and outputs them to a value which can be used as for example a filter value for php infection.

### assumptions

this script assumes the presence of the CODEOWNERS file in the root directory of you project.
though configurable in the `codeowner2commaseparatedlist.pl` file, for now no plans to make that configurable or accept it as input parameter.

> [!CAUTION]
> the `codeowner2commaseparatedlist.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).

Expand Down
6 changes: 0 additions & 6 deletions doc/PHPMD.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ use `codeowner2phpmd.pl` this script generates a phpmd config which currently on
the following environment variable is used by the codeowner2phpmd script
- `CYCLO_LEVEL`: cyclomatic complexity threshold. defaults to 10

### global variables

the following environment variables are used by all scripts
- `DEV_TEAM`: owner as defined in the `CODEOWNERS` file
- `EXCLUDE_PATHS`: (optional): comma seperated list of paths to exclude while defined in the `CODEOWNERS` file for owner `DEV_TEAM`. defaults to empty string.

### example config

> gitlab-ci-yml
Expand Down
3 changes: 0 additions & 3 deletions doc/PHPStan.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ the following environment variables are used by the codeowner2phpstan script
- `PHPSTAN_IGNORED_DIRS`: (optional) directories to ignore
- `PHPSTAN_INCLUDES`: (optional) comma seperated list of files to include
- `PHPSTAN_THREADS`: (optional) number of threads to use (defaults to `4`)
-
### assumptions

this script assumes the presence of the CODEOWNERS file in the root directory of you project.

### example config

Expand Down
5 changes: 0 additions & 5 deletions doc/PHPUnit.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ the following environment variable is used by the coverage2codeowner script
- `MIN_COVERAGE` (optional): minimum coverage required for the job to succeed. defaults to 0.1
- `PHPUNIT_BASELINE` (optional): filepath of file containing paths to files and / or directories which are within the defined code space, but should be ignored while calculating coverage statistics.

### assumptions

this script assumes the presence of composer at the usual location and the CODEOWNERS file in the root directory of you project.
though both paths are configurable in the `coverage2codeowner.pl` file, for now no plans to make that configurable or accept them as input parameters.

> [!CAUTION]
> the `GPH::Composer.pm` module requires either an optimised or an authoritative classmap file so make sure to generate one of those in your configuration (see example below).

Expand Down
10 changes: 0 additions & 10 deletions doc/Psalm.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

`codeowner2psalm.pl` script generates a psalm config based on the paths defined in your `CODEOWNERS` file.

### assumptions

this script assumes the presence of the CODEOWNERS file in the root directory of you project.

### global variables

the following environment variables are used by all scripts
- `DEV_TEAM`: owner as defined in the `CODEOWNERS` file
- `EXCLUDE_PATHS`: (optional): comma seperated list of paths to exclude while defined in the `CODEOWNERS` file for owner `DEV_TEAM`. defaults to empty string.

### variables

the following environment variables are used by the codeowner2psalm script
Expand Down
2 changes: 1 addition & 1 deletion lib/GPH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package GPH;
use strict;
use warnings FATAL => 'all';

our $VERSION = '1.1.0';
our $VERSION = '1.1.1';

1;
2 changes: 1 addition & 1 deletion lib/GPH/PHPUnit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ sub new {

bless $self, $class;

if (exists($args{baseline})) {
if (exists($args{baseline}) and defined $args{baseline}) {
open(my $fh, '<', $args{baseline}) or die "unable to open phpunit baseline file $args{baseline} $!";
my @lines = ();

Expand Down
6 changes: 4 additions & 2 deletions stdin2codeowner-filter.pl
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my @excludes = split /,/, ($ENV{'EXCLUDE_PATHS'} || '');
my $codeonwers = $ENV{'CODEOWNERS'} || './CODEOWNERS';

my %config = (
owner => $owner,
codeowners => './CODEOWNERS',
excludes => \@excludes
codeowners => $codeonwers,
excludes => \@excludes,
);

my $gitlab = GPH::Gitlab->new(%config);
Expand Down
45 changes: 45 additions & 0 deletions t/functional/codeowner2commaseparatedlist.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/perl
use strict;
use warnings;

use Test2::V0;
use Test2::Tools::Spec;

use Data::Dumper;
use File::Temp;

BEGIN {
@ENV{"DEV_TEAM", "EXCLUDE_PATHS", "CODEOWNERS"} = ('@teams/alpha', '.gitlab-ci.yml', './t/share/Gitlab/CODEOWNERS-functional');
}

describe "generate phpmd config" => sub {
tests "compare config" => sub {
my ($c, $fh, $exception, $warnings, $stdout, $file);

$exception = dies {
$warnings = warns {
$file = File::Temp::tmpnam();
$c = system("$^X codeowner2commaseparatedlist.pl > $file");
};
};

is($exception, undef, 'no exception thrown');
is($warnings, 0, 'no warnings generated');
is($c, 0, 'program exited with successful exit code', $c);

open $fh, '<', $file or die $!;
$stdout = do {
local $/;
<$fh>
};
close($fh);

is($stdout, '/src/Command/,/src/Service/', 'config content correct') or diag Dumper($stdout);

unlink($file);

};
};

done_testing();

51 changes: 51 additions & 0 deletions t/functional/codeowner2phpmd.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/perl
use strict;
use warnings;

use Test2::V0;
use Test2::Tools::Spec;

use Data::Dumper;
use File::Temp;

BEGIN {
@ENV{"DEV_TEAM", "CYCLO_LEVEL"} = ('@teams/alpha', "3");
}

describe "generate phpmd config" => sub {
tests "compare config" => sub {
my ($c, $fh, $file, $mock, $stdout, $exception, $warnings);

$exception = dies {
$warnings = warns {
$file = File::Temp::tmpnam();
$c = system("$^X codeowner2phpmd.pl > $file");
};
};

is($exception, undef, 'no exception thrown');
is($warnings, 0, 'no warnings generated');
is($c, 0, 'program exited with successful exit code', $c);

open $fh, '<', './t/share/PHPMD/phpmd-ruleset-functional.xml' or die $!;
$mock = do {
local $/;
<$fh>
};
close($fh);

open $fh, '<', $file or die $!;
$stdout = do {
local $/;
<$fh>
};
close($fh);

is($stdout, $mock, 'config content correct') or diag Dumper($stdout);

unlink($file);
};
};

done_testing();

51 changes: 51 additions & 0 deletions t/functional/codeowner2phpstan.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/perl
use strict;
use warnings;

use Test2::V0;
use Test2::Tools::Spec;

use Data::Dumper;
use File::Temp;

BEGIN {
@ENV{"DEV_TEAM", "CODEOWNERS", "EXCLUDE_PATHS", "PHPSTAN_LEVEL", "PHPSTAN_IGNORED_DIRS", "PHPSTAN_INCLUDES", "PHPSTAN_BASELINE", "PHPSTAN_CACHE_DIR", "PHPSTAN_THREADS"} = ('@teams/alpha', './t/share/Gitlab/CODEOWNERS-functional', '.gitlab-ci.yml', '1', "/ignored/", '/includes/', './baselines/baseline.xml', '/tmp', '6');
}

describe "generate PHPStan config" => sub {
tests "compare config" => sub {
my ($c, $fh, $file, $mock, $stdout, $exception, $warnings);

$exception = dies {
$warnings = warns {
$file = File::Temp::tmpnam();
$c = system("$^X codeowner2phpstan.pl > $file");
};
};

is($exception, undef, 'no exception thrown');
is($warnings, 0, 'no warnings generated');
is($c, 0, 'program exited with successful exit code', $c);

open $fh, '<', './t/share/PHPStan/phpstan-functional.neon' or die $!;
$mock = do {
local $/;
<$fh>
};
close($fh);

open $fh, '<', $file or die $!;
$stdout = do {
local $/;
<$fh>
};
close($fh);

is($stdout, $mock, 'config content correct') or diag Dumper($stdout);

unlink($file);
};
};

done_testing();

Loading
Loading