use Test::More tests => 4;
use Test::Mojo;
use t::lib::TestBuilder;
+use t::lib::Mocks;
use DateTime;
use Koha::Items;
use Koha::Patrons;
+my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new();
-my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
+$schema->storage->txn_begin;
+
+# FIXME: sessionStorage defaults to mysql, but it seems to break transaction handling
+# this affects the other REST api tests
+t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' );
$ENV{REMOTE_ADDR} = '127.0.0.1';
my $t = Test::Mojo->new('Koha::REST::V1');
my $biblionumber2 = create_biblio('RESTful Web APIs');
my $itemnumber2 = create_item($biblionumber2, 'TEST000002');
+my $dbh = C4::Context->dbh;
$dbh->do('DELETE FROM reserves');
$dbh->do('DELETE FROM issuingrules');
$dbh->do(q{
->json_like('/error', qr/tooManyReserves/);
};
-
-$dbh->rollback;
+$schema->storage->txn_rollback;
sub create_biblio {
my ($title) = @_;
use Test::More tests => 20;
use Test::Mojo;
use t::lib::TestBuilder;
+use t::lib::Mocks;
use C4::Auth;
use C4::Context;
use Koha::Database;
use Koha::Patron;
+my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new();
-my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
+$schema->storage->txn_begin;
$ENV{REMOTE_ADDR} = '127.0.0.1';
my $t = Test::Mojo->new('Koha::REST::V1');
->json_is('/borrowernumber' => $borrower->{ borrowernumber })
->json_is('/surname' => $borrower->{ surname });
-$dbh->rollback;
+$schema->storage->txn_rollback;