File: bug_082243.t

package info (click to toggle)
libdbd-mock-perl 1.59-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 512 kB
  • sloc: perl: 1,251; makefile: 7
file content (38 lines) | stat: -rw-r--r-- 938 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# This is test for bug rt#82243 - Bug with Regex in DBD::Mock::Session
use 5.008;

use strict;
use warnings;

use Test::More;

BEGIN {
    use_ok('DBD::Mock');
    use_ok('DBI');
}

{
    my $dbh = DBI->connect('dbi:Mock:', '', '', { RaiseError => 1, PrintError => 0 });
    isa_ok($dbh, 'DBI::db');
    
    my $session = DBD::Mock::Session->new((
        {
            statement    => 'SELECT bar FROM foo WHERE baz = ?',
            bound_params => [ qr/^125$/ ],
            results      => [[ 'bar' ], [ 15 ]]
        },
    ));
    isa_ok($session, 'DBD::Mock::Session');
    
    $dbh->{mock_session} = $session;
    
    my $sth = $dbh->prepare('SELECT bar FROM foo WHERE baz = ?');
    $sth->execute(125);
    my ($result) = $sth->fetchrow_array();
    is($result, 15, 'Regex matching on bound_params should work as expected.');

    # Shuts up warning when object is destroyed
    undef $dbh->{mock_session};
}

done_testing();