| | 939 | sub _is_object { |
| | 940 | my ($got, $expected, $name) = @_; |
| | 941 | |
| | 942 | if (!defined $got) { |
| | 943 | fail($name); |
| | 944 | diag(' got undef, not an object'); |
| | 945 | return; |
| | 946 | } |
| | 947 | |
| | 948 | if (!$got->isa(ref $expected)) { |
| | 949 | fail($name); |
| | 950 | diag(' got a ', ref($got), ' but expected a ', ref $expected); |
| | 951 | return; |
| | 952 | } |
| | 953 | |
| | 954 | if ($got == $expected) { |
| | 955 | fail($name); |
| | 956 | diag(' got the exact same instance as expected, when really expected a different but equivalent object'); |
| | 957 | return; |
| | 958 | } |
| | 959 | |
| | 960 | # Ignore object columns that have undefined values. |
| | 961 | my (%got_values, %expected_values); |
| | 962 | while (my ($field, $value) = each %{ $got->{column_values} }) { |
| | 963 | $got_values{$field} = $value if defined $value; |
| | 964 | } |
| | 965 | while (my ($field, $value) = each %{ $expected->{column_values} }) { |
| | 966 | $expected_values{$field} = $value if defined $value; |
| | 967 | } |
| | 968 | |
| | 969 | if (!eq_deeply(\%got_values, \%expected_values)) { |
| | 970 | # 'Test' again so the helpful failure diagnostics are output. |
| | 971 | is_deeply(\%got_values, \%expected_values, $name); |
| | 972 | return; |
| | 973 | } |
| | 974 | |
| | 975 | return 1; |
| | 976 | } |
| | 977 | |
| | 978 | sub is_object { |
| | 979 | my ($got, $expected, $name) = @_; |
| | 980 | pass($name) if _is_object(@_); |
| | 981 | } |
| | 982 | |
| | 983 | sub are_objects { |
| | 984 | my ($got, $expected, $name) = @_; |
| | 985 | |
| | 986 | my $count = scalar @$expected; |
| | 987 | if ($count != scalar @$got) { |
| | 988 | fail($name); |
| | 989 | diag(' got ', scalar(@$got), ' objects but expected ', $count); |
| | 990 | return; |
| | 991 | } |
| | 992 | |
| | 993 | for my $i (0..$count-1) { |
| | 994 | return if !_is_object($$got[$i], $$expected[$i], "$name (#$i)"); |
| | 995 | } |
| | 996 | pass($name); |
| | 997 | } |
| | 998 | |
| | 999 | sub reset_table_for { |
| | 1000 | my $self = shift; |
| | 1001 | for my $class (@_) { |
| | 1002 | my $driver = $class->dbi_driver; |
| | 1003 | my $dbh = $driver->rw_handle; |
| | 1004 | my $ddl_class = $driver->dbd->ddl_class; |
| | 1005 | |
| | 1006 | $dbh->do($ddl_class->drop_table_sql($class)) or die $dbh->errstr; |
| | 1007 | $dbh->do($ddl_class->create_table_sql($class)) or die $dbh->errstr; |
| | 1008 | $dbh->do($_) or die $dbh->errstr for $ddl_class->index_table_sql($class); |
| | 1009 | $ddl_class->create_sequence($class); # may do nothing |
| | 1010 | } |
| | 1011 | } |
| | 1012 | |