Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added data_sources stuff and prepared for release

  • Loading branch information...
commit 7b1763d38aed5f426bc863daa1608b4085dd6a2b 1 parent 1c03960
Stevan Little authored
View
12 Changes
@@ -1,11 +1,19 @@
Revision history for Perl extension DBD::Mock.
0.26 Fri Apr 08 2005
- - Added get_info() and set_info()
- - Added tests for this
+ - added Rob Kinyon to the AUTHORS list
+ - added get_info() and set_info()
+ - added tests for this
- added bind_param_inout() for DBD::Mock::st
code from Thilo Planz (Thanks Thilo)
- added tests for this
+ - added mock_data_sources and mock_add_data_sources
+ properties for the Driver and Database handles
+ - added tests and docs for this
+ - added begin_work(), commit() and rollback() method
+ implementations which wrap the prepare() method and
+ deal with the AutoCommit value per the DBI spec.
+ - added tests and docs for this
0.25 Sat Feb 26 2005
- removed the DBD::Mock::_error_handler routine
View
2  META.yml
@@ -1,6 +1,6 @@
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: DBD-Mock
-version: 0.25
+version: 0.26
version_from: VERSION
installdirs: site
requires:
View
2  VERSION
@@ -1 +1 @@
-$VERSION = '0.25';
+$VERSION = '0.26';
View
55 lib/DBD/Mock.pm
@@ -118,20 +118,52 @@ sub connect {
return $dbh;
}
+sub FETCH {
+ my ($drh, $attr) = @_;
+ if ($attr =~ /^mock_/) {
+ if ($attr eq 'mock_connect_fail') {
+ return $drh->{'mock_connect_fail'};
+ }
+ elsif ($attr eq 'mock_data_sources') {
+ unless (defined $drh->{'mock_data_sources'}) {
+ $drh->{'mock_data_sources'} = [ 'DBI:Mock:' ];
+ }
+ return $drh->{'mock_data_sources'};
+ }
+ else {
+ return $drh->SUPER::FETCH($attr);
+ }
+ }
+ else {
+ return $drh->SUPER::FETCH($attr);
+ }
+}
+
sub STORE {
my ($drh, $attr, $value) = @_;
if ($attr =~ /^mock_/) {
if ($attr eq 'mock_connect_fail') {
return $drh->{'mock_connect_fail'} = $value ? 1 : 0;
}
- }
+ elsif ($attr eq 'mock_data_sources') {
+ if (ref($value) ne 'ARRAY') {
+ $drh->DBI::set_err(1, "You must pass an array ref of data sources");
+ return undef;
+ }
+ return $drh->{'mock_data_sources'} = $value;
+ }
+ elsif ($attr eq 'mock_add_data_sources') {
+ return push @{$drh->{'mock_data_sources'}} => $value;
+ }
+ }
else {
return $drh->SUPER::STORE($attr, $value);
}
}
sub data_sources {
- return ("DBI:Mock:");
+ my $drh = shift;
+ return map { (/^DBI\:Mock\:/i) ? $_ : "DBI:Mock:$_" } @{$drh->FETCH('mock_data_sources')};
}
# Necessary to support DBI < 1.34
@@ -406,6 +438,9 @@ sub STORE {
if defined $value;
$dbh->{mock_session} = $value;
}
+ elsif ($attrib =~ /^mock_(add_)?data_sources/) {
+ $dbh->{Driver}->STORE($attrib, $value);
+ }
elsif ($attrib =~ /^mock/) {
return $dbh->{$attrib} = $value;
}
@@ -1093,6 +1128,14 @@ This is a boolean property which when set to true (C<1>) will not allow DBI to c
This feature is conceptually different from the 'mock_can_connect' attribute of the C<$dbh> in that it has a driver-wide scope, where 'mock_can_connect' is handle-wide scope. It also only prevents the initial connection, any C<$dbh> handles created prior to setting 'mock_connect_fail' to true (C<1>) will still go on working just fine.
+=item B<mock_data_sources>
+
+This is an ARRAY reference which holds fake data sources which are returned by the Driver and Database Handle's C<data_source()> method.
+
+=item B<mock_add_data_sources>
+
+This takes a string and adds it to the 'mock_data_sources' attribute.
+
=back
=head2 Database Handle Properties
@@ -1300,6 +1343,10 @@ Instead of providing a subroutine reference you can use an object. The only requ
my $parser = SQL::Parser->new( 'mysql', { RaiseError => 1 } );
$dbh->{mock_add_parser} = $parser;
+=item B<mock_data_sources> & B<mock_add_data_sources>
+
+These properties will dispatch to the Driver's properties of the same name.
+
=back
=head2 Database Driver Methods
@@ -1636,9 +1683,9 @@ I use L<Devel::Cover> to test the code coverage of my tests, below is the L<Deve
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt branch cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
- lib/DBD/Mock.pm 90.7 86.6 82.6 94.2 0.0 100.0 89.1
+ DBD/Mock.pm 93.2 88.4 77.2 94.8 0.0 100.0 90.7
---------------------------- ------ ------ ------ ------ ------ ------ ------
- Total 90.7 86.6 82.6 94.2 0.0 100.0 89.1
+ Total 93.2 88.4 77.2 94.8 0.0 100.0 90.7
---------------------------- ------ ------ ------ ------ ------ ------ ------
=head1 SEE ALSO
View
19 t/10_db_handle.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More tests => 16;
BEGIN {
use_ok('DBD::Mock');
@@ -73,3 +73,20 @@ BEGIN {
$dbh->disconnect();
}
+
+
+{
+ my $dbh = DBI->connect( 'DBI:Mock:', '', '' );
+ is_deeply(
+ [ $dbh->data_sources() ],
+ [ 'DBI:Mock:' ],
+ '... got the right data sources');
+
+ $dbh->{'mock_add_data_sources'} = 'foo';
+
+ is_deeply(
+ [ $dbh->data_sources() ],
+ [ 'DBI:Mock:', 'DBI:Mock:foo' ],
+ '... got the right data sources');
+
+}
View
21 t/11_dr_handle.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 22;
+use Test::More tests => 24;
BEGIN {
use_ok('DBD::Mock');
@@ -27,7 +27,24 @@ is($drh->{Attribution},
is($drh, $drh2, '... got the same driver');
}
-is($drh->data_sources(), 'DBI:Mock:', '... got the expected data sources');
+is_deeply(
+ [ $drh->data_sources() ],
+ [ 'DBI:Mock:' ],
+ '... got the expected data sources');
+
+$drh->{mock_data_sources} = [ 'test', 'DBI:Mock:mysql' ];
+
+is_deeply(
+ [ $drh->data_sources() ],
+ [ 'DBI:Mock:test', 'DBI:Mock:mysql' ],
+ '... got the expected data sources');
+
+$drh->{mock_add_data_sources} = 'foo';
+
+is_deeply(
+ [ $drh->data_sources() ],
+ [ 'DBI:Mock:test', 'DBI:Mock:mysql', 'DBI:Mock:foo' ],
+ '... got the expected data sources');
{ # connect through the driver handle
my $dbh = $drh->connect();
Please sign in to comment.
Something went wrong with that request. Please try again.