|
Lines 1-9
Link Here
|
| 1 |
package t::lib::Mocks; |
1 |
package t::lib::Mocks; |
| 2 |
|
2 |
|
|
|
3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 4 |
use C4::Context; |
19 |
use C4::Context; |
| 5 |
|
20 |
|
| 6 |
use Test::MockModule; |
21 |
use Test::MockModule; |
|
|
22 |
use Test::MockObject; |
| 7 |
|
23 |
|
| 8 |
my %configs; |
24 |
my %configs; |
| 9 |
sub mock_config { |
25 |
sub mock_config { |
|
Lines 74-77
sub mock_userenv {
Link Here
|
| 74 |
); |
90 |
); |
| 75 |
} |
91 |
} |
| 76 |
|
92 |
|
|
|
93 |
=head3 mock_logger |
| 94 |
|
| 95 |
my $mocked_logger = t::lib::Mocks::mock_logger({ [ warn => 0|1 ] }); |
| 96 |
|
| 97 |
Mocks the Koha::Logger for testing purposes. The mocked subs (log levels) |
| 98 |
return the passed string, in case we want to test the debugging string contents. |
| 99 |
|
| 100 |
A I<warn> parameter can be passed so the call to the logging method warns instead |
| 101 |
of just returning (useful for writing tests). |
| 102 |
|
| 103 |
=cut |
| 104 |
|
| 105 |
sub mock_logger { |
| 106 |
my ($params) = @_; |
| 107 |
|
| 108 |
my $warn = $params->{warn}; |
| 109 |
|
| 110 |
my $mocked_logger_class = Test::MockModule->new("Koha::Logger"); |
| 111 |
$mocked_logger_class->mock( 'get', sub |
| 112 |
{ |
| 113 |
my $mocked_logger = Test::MockObject->new(); |
| 114 |
$mocked_logger->mock( 'debug', sub { |
| 115 |
my ( $self, $string ) = @_; |
| 116 |
warn $string |
| 117 |
if $warn; |
| 118 |
return $string |
| 119 |
}); |
| 120 |
$mocked_logger->mock( 'warn', sub { |
| 121 |
my ( $self, $string ) = @_; |
| 122 |
warn $string |
| 123 |
if $warn; |
| 124 |
return $string; |
| 125 |
}); |
| 126 |
} |
| 127 |
); |
| 128 |
|
| 129 |
return $mocked_logger_class; |
| 130 |
} |
| 131 |
|
| 77 |
1; |
132 |
1; |
| 78 |
- |
|
|