1 package DBIC::SqlMakerTest;
9 use SQL::Abstract::Test;
22 sub is_same_sql_bind {
23 # unroll possible as_query arrayrefrefs
29 if ( ref $chunk eq 'REF' and ref $$chunk eq 'ARRAY' ) {
30 my ($sql, @bind) = @$$chunk;
31 push @args, ($sql, \@bind);
34 push @args, $chunk, shift @_;
41 croak "Unexpected argument(s) supplied to is_same_sql_bind: " . join ('; ', @_)
45 goto &SQL::Abstract::Test::is_same_sql_bind;
48 *is_same_sql = \&SQL::Abstract::Test::is_same_sql;
49 *is_same_bind = \&SQL::Abstract::Test::is_same_bind;
50 *eq_sql = \&SQL::Abstract::Test::eq_sql;
51 *eq_bind = \&SQL::Abstract::Test::eq_bind;
52 *eq_sql_bind = \&SQL::Abstract::Test::eq_sql_bind;
61 DBIC::SqlMakerTest - Helper package for testing sql_maker component of DBIC
66 use DBIC::SqlMakerTest;
68 my ($sql, @bind) = $schema->storage->sql_maker->select(%args);
71 $expected_sql, \@expected_bind,
77 Exports functions that can be used to compare generated SQL and bind values.
79 This is a thin wrapper around L<SQL::Abstract::Test>, which makes it easier
80 to compare as_query sql/bind arrayrefrefs directly.
84 =head2 is_same_sql_bind
87 $given_sql, \@given_bind,
88 $expected_sql, \@expected_bind,
94 $expected_sql, \@expected_bind,
99 \[$given_sql, @given_bind],
100 $expected_sql, \@expected_bind,
104 Compares given and expected pairs of C<($sql, \@bind)>, and calls
105 L<Test::Builder/ok> on the result, with C<$test_msg> as message.
115 Compares given and expected SQL statement, and calls L<Test::Builder/ok> on the
116 result, with C<$test_msg> as message.
126 Compares given and expected bind value lists, and calls L<Test::Builder/ok> on
127 the result, with C<$test_msg> as message.
131 my $is_same = eq_sql($given_sql, $expected_sql);
133 Compares the two SQL statements. Returns true IFF they are equivalent.
137 my $is_same = eq_sql(\@given_bind, \@expected_bind);
139 Compares two lists of bind values. Returns true IFF their values are the same.
143 my $is_same = eq_sql_bind(
144 $given_sql, \@given_bind,
145 $expected_sql, \@expected_bind
148 Compares the two SQL statements and the two lists of bind values. Returns true
149 IFF they are equivalent and the bind values are the same.
154 L<SQL::Abstract::Test>, L<Test::More>, L<Test::Builder>.
158 Norbert Buchmuller, <norbi@nix.hu>
160 =head1 COPYRIGHT AND LICENSE
162 Copyright 2008 by Norbert Buchmuller.
164 This library is free software; you can redistribute it and/or modify
165 it under the same terms as Perl itself.