@@ -, +, @@ $ kshell k$ prove t/db_dependent/Koha/Object.t --- t/db_dependent/Koha/Object.t | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) --- a/t/db_dependent/Koha/Object.t +++ a/t/db_dependent/Koha/Object.t @@ -215,7 +215,7 @@ subtest 'TO_JSON tests' => sub { subtest "to_api() tests" => sub { - plan tests => 28; + plan tests => 29; $schema->storage->txn_begin; @@ -365,6 +365,19 @@ subtest "to_api() tests" => sub { 'Koha::Exceptions::Object::MethodNotCoveredByTests', 'Unknown method exception thrown if is_count not specified'; + # Simulate a situation in which the relation returns undef instead of an empty iterator + my $patron_class = Test::MockModule->new('Koha::Patron'); + $patron_class->mock( 'holds', sub { + return; + }); + + $patron_api = $patron->to_api( + { + embed => { holds_count => { is_count => 1 } } + } + ); + is( $patron_api->{holds_count}, 0, 'Count embeds returns 0 if the relation is undef' ); + $schema->storage->txn_rollback; }; --