App-PRT

 view release on metacpan or  search on metacpan

t/App-PRT-Command-RenameClass.t  view on Meta::CPAN

    is file($file_out)->slurp, <<'CODE', 'package statement was rewritten';
# A package with a comment before the `package` statement
package My::Commented2;
use strict;
use warnings;

sub new { bless {}, shift; }

1;
CODE

}

sub execute_package_with_pod_first : Tests {
    my $directory = t::test::prepare_test_code('tokens_before_package');

    my $command = App::PRT::Command::RenameClass->new;

    $command->register('My::POD' => 'My::POD2');

    my $file_in = "$directory/lib/My/POD.pm";
    my $file_out = "$directory/lib/My/POD2.pm";

    is $command->execute($file_in), $file_out, 'returns destination file when success';

    ok ! -f $file_in, "$file_in doesn't exist";
    ok -e $file_out, "$file_out exists";

    is file($file_out)->slurp, <<'CODE', 'package statement was rewritten';
=head1 NAME

My::POD - A package with POD before the `package` statement

=cut

package My::POD2;
use strict;
use warnings;

sub new { bless {}, shift; }

1;
CODE

}
sub execute_with_inherit : Tests {
    my $directory = t::test::prepare_test_code('inherit');

    my $command = App::PRT::Command::RenameClass->new;

    $command->register('Parent' => 'Boss');

    subtest 'target class' => sub {
        my $file = "$directory/inherit.pl";

        $command->execute($file);

        ok -e $file, "script file exists";
        is file($file)->slurp, <<'CODE', 'use parent, use base statements were rewritten';
package Child1 {
    use DateTime;
    use utf8;
    use parent 'Boss';
};

package Child2 {
    use parent qw(Boss AnotherParent YetAnother::Parent);
};

package Child3 {
    use base 'Boss';
};

package Child4 {
    use base 'Boss';
};

package Child5 {
    use base 'Boss';
};

package Child6 {
    use base 'Boss';
};

package GrandChild {
    use base 'Child';
};
CODE

     };

}

sub execute_test_more_style_test_file : Tests {
    my $directory = t::test::prepare_test_code('dinner');

    my $command = App::PRT::Command::RenameClass->new;

    $command->register('My::Food' => 'My::Meal');

    my $file = "$directory/t/001-my-food._t";

    $command->execute($file);

    is file($file)->slurp, <<'CODE', 'test replaced';
use Test::More tests => 5;

use_ok 'My::Meal';
require_ok 'My::Meal';

new_ok 'My::Meal';
isa_ok My::Meal->new, 'My::Meal';

subtest 'name' => sub {
    my $pizza = My::Meal->new('Pizza');
    is $pizza->name, 'Pizza';
};
CODE

}



( run in 1.125 second using v1.01-cache-2.11-cpan-39bf76dae61 )