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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512
|
package Test::DBIx::Class;
use 5.008;
use strict;
use warnings;
use base 'Test::Builder::Module';
our $VERSION = '0.52';
our $AUTHORITY = 'cpan:JJNAPIORK';
use Config::Any;
use Data::Visitor::Callback;
use Digest::MD5;
use Hash::Merge;
use Path::Class;
use Scalar::Util ();
use Sub::Exporter;
use Test::DBIx::Class::SchemaManager;
use Test::Deep ();
use Test::More ();
sub eq_or_diff2 {
my ($given, $expected, $message) = @_;
my ($ok, $stack) = Test::Deep::cmp_details($given, $expected);
if($ok) {
Test::More::pass($message);
} else {
my $diag = Test::Deep::deep_diag($stack);
Test::More::fail("$message: $diag");
}
}
sub import {
my ($class, @opts) = @_;
my ($schema_manager, $merged_config, @exports) = $class->_initialize(@opts);
my $exporter = Sub::Exporter::build_exporter({
exports => [
dump_settings => sub {
return sub {
return $merged_config, @exports;
};
},
Schema => sub {
return sub {
return $schema_manager->schema;
}
},
ResultSet => sub {
my ($local_class, $name, $arg) = @_;
return sub {
my $source = shift @_;
my $search = shift @_;
my $resultset = $schema_manager->schema->resultset($source);
if(my $global_search = $arg->{search}) {
my @global_search = ref $global_search eq 'ARRAY' ? @$global_search : ($global_search);
$resultset = $resultset->search(@global_search);
}
if(my $global_cb = $arg->{exec}) {
$resultset = $global_cb->($resultset);
}
if($search) {
my @search = ref $search eq 'ARRAY' ? @$search : ($search, @_);
$resultset = $resultset->search(@search);
}
return $resultset;
}
},
is_result => sub {
my ($local_class, $name, $arg) = @_;
my $global_class = defined $arg->{isa_class} ? $arg->{isa_class} : '';
return sub {
my $rs = shift @_;
my $compare = shift @_ || $global_class || "DBIx::Class";
my $message = shift @_;
Test::More::isa_ok($rs, $compare, $message);
}
},
is_resultset => sub {
my ($local_class, $name, $arg) = @_;
my $global_class = defined $arg->{isa_class} ? $arg->{isa_class} : '';
return sub {
my $rs = shift @_;
my $compare = shift @_ || $global_class || "DBIx::Class::ResultSet";
my $message = shift @_;
Test::More::isa_ok($rs, $compare, $message);
}
},
eq_result => sub {
return sub {
my ($result1, $result2, $message) = @_;
$message = defined $message ? $message : ref($result1) . " equals " . ref($result2);
if( ref($result1) eq ref($result2) ) {
eq_or_diff2(
{$result2->get_columns},
{$result1->get_columns},
$message,
);
} else {
Test::More::fail($message ." :Result arguments not of same class");
}
},
},
eq_resultset => sub {
return sub {
my ($rs1, $rs2, $message) = @_;
$message = defined $message ? $message : ref($rs1) . " equals " . ref($rs2);
if( ref($rs1) eq ref($rs2) ) {
($rs1, $rs2) = map {
my $me = $_->current_source_alias;
my @pks = map { "$me.$_"} $_->result_source->primary_columns;
my @result = $_->search({}, {
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
order_by => [@pks],
})->all;
[@result];
} ($rs1, $rs2);
eq_or_diff2([$rs2],[$rs1],$message);
} else {
Test::More::fail($message ." :ResultSet arguments not of same class");
}
},
},
hri_dump => sub {
return sub {
(shift)->search ({}, {
result_class => 'DBIx::Class::ResultClass::HashRefInflator'
});
}
},
fixtures_ok => sub {
return sub {
my ($arg, $message) = @_;
$message = defined $message ? $message : 'Fixtures Installed';
if ($arg && ref $arg && (ref $arg eq 'CODE')) {
eval {
$arg->($schema_manager->schema);
}; if($@) {
Test::More::fail($message);
$schema_manager->builder->diag($@);
} else {
Test::More::pass($message);
}
} elsif( $arg && ref $arg && (ref $arg eq 'HASH' || ref $arg eq 'ARRAY') ) {
my @return;
eval {
@return = $schema_manager->install_fixtures($arg);
}; if($@) {
Test::More::fail($message);
$schema_manager->builder->diag($@);
} else {
Test::More::pass($message);
return @return;
}
} elsif( $arg ) {
my @sets = ref $arg ? @$arg : ($arg);
my @fixtures = $schema_manager->get_fixture_sets(@sets);
my @return;
foreach my $fixture (@fixtures) {
eval {
push @return, $schema_manager->install_fixtures($fixture);
}; if($@) {
Test::More::fail($message);
$schema_manager->builder->diag($@);
} else {
Test::More::pass($message);
return @return;
}
}
} else {
Test::More::fail("Can't figure out what fixtures you want");
}
}
},
is_fields => sub {
my ($local_class, $name, $arg) = @_;
my @default_fields = ();
if(defined $arg && ref $arg eq 'HASH' && defined $arg->{fields}) {
@default_fields = ref $arg->{fields} ? @{$arg->{fields}} : ($arg->{fields});
}
return sub {
my @args = @_;
my @fields = @default_fields;
if(!ref($args[0]) || (ref($args[0]) eq 'ARRAY')) {
my $fields = shift(@args);
@fields = ref $fields ? @$fields : ($fields);
}
if(Scalar::Util::blessed($args[0]) &&
$args[0]->isa('DBIx::Class') &&
!$args[0]->isa('DBIx::Class::ResultSet')
) {
my $result = shift(@args);
unless(@fields) {
my @pks = $result->result_source->primary_columns;
push @fields, grep {
my $field = $_;
$field ne ((grep { $field eq $_ } @pks)[0] || '')
} ($result->result_source->columns);
}
my $compare = shift(@args);
if(ref $compare eq 'HASH') {
} elsif(ref $compare eq 'ARRAY') {
my @localfields = @fields;
$compare = {map {
my $value = $_;
my $key = shift(@localfields);
$key => $value } @$compare};
Test::More::fail('Too many fields!') if @localfields;
} elsif(!ref $compare) {
my @localfields = @fields;
$compare = {map {
my $value = $_;
my $key = shift(@localfields);
$key => $value } ($compare)};
Test::More::fail('Too many fields!') if @localfields;
}
my $message = shift(@args) || 'Fields match';
my $compare_rs = {map {
die "$_ is not an available field"
unless $result->can($_);
$_ => $result->$_ } @fields};
eq_or_diff2($compare,$compare_rs,$message);
return $compare;
} elsif (Scalar::Util::blessed($args[0]) && $args[0]->isa('DBIx::Class::ResultSet')) {
my $resultset = shift(@args);
unless(@fields) {
my @pks = $resultset->result_source->primary_columns;
push @fields, grep {
my $field = $_;
$field ne ((grep { $field eq $_ } @pks)[0] || '')
} ($resultset->result_source->columns);
}
my @compare = @{shift(@args)};
foreach (@compare) {
if(!ref $_) {
my @localfields = @fields;
$_ = {map {
my $value = $_;
my $key = shift(@localfields);
$key => $value } ($_)};
Test::More::fail('Too many fields!') if @localfields;
} elsif(ref $_ eq 'ARRAY') {
my @localfields = @fields;
$_ = {map {
my $value = $_;
my $key = shift(@localfields);
$key => $value } (@$_)};
Test::More::fail('Too many fields!') if @localfields;
}
}
my $message = shift(@args) || 'Fields match';
my @resultset = $resultset->search({}, {
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
columns => [@fields],
})->all;
my %compare_rs;
foreach my $row(@resultset) {
no warnings 'uninitialized';
my $id = Digest::MD5::md5_hex(join('.', map {$row->{$_}} sort keys %$row));
$compare_rs{$id} = { map { $_,"$row->{$_}"} keys %$row};
}
my %compare;
foreach my $row(@compare) {
no warnings 'uninitialized';
my $id = Digest::MD5::md5_hex(join('.', map {$row->{$_}} sort keys %$row));
## Force comparison stuff in stringy form :(
$compare{$id} = { map { $_,"$row->{$_}"} keys %$row};
}
eq_or_diff2(\%compare,\%compare_rs,$message);
return \@compare;
} else {
die "I'm not sure what to do with your arguments";
}
};
},
reset_schema => sub {
return sub {
my $message = shift @_ || 'Schema reset complete';
$schema_manager->reset;
Test::More::pass($message);
}
},
cleanup_schema => sub {
return sub {
my $message = shift @_ || 'Schema cleanup complete';
$schema_manager->cleanup;
Test::More::pass($message);
}
},
map {
my $source = $_;
$source => sub {
my ($local_class, $name, $arg) = @_;
my $resultset = $schema_manager->schema->resultset($source);
if(my $search = $arg->{search}) {
my @search = ref $search eq 'ARRAY' ? @$search : ($search);
$resultset = $resultset->search(@search);
}
return sub {
my $search = shift @_;
if($search) {
my @search = ();
if(ref $search && ref $search eq 'HASH') {
@search = ($search, @_);
} else {
@search = ({$search, @_});
}
return $resultset->search(@search);
}
return $resultset->search_rs;
}
};
} $schema_manager->schema->sources,
],
groups => {
resultsets => [$schema_manager->schema->sources],
},
into_level => 1,
});
$class->$exporter(
qw/Schema ResultSet is_result is_resultset hri_dump fixtures_ok reset_schema
eq_result eq_resultset is_fields dump_settings cleanup_schema /,
@exports
);
}
sub _initialize {
my ($class, @opts) = @_;
my ($config, @exports) = $class->_normalize_opts(@opts);
my $merged_config = $class->_prepare_config($config);
if(my $resultsets = delete $merged_config->{resultsets}) {
if(ref $resultsets eq 'ARRAY') {
push @exports, @$resultsets;
} else {
die '"resultsets" options must be a Array Reference.';
}
}
my $merged_with_fixtures_config = $class->_prepare_fixtures($merged_config);
my $visitor = Data::Visitor::Callback->new(plain_value=>\&_visit_config_values);
$visitor->visit($merged_with_fixtures_config);
my $schema_manager = $class->_initialize_schema($merged_with_fixtures_config);
return (
$schema_manager,
$merged_config,
@exports,
);
}
sub _visit_config_values {
return unless $_;
&_config_substitutions($_);
}
sub _config_substitutions {
my $subs = {};
$subs->{ ENV } =
sub {
my ( $v ) = @_;
if (! defined($ENV{$v})) {
Test::More::fail("Missing environment variable: $v");
return '';
} else {
return $ENV{ $v };
}
};
$subs->{ literal } ||= sub { return $_[ 1 ]; };
my $subsre = join( '|', keys %$subs );
for ( @_ ) {
s{__($subsre)(?:\((.+?)\))?__}{ $subs->{ $1 }->( $2 ? split( /,/, $2 ) : () ) }eg;
}
}
sub _normalize_opts {
my ($class, @opts) = @_;
my ($config, @exports) = ({},());
if(ref $opts[0]) {
if(ref $opts[0] eq 'HASH') {
$config = shift(@opts);
} else {
die 'First argument to "use Test::DBIx::Class @args" not properly formed.';
}
}
while( my $opt = shift(@opts)) {
if($opt =~m/^-(.+)/) {
if($config->{$1}) {
die "$1 already is defined as $config->{$1}";
} else {
$config->{$1} = shift(@opts);
}
} else {
@exports = ($opt, @opts);
last;
}
}
if(my $resultsets = delete $config->{resultsets}) {
if(ref $resultsets eq 'ARRAY') {
push @exports, @$resultsets;
} else {
die '"resultsets" options must be a Array Reference.';
}
}
@exports = map { ref $_ && ref $_ eq 'ARRAY' ? @$_:$_ } @exports;
return ($config, @exports);
}
sub _prepare_fixtures {
my ($class, $config) = @_;
my @dirs;
if(my $fixture_path = delete $config->{fixture_path}) {
@dirs = $class->_normalize_config_path(
$class->_default_fixture_paths, $fixture_path,
);
} else {
@dirs = $class->_normalize_config_path($class->_default_fixture_paths);
}
my @extensions = $class->_allowed_extensions;
my @files = (
grep { $class->_is_allowed_extension($_) }
map {Path::Class::dir($_)->children}
grep { -e $_ }
@dirs
);
my $fixture_definitions = Config::Any->load_files({
files => \@files,
use_ext => 1,
});
my %merged_fixtures;
foreach my $fixture_definition(@$fixture_definitions) {
my ($path, $fixture) = %$fixture_definition;
## hack to normalize arrayref fixtures. needs work!!!
$fixture = ref $fixture eq 'HASH' ? [$fixture] : $fixture;
my $file = Path::Class::file($path)->basename;
$file =~s/\..{1,4}$//;
if($merged_fixtures{$file}) {
my $old_fixture = $merged_fixtures{$file};
my $merged_fixture = Hash::Merge::merge($fixture, $old_fixture);
$merged_fixtures{$file} = $merged_fixture;
} else {
$merged_fixtures{$file} = $fixture;
}
}
if(my $old_fixture_sets = delete $config->{fixture_sets}) {
## hack to normalize arrayref fixtures. needs work!!!
my %normalized_old_fixture_sets = map {
ref($old_fixture_sets->{$_}) eq 'HASH' ? ($_, [$old_fixture_sets->{$_}]): ($_, $old_fixture_sets->{$_});
} keys %$old_fixture_sets;
my $new_fixture_sets = Hash::Merge::merge(\%normalized_old_fixture_sets, \%merged_fixtures );
$config->{fixture_sets} = $new_fixture_sets;
} else {
$config->{fixture_sets} = \%merged_fixtures;
}
return $config;
}
sub _is_allowed_extension {
my ($class, $file) = @_;
my @extensions = $class->_allowed_extensions;
foreach my $extension(@extensions) {
if($file =~ m/\.$extension$/) {
return $file;
}
}
return;
}
sub _prepare_config {
my ($class, $config) = @_;
if(my $extra_config = delete $config->{config_path}) {
my @config_data = $class->_load_via_config_any($extra_config);
foreach my $config_datum(reverse @config_data) {
$config = Hash::Merge::merge($config, $config_datum);
}
} else {
my @config_data = $class->_load_via_config_any();
foreach my $config_datum(reverse @config_data) {
$config = Hash::Merge::merge($config, $config_datum);
}
}
if(my $post_config = delete $config->{config_path}) {
my @post_config_paths = $class->_normalize_external_paths($post_config);
my @extensions = $class->_allowed_extensions;
my @post_config_files = grep { -e $_} map {
my $path = $_;
map {
$ENV{TEST_DBIC_CONFIG_SUFFIX} ?
("$path.$_", "$path$ENV{TEST_DBIC_CONFIG_SUFFIX}.$_") :
("$path.$_");
} @extensions;
} map {
my @local_path = ref $_ ? @$_ : ($_);
Path::Class::file(@local_path);
} @post_config_paths;
my $post_config = $class->_config_any_load_files(@post_config_files);
foreach my $config_datum(reverse map { values %$_ } @$post_config) {
$config = Hash::Merge::merge($config, $config_datum);
}
}
return $config;
}
sub _load_via_config_any {
my ($class, $extra_paths) = @_;
my @files = $class->_valid_config_files($class->_default_paths, $extra_paths);
my $config = $class->_config_any_load_files(@files);
my @config_data = map { values %$_ } @$config;
return @config_data;
}
sub _config_any_load_files {
my ($class, @files) = @_;
return Config::Any->load_files({
files => \@files,
use_ext => 1,
});
}
sub _valid_config_files {
my ($class, $default_paths, $extra_paths) = @_;
my @extensions = $class->_allowed_extensions;
my @paths = $class->_normalize_config_path($default_paths, $extra_paths);
my @config_files = grep { -e $_} map {
my $path = $_;
map {
$ENV{TEST_DBIC_CONFIG_SUFFIX} ?
("$path.$_", "$path$ENV{TEST_DBIC_CONFIG_SUFFIX}.$_") :
("$path.$_");
} @extensions;
} @paths;
return @config_files;
}
sub _allowed_extensions {
return @{ Config::Any->extensions };
}
sub _normalize_external_paths {
my ($class, $extra_paths) = @_;
my @extra_paths;
if(!ref $extra_paths) {
@extra_paths = ([$extra_paths]); ## "t/etc" => (["t/etc"])
} elsif(ref $extra_paths eq 'ARRAY') {
if(!ref $extra_paths->[0]) {
@extra_paths = ($extra_paths); ## [qw( t etc )]
} elsif( ref $extra_paths->[0] eq 'ARRAY') {
@extra_paths = @$extra_paths;
}
}
return @extra_paths;
}
sub _normalize_config_path {
my ($class, $default_paths, $extra_paths) = @_;
if(defined $extra_paths) {
my @extra_paths = map { "$_" eq "+" ? @$default_paths : $_ } map {
my @local_path = ref $_ ? @$_ : ($_);
Path::Class::file(@local_path);
} $class->_normalize_external_paths($extra_paths);
return @extra_paths;
} else {
return @$default_paths;
}
}
sub _script_path {
return ($0 =~m/^(.+)\.t$/)[0];
}
sub _default_fixture_paths {
my ($class) = @_;
my $script_path = Path::Class::file($class->_script_path);
my $script_dir = $script_path->dir;
my @dir_parts = $script_dir->dir_list(1);
return [
Path::Class::file(qw/t etc fixtures/),
Path::Class::file(qw/t etc fixtures/, @dir_parts, $script_path->basename),
];
}
sub _default_paths {
my ($class) = @_;
my $script_path = Path::Class::file($class->_script_path);
my $script_dir = $script_path->dir;
my @dir_parts = $script_dir->dir_list(1);
if(
$script_path->basename eq 'schema' &&
(scalar(@dir_parts) == 0 )
) {
return [
Path::Class::file(qw/t etc schema/),
];
} else {
return [
Path::Class::file(qw/t etc schema/),
Path::Class::file(qw/t etc /, @dir_parts, $script_path->basename),
];
}
}
sub _initialize_schema {
my $class = shift @_;
my $config = shift @_;
my $builder = __PACKAGE__->builder;
my $fail_on_schema_break = delete $config->{fail_on_schema_break};
my $schema_manager;
eval {
$schema_manager = Test::DBIx::Class::SchemaManager->initialize_schema({
%$config,
builder => $builder,
});
}; if ($@ or !$schema_manager) {
Test::More::diag("Can't initialize a schema with the given configuration");
Test::More::diag("Returned Error: ".$@) if $@;
Test::More::diag(
Test::More::explain("configuration: " => $config)
);
# FIXME: make this optional.
if($fail_on_schema_break)
{
Test::More::fail("Failed remaining tests since we don't have a schema");
Test::More::done_testing();
$builder->finalize();
exit(0);
}
else
{
$builder->skip_all("Skipping remaining tests since we don't have a schema");
}
}
return $schema_manager
}
1;
__END__
=head1 NAME
Test::DBIx::Class - Easier test cases for your DBIx::Class applications
=head1 SYNOPSIS
The following is example usage for this module. Assume you create a standard
Perl testing script, such as "MyApp/t/schema/01-basic.t" which is run from the
shell like "prove -l t/schema/01-basic.t" or during "make test". That test
script could contain:
use Test::More;
use strict;
use warnings;
use Test::DBIx::Class {
schema_class => 'MyApp::Schema',
connect_info => ['dbi:SQLite:dbname=:memory:','',''],
connect_opts => { name_sep => '.', quote_char => '`', },
fixture_class => '::Populate',
}, 'Person', 'Person::Employee' => {-as => 'Employee'}, 'Job', 'Phone';
## Your testing code below ##
## Your testing code above ##
done_testing;
Yes, it looks like a lot of boilerplate, but sensible defaults are in place
(the above code example shows most of the existing defaults) and configuration
data L<can be loaded from a central file|/"CONFIGURATION BY FILE">. So,
assuming you put all of your test configuration in the standard place, your
'real life' example is going to look closer to:
use Test::More;
use strict;
use warnings;
use Test::DBIx::Class qw(:resultsets);
## Your testing code below ##
## Your testing code above ##
done_testing;
Then, assuming the existence of a L<DBIx::Class::Schema> subclass called,
"MyApp::Schema" and some L<DBIx::Class::ResultSource>s named like "Person",
"Person::Employee", "Job" and "Phone", will automatically deploy a testing
schema in the given database / storage (or auto deploy to an in-memory based
L<DBD::SQLite> database), install fixtures and let you run some test cases,
such as:
## Your testing code below ##
fixtures_ok 'basic'
=> 'installed the basic fixtures from configuration files';
fixtures_ok [
Job => [
[qw/name description/],
[Programmer => 'She who writes the code'],
['Movie Star' => 'Knows nothing about the code'],
],
], 'Installed some custom fixtures via the Populate fixture class',
ok my $john = Person->find({email=>'jjnapiork@cpan.org'})
=> 'John has entered the building!';
is_fields $john, {
name => 'John Napiorkowski',
email => 'jjnapiork@cpan.org',
age => 40,
}, 'John has the expected fields';
is_fields ['job_title'], $john->jobs, [
{job_title => 'programmer'},
{job_title => 'administrator'},
],
is_fields 'job_title', $john->jobs,
[qw/programmer administrator/],
'Same test as above, just different compare format;
is_fields [qw/job_title salary/], $john->jobs, [
['programmer', 100000],
['administrator, 120000],
], 'Got expected fields from $john->jobs';
is_fields [qw/name age/], $john, ['John Napiorkowski', 40],
=> 'John has expected name and age';
is_fields_multi 'name', [
$john, ['John Napiorkowski'],
$vanessa, ['Vanessa Li'],
$vincent, ['Vincent Zhou'],
] => 'All names as expected';
is_fields 'fullname',
ResultSet('Country')->find('USA'),
'United States of America',
'Found the USA';
is_deeply [sort Schema->sources], [qw/
Person Person::Employee Job Country Phone
/], 'Found all expected sources in the schema';
fixtures_ok my $first_album = sub {
my $schema = shift @_;
my $cd_rs = $schema->resultset('CD');
return $cd_rs->create({
name => 'My First Album',
track_rs => [
{position=>1, title=>'the first song'},
{position=>2, title=>'yet another song'},
],
cd_artist_rs=> [
{person_artist=>{person => $vanessa}},
{person_artist=>{person => $john}},
],
});
}, 'You can even use a code reference for custom fixtures';
## Your testing code above ##
Please see the test cases for more examples.
=head1 DESCRIPTION
The goal of this distribution is to make it easier to write test cases for your
L<DBIx::Class> based applications. It does this in three ways. First, it trys
to make it easy to deploy your Schema. This can be to your dedicated testing
database, or a simple SQLite database. This allows you to run tests without
interfering with your development work and having to stop and set up a testing
database instance.
Second, we allow you to load test fixtures via several different tools. Last
we create some helper functions in your test script so that you can reduce
repeated or boilerplate code.
Overall, we attempt to reduce the amount of code you have to write before you
can begin writing tests.
=head1 IMPORTED METHODS
The following methods are automatically imported when you use this module.
=head2 Schema
You probably won't need this directly in your tests unless you have some
application logic methods in it.
=head2 ResultSet ($source, ?{%search}, ?{%conditions})
Although you can import your sources as local keywords, sometimes you might
need to get a particular resultset when you don't wish to import it globally.
Use like
ok ResultSet('Job'), "Yeah, some jobs in the database";
ok ResultSet( Job => {hourly_pay=>{'>'=>100}}), "Good paying jobs available!";
Since this returns a normal L<DBIx::Class::ResultSet>, you can just call the
normal methods against it.
ok ResultSet('Job')->search({hourly_pay=>{'>'=>100}}), "Good paying jobs available!";
This is the same as the test above.
ResultSet can also be called with a C<< $source, [\%search,
\%condition] >> signature.
=head2 fixtures_ok
This is used to install and verify installation of fixtures, either inlined,
from a fixture set in a file, or through a custom sub reference. Accept three
argument styles:
=over 4
=item coderef
Given a code reference, execute it against the currently defined schema. This
is used when you need a lot of control over installing your fixtures. Example:
fixtures_ok sub {
my $schema = shift @_;
my $cd_rs = $schema->resultset('CD');
return $cd_rs->create({
name => 'My First Album',
track_rs => [
{position=>1, title=>'the first song'},
{position=>2, title=>'yet another song'},
],
cd_artist_rs=> [
{person_artist=>{person => $vanessa}},
{person_artist=>{person => $john}},
],
});
}, 'Installed fixtures';
The above gets executed at runtime and if there is an error it is trapped,
reported and we move on to the next test.
=item arrayref
Given an array reference, attempt to process it via the default fixtures loader
or through the specified loader.
fixtures_ok [
Person => [
['name', 'age', 'email'],
['John', 40, 'john@nowehere.com'],
['Vincent', 15, 'vincent@home.com'],
['Vanessa', 35, 'vanessa@school.com'],
],
], 'Installed fixtures';
This is a good option to use while you are building up your fixture sets or
when your sets are going to be small and not reused across lots of tests. This
will get you rolling without messing around with configuration files.
=item fixture set name
Given a fixture name, or array reference of names, install the fixtures.
fixtures_ok 'core';
fixtures_ok [qw/core extra/];
Fixtures are installed in the order specified.
=back
All different types can be mixed and matched in a given test file.
=head2 is_result ($result, ?$result)
Quick test to make sure $result does inherit from L<DBIx::Class> or that it
inherits from a subclass of L<DBIx::Class>.
=head2 is_resultset ($resultset, ?$resultset)
Quick test to make sure $resultset does inherit from L<DBIx::Class::ResultSet>
or from a subclass of L<DBIx::Class::ResultSet>.
=head2 eq_resultset ($resultset, $resultset, ?$message)
Given two ResultSets, determine if the are equal based on class type and data.
This is a true set equality that ignores sorting order of items inside the
set.
=head2 eq_result ($resultset, $resultset, ?$message)
Given two row objects, make sure they are the same.
=head2 hri_dump ($resultset)
Not a test, just returns a version of the ResultSet that has its inflator set
to L<DBIx::Class::ResultClass::HashRefInflator>, which returns a set of hashes
and makes it easier to stop issues. This return value is suitable for dumping
via L<Data::Dump>, for example.
=head2 reset_schema
Wipes and reloads the schema.
=head2 cleanup_schema
Wipes schema and disconnects.
=head2 dump_settings
Returns the configuration and related settings used to initialize this testing
module. This is mostly to help you debug trouble with configuration and to help
the authors find and fix bugs. At some point this won't be exported by default
so don't use it for your real tests, just to help you understand what is going
on. You've been warned!
=head2 is_fields
A 'Swiss Army Knife' method to check your results or resultsets. Tests the
values of a Result or ResultSet against expected via a pattern. A pattern
is automatically created by instrospecting the fields of your ResultSet or
Result.
Example usage for testing a result follows.
ok my $john = Person->find('john');
is_fields 'name', $john, ['John Napiorkowski'],
'Found name of $john';
is_fields [qw/name age/], $john, ['John Napiorkowski', 40],
'Found $johns name and age';
is_fields $john, {
name => 'John Napiorkowski',
age => 40,
email => 'john@home.com'}; # Assuming $john has only the three columns listed
In the case where we need to infer the match pattern, we get the columns of the
given result but remove the primary key. Please note the following would also
work:
is_fields [qw/name age/] $john, {
name => 'John Napiorkowski',
age => 40}, 'Still got the name and age correct';
You should choose the method that makes most sense in your tests.
Example usage for testing a resultset follows.
is_fields 'name', Person, [
'John',
'Vanessa',
'Vincent',
];
is_fields ['name'], Person, [
'John',
'Vanessa',
'Vincent',
];
is_fields ['name','age'], Person, [
['John',40],
['Vincent',15],
['Vanessa',35],
];
is_fields ['name','age'], Person, [
{name=>'John', age=>40},
{name=>'Vanessa',age=>35},
{name=>'Vincent', age=>15},
];
I find the array version is most consise. Please note that the match is not
ordered. If you need to test that a given Resultset is in a particular order,
you will currently need to write a custom test. If you have a big need for
this I'd be willing to write a test for it, or gladly accept a patch to add it.
You should examine the test cases for more examples.
=head2 is_fields_multi
TBD: Not yet written.
=head1 SETUP AND INITIALIZATION
The generic usage for this would look like one of the following:
use Test::DBIx::Class \%options, @sources
use Test::DBIx::Class %options, @sources
Where %options are key value pairs and @sources an array as specified below.
=head2 Initialization Options
The only difference between the hash and hash reference version of %options
is that the hash version requires its keys to be prepended with "-". If
you are inlining a lot of configuration the hash reference version may look
neater, while if you are only setting one or two options the hash version
might be more readable. For example, the following are the same:
use Test::DBIx::Class -config_path=>[qw(t etc config)], 'Person', 'Job';
use Test::DBIx::Class {config_path=>[qw(t etc config)]}, 'Person', 'Job';
The following options are currently standard and always available. Depending
on your storage engine (such as SQLite or MySQL) you will have other options.
=over 4
=item config_path
These are the relative paths searched for configuration file information. See
L</Initialization Sources> for more.
In the case were we have both inlined and file based configurations, the
inlined is merged last (that is, has highest authority to override configuration
files).
When the final merging of all configurations (both anything inlined at 'use'
time, and anything found in any of the specified config_paths, we do a single
'post' config_path check. This allows you to add in a configuration file from
inside a configuration file. For safety and sanity you can only do this once.
This feature makes it easier to globalize any additional configuration files.
For example, I often store user specific settings in "~/etc/conf.*". This
feature allows me to add that into my standard "t/etc/schema.*" so it's
available to all my test cases.
=item schema_class
Required. This must be your subclass of L<DBIx::Class::Schema> that defines
your database schema.
=item connect_info
Required. This will accept anything you can send to L<DBIx::Class/connect>.
Defaults to: ['dbi:SQLite:dbname=:memory:','',''] if left blank (but see
'traits' below for more)
=item connect_opts
Use this to customise connect_info if you have left that blank in order to
have the dsn auto-generated, but require extra attributes such as name_sep
and quote_char.
=item deploy_opts
Use this to customise any arguments that are to be passed to
L<DBIx::Class::Schema/deploy>, such as add_drop_table or quote_identifiers.
=item default_resultset_attributes
Allows you to specify default_resultset_attributes to be set on the schema.
These will be used when creating all new resultsets.
This is typically done to enable caching or turn on the software_limit flag.
=item fixture_path
These are a list of relative paths search for fixtures. Each item should be
a directory that contains files loadable by L<Config::Any> and suitable to
be installed via one of the fixture classes.
=item fixture_class
Command class that installs data into the database. Must provide a method
called 'install_fixtures' that accepts a perl data structure and installs
it into the database. Must capture and report errors. Default value is
"::Populate", which loads L<Test::DBIx::Class::FixtureCommand::Populate>, which
is a command class based on L<DBIx::Class::Schema/populate>.
=item resultsets
Lets you add in some result source definitions to be imported at test script
runtime. See L</Initialization Sources> for more.
=item force_drop_table
When deploying the database this option allows you add a 'drop table' statement
before the create ddl. Since this will return an error if you attempt to drop
a table that doesn't exist, this is off by default for SQLite storage engines.
You may need to enble it you you are using the following 'keep_db' option.
=item keep_db
By default your testing database is 'cleaned up' after you are finished. This
drops all the created tables (but currently doesn't delete any related files
or database users, if any). If you want to keep your testing database after
all the tests are run, you can set this to true. If so, you may also need to
set the previously mentioned option 'force_drop_table' to true as well, or we
will attempt to create tables and populate them when they are already populated
and created.
=item deploy_db
By default a fresh version of the schema is deployed when 'Test::DBIx::Class'
is invoked. If you want to skip the schema deployment and instead connect
to an already existing and populated database, set this option to false.
=item traits
Traits are L<Moose::Role>s that are applied to the class managing the connection
to your database. If you leave this option blank and you don't specify anything
for 'connect_info' (above), we automatically load the SQLite trait (which can
be reviewed at L<Test::DBIx::Class::SchemaManager::Trait::SQLite>). This trait
installs the ability to automatically discover and deploy to an in memory or a
filesystem SQLite database. If you are just getting started with testing, this
is probably your easiest option.
Currently there are only three traits, the SQLite trait just described (and since
it get's automatically loaded you never need to load it yourself). The
L<Test::DBIx::Class::SchemaManager::Trait::Testmysqld> trait, which is built on
top of L<Test::mysqld> and allows you the ability to deploy to and run tests
against a temporary instance of MySQL. For this trait MySQL and L<DBD::mysql>
needs to be installed, but MySQL does not need to be running, nor do you need
to create a test database or user. The third one is the
L<Test::DBIx::Class::SchemaManager::Trait::Testpostgresql> trait, which is
built on top of L<Test::Postgresql58> and allows you to deploy to and run tests
against a temporary instance of Postgresql. For this trait Postgresql
and L<DBD::Pg> needs to be installed, but Postgresql does not need to be
running, nor do you need to create a test database or user.
See L</TRAITS> for more.
=item fail_on_schema_break
Makes the test run fail when the schema can not be created. Normally the
test run is skipped when the schema fails to create. A failure can be more
convenient when you want to spot compilation failures.
=back
Please note that although all initialization options can be set inlined or in
a configuration file, some options can also be set via %ENV variables. %ENV
settings will only apply IF there are no existing values for the option in any
configuration file. As of this time we don't merge %ENV settings, they only
provider overrides to the default settings. Example use (assumes you are
using the default SQLite database)
DBNAME=test.db KEEP_DB=1 prove -lv t/schema/check-person.t
After running the test there will be a new file called 'test.db' in the home
directory of your distribution. You can use:
sqlite3 test.db
to open and view the tables and their data as loaded by any fixtures or create
statements. See L<Test::DBIx::Class::SchemaManager::Trait::SQLite> for more.
Note that you can specify both 'dbpath' and 'keep_db' in your configuration
files if you prefer. I tried to expose a subset of configuration to %ENV that
I thought the most useful. Patches and suggestions welcomed.
=head2 Initialization Sources
The @sources are a list of result sources that you want helper methods injected
into your test script namespace. This is the 'Source' part of:
$schema->resultset('Source');
Injecting methods are optional since you can also use the 'ResultSet' keyword
Imported Source keywords use L<Sub::Exporter> so you have quite a few options
for controling how the keywords are imported. For example:
use Test::DBIx::Class
'Person',
'Person::Employee' => {-as => 'Employee'},
'Person' => {search => {age=>{'>'=>55}}, -as => 'OlderPerson'};
This would import three local keywork methods, "Person", "Employee" and
"OlderPerson". For "OlderPerson", the search parameter would automatically be
resolved via $resultset->search and the correct resultset returned. You may
wish to preconfigure all your test result set cases in one go at the top of
your test script as a way to promote reusability.
In addition to the 'search' parameter, there is also an 'exec' parameter
which let's you process your resultset programatically. For example:
'Person' => {exec => sub { shift->older_than(55) }, -as => 'OlderPerson'};
This code reference gets passed the resultset object. So you can use any
method on $resultset. For example:
'Person' => {exec => sub { shift->find('john') }, -as => 'John'};
is_result John;
is John->name, 'John Napiorkowski', "Got Correct Name";
Although since fixtures will not yet be installed, the above is probably not
going to be a normally working example :)
Additionally, since you can also initialize sources via the 'resultsets'
configuration option, which can be placed into your global configuration files
this means you can predefine and result resultsets across all your tests. Here
is an example 't/etc/schema.pl' file where I initialize pretty much everything
in one file:
{
'schema_class' => 'Test::DBIx::Class::Example::Schema',
'resultsets' => [
'Person',
'Job',
'Person' => { '-as' => 'NotTeenager', search => {age=>{'>'=>18}}},
],
'fixture_sets' => {
'basic' => [
'Person' => [
[
'name',
'age',
'email'
],
[
'John',
'40',
'john@nowehere.com'
],
[
'Vincent',
'15',
'vincent@home.com'
],
[
'Vanessa',
'35',
'vanessa@school.com'
]
]
]
},
};
In this case you can simple do "use Test::DBIx::Class" and everything will
happen automatically.
In the example 't/etc/schema.pl' file, instead of (or as well as) fixture_sets
you could instead define fixture_path to allow resultset data outside of the
main 't/etc/schema.pl' file.
'fixture_path' => [qw{t etc fixtures}],
Create the file './t/etc/fixtures/basic.pl' and insert
[
'Person' => [
[
'name',
'age',
'email'
],
[
'John',
'40',
'john@nowehere.com'
],
[
'Vincent',
'15',
'vincent@home.com'
],
[
'Vanessa',
'35',
'vanessa@school.com'
]
]
]
Additional rulesets should be included within the outermost [ ] like
this.
[
'Person' => [
...
],
'Job' => [
...
]
]
The 'basic' fixture would be used with fixtures_ok in exactly the same way
as when it was embedded within schema.pl using fixture_sets.
=head1 CONFIGURATION BY FILE
By default, we try to load configuration files from the following locations:
./t/etc/schema.*
./t/etc/[test file path].*
Where "." is the root of the distribution and "*" is any of the configuration
file types supported by L<Config::Any> configuration loader. This allows you
to store configuration in the format of your choice.
"[test file path]" is the relative path part under the "t" directory of the
calling test script. For example, if your test script is "t/mytest.t" we add
the path "./t/etc/mytest.*" to the path.
Additionally, we do a merge using L<Hash::Merge> of all the matching found
configurations. This allows you to do 'cascading' configuration from the most
global to the most local settings.
You can override this search path with the "-config_path" key in options. For
example, the following searches for "t/etc/myconfig.*" (or whatever is the
correct directory separator for your operating system):
use Test::DBIx::Class -config_path => [qw/t etc myconfig/];
Relative paths are rooted to the distribution home directory (ie, the one that
contains your 'lib' and 't' directories). Full paths are searched without
modification.
You can specify multiple paths. The following would search for both "schema.*"
and "share/schema".
use Test::DBIx::Class -config_path => [[qw/share schema/], [qw/schema/]];
Lastly, you can use the special symbol "+" to indicate that your custom path
adds to or prepends to the default search path. Since as indicated we merge
all the configurations found, this means it's easy to create user level
configuration settings mixed with global settings, as in:
use Test::DBIx::Class
-config_path => [
[qw(/ etc myapp test-schema)],
'+',
[qw(~ etc test-schema)],
];
Which would search and combine "/etc/myapp/test-schema.*", "./t/etc/schema.*",
"./etc/[test script name].*" and "~/etc/test-schema.*". This would let you set
up server level global settings, distribution level settings and finally user
level settings.
Please note that in all the examples given, paths are written as an array
reference of path parts, rather than as a string with delimiters (i.e. we do
[qw(t etc)] rather than "t/etc"). This is not required but recommended. All
arguments, either string or array references, are passed to L<Path::Class> so
that we can maintain better compatibility with non unix filesystems. If you
are writing for CPAN, please consider our non Unix filesystem friends :)
Lastly, there is an %ENV variable named 'TEST_DBIC_CONFIG_SUFFIX' which, if it
exists, can be used to further customize your configuration path. If we find
that $ENV{TEST_DBIC_CONFIG_SUFFIX} is set, we attempt to find configuration files
with the suffix appended to each of the items in the config_path option. So, if
you have:
use Test::DBIx::Class
-config_path => [
[qw(/ etc myapp test-schema)],
'+',
[qw(~ etc test-schema)],
];
and $ENV{TEST_DBIC_CONFIG_SUFFIX} = '-mysql' we will check the following paths
for valid and loading configuration files (assuming unix filesystem conventions)
/etc/myapp/test-schema.*
/etc/myapp/test-schema-mysql.*
./t/etc/schema.*
./t/etc/schema-mysql.*
./etc/[test script name].*
./etc/[test script name]-mysql.*
~/etc/test-schema.*
~/etc/test-schema-mysql.*
Each path is tested in turn and all found configurations are merged from top to
bottom. This feature is intended to make it easier to switch between sets of
configuration files when developing. For example, you can create a test suite
intended for a MySQL database, but allow a failback to the default Sqlite should
certain enviroment variables not exist.
=head1 CONFIGURATION SUBSTITUTIONS
Similarly to L<Catalyst::Plugin::ConfigLoader>, there are some macro style
keyword inflators available for use within your configuration files. This
allows you to set the value of a configuration setting from an external source,
such as from %ENV. There are currently two macro substitutions:
=over 4
=item ENV
Given a value in %ENV, substitute the keyword for the value of the named
substitution. For example, if you had:
email = 'vanessa__ENV(TEST_DBIC_LAST_NAME)__@school.com'
in your configuration filem your could:
TEST_DBIC_LAST_NAME=_lee prove -lv t/schema-your-test.t
and then:
is $vanessa->email, 'vanessa_lee@school.com', 'Got expected email';
You might find this useful for configuring localized username and passwords
although personally I'd rather set that via configuration in the user home
directory.
=back
=head1 TRAITS
As described, a trait is a L<Moose::Role> that is applied to the class
managing your database and test instance. Traits are installed by the
'traits' configuration option, which expects an ArrayRef as its input
(however will also normalize a scalar to an ArrayRef).
Available traits are as follows.
=head2 SQLite
This is the default trait which will be loaded if no other traits are installed
and there is not 'connect_info' in the configuration. In this case we assume
you want us to go and create a tempory SQLite database for testing. Please see
L<Test::DBIx::Class::SchemaManager::Trait::SQLite> for more.
=head2 Testmysqld
If MySQL is installed on the testing machine, and L<DBD::mysql>, we try to auto
create an instance of MySQL and deploy our tests to that. Similarly to the way
the SQLite trait works, we attempt to create the database without requiring any
other using effort or setup.
See L<Test::DBIx::Class::SchemaManager::Trait::Testmysqld> for more.
=head2 Testpostgresql
If Postgresql is installed on the testing machine, along with L<DBD::Pg>, we try
to auto create an instance of Postgresql in a testing area and deploy our tests
and fixtures to it.
See L<Test::DBIx::Class::SchemaManager::Trait::Testpostgresql> for more.
=head1 SEE ALSO
The following modules or resources may be of interest.
L<DBIx::Class>, L<DBIx::Class::Schema::PopulateMore>, L<DBIx::Class::Fixtures>
=head1 AUTHOR
John Napiorkowski C<< <jjnapiork@cpan.org> >>
=head1 CONTRIBUTORS
Tristan Pratt
Tomas Doran C<< <bobtfish@bobtfish.net> >>
Kyle Hasselbacher C<< kyleha@gmail.com >>
cvince
colinnewell
rbuels
wlk
yanick
hippich
lecstor
bphillips
abraxxa
oalders
felliott
Vadim Pushtaev C<< <pushtaev@cpan.org> >>
simonamor
=head1 COPYRIGHT & LICENSE
Copyright 2012, John Napiorkowski C<< <jjnapiork@cpan.org> >>
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|