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
4 changes: 2 additions & 2 deletions 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.2';
our $VERSION = '1.1.3';

1;

Expand All @@ -17,7 +17,7 @@ GPH - Gitlab Perl Helpers

set of modules and integration scripts to support building code owner specific ci jobs for gitlab

=head1 API
=head1 MODULES

=over 4

Expand Down
47 changes: 35 additions & 12 deletions lib/GPH/PHPUnit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,7 @@ sub new {

bless $self, $class;

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

while (<$fh>) {
chomp $_;
push(@lines, $_);
}
close($fh);

$self->{baseline} = \@lines;
}
$self->parseBaseline(%args);

return $self;
}
Expand Down Expand Up @@ -68,6 +57,26 @@ sub parse {
return ($self->{stats}->exitCode());
}

sub parseBaseline {
my ($self, %args) = @_;
my ($fh, @lines);

if (exists($args{baseline}) and defined $args{baseline}) {

open($fh, '<', $args{baseline}) or die $!;

@lines = ();

while (<$fh>) {
chomp $_;
push(@lines, $_);
}
close($fh);

$self->{baseline} = \@lines;
}
}

sub classReport {
my $self = shift;

Expand Down Expand Up @@ -141,6 +150,20 @@ parse PHPUnit output from <>, print warning or note when appropriate and return

print matched coverage lines

=item C<< -E<gt>parseBaseline(%args) >> B<< (internal) >>

parse baseline file. takes a hash of options, valid option keys include:

=over

=item baseline

path to baseline file which contains paths to ignore while parsing PHPUnit's output

=back

code owner name

=back

=head1 AUTHOR
Expand Down
4 changes: 2 additions & 2 deletions lib/GPH/Psalm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ sub getConfig {
}

sub getConfigWithIssueHandlers {
my ($self, $path, $blacklist) = @_;
my ($self, $path, @blacklist) = @_;

my $dom = XML::LibXML->load_xml(location => $path);
my $config = XML::LibXML->load_xml(string => $self->getConfig());

my ($handlers) = $dom->findnodes('//*[local-name()="issueHandlers"]');

foreach my $exclude ($blacklist) {
foreach my $exclude (@blacklist) {
next unless defined $exclude;

my ($remove) = $handlers->findnodes("//*[local-name()=\"${exclude}\"]");
Expand Down
1 change: 1 addition & 0 deletions t/share/Psalm/psalm-issue-handlers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<file name="/src/DependencyInjection/Configuration.php"/>
<ignoreFiles>
<directory name="vendor"/>
<file name="example.php"/>
</ignoreFiles>
</projectFiles>
<plugins>
Expand Down
1 change: 1 addition & 0 deletions t/share/Psalm/psalm.xml → t/share/Psalm/psalm-max.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<file name="/src/DependencyInjection/Configuration.php"/>
<ignoreFiles>
<directory name="vendor"/>
<file name="example.php"/>
</ignoreFiles>
</projectFiles>
<plugins>
Expand Down
8 changes: 8 additions & 0 deletions t/share/Psalm/psalm-min.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" cacheDirectory="./psalm" errorLevel="2" findUnusedBaselineEntry="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<projectFiles>
<directory name="/src/Command"/>
<directory name="/src/Service"/>
<file name="/src/DependencyInjection/Configuration.php"/>
</projectFiles>
</psalm>
4 changes: 2 additions & 2 deletions t/unit/GPH/PHPUnit.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe "class `$CLASS`" => sub {
ok(lives {$CLASS->new(('owner' => '@teams/alpha', 'codeowners' => CODEOWNERS_FILE, classmap => CLASSMAP_FILE))}, 'lives with mandatory config settings') or note($@);
};

tests "baseline file not found" => sub {
ok(dies {$CLASS->new((codeowners => CODEOWNERS_FILE, owner => '@teams/alpha', baseline => 'foo.txt'))}, 'died with baseline not found') or note($@);
tests "baseline file tests" => sub {
ok(dies {$CLASS->new((codeowners => CODEOWNERS_FILE, owner => '@teams/alpha', classmap => CLASSMAP_FILE, baseline => 'foo.txt'))}, 'died with baseline not found') or note($@);
ok(lives {$CLASS->new((codeowners => CODEOWNERS_FILE, owner => '@teams/alpha', classmap => CLASSMAP_FILE, baseline => PHPUNIT_BASELINE_FILE))}, 'lives with correct baseline') or note($@);
};
};
Expand Down
30 changes: 25 additions & 5 deletions t/unit/GPH/Psalm.t
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,35 @@ describe "class `$CLASS` config generation" => sub {
my %config = (
level => 2,
paths => \@paths,
ignored_directories => [ 'vendor' ],
ignored_directories => [ 'vendor', 'example.php' ],
baseline => 'baselines/psalm-baseline.xml',
baseline_check => 'true',
cache_dir => './psalm',
plugins => [ 'Psalm\SymfonyPsalmPlugin\Plugin' ],
);

my $object = $CLASS->new(%config);
tests 'compare max config contents' => sub {
my $object = $CLASS->new(%config);
my $config = $object->getConfig();
my $mock;

open(my $fh, '<', './t/share/Psalm/psalm-max.xml');

local $/;
$mock = <$fh>;

close($fh);

is($config, $mock, 'config content correct');
};

tests 'compare min config contents' => sub {
my $object = $CLASS->new((level => 2, paths => \@paths));

tests 'compare config contents' => sub {
my $config = $object->getConfig();
my $mock;

open(my $fh, '<', './t/share/Psalm/psalm.xml');
open(my $fh, '<', './t/share/Psalm/psalm-min.xml');

local $/;
$mock = <$fh>;
Expand All @@ -137,7 +152,12 @@ describe "class `$CLASS` config generation" => sub {
};

tests 'compare config with issue handlers content' => sub {
my $config = $object->getConfigWithIssueHandlers('./t/share/Psalm/psalm-stub.xml', qw{MoreSpecificImplementedParamType NonExistingHandler});
my $object = $CLASS->new(%config);

my @blacklist = qw{MoreSpecificImplementedParamType NonExistingHandler};
$blacklist[2] = undef;

my $config = $object->getConfigWithIssueHandlers('./t/share/Psalm/psalm-stub.xml', @blacklist);
my $mock;

open(my $fh, '<', './t/share/Psalm/psalm-issue-handlers.xml');
Expand Down