@@ -, +, @@ Subtest: _gen_real formatting 1..4 not ok 1 - There can be more decimals when the column size allows it. Failed test 'There can be more decimals when the column size allows it.' at t/db_dependent/TestBuilder.t line 112. got: '10.10' expected: '10.100000' not ok 2 - decimal - Builder builds same format as DBIx returns. Failed test 'decimal - Builder builds same format as DBIx returns.' at t/db_dependent/TestBuilder.t line 118. got: '10.10' expected: '10.100000' not ok 3 - float - Builder builds same precision as DBIx returns. Failed test 'float - Builder builds same precision as DBIx returns.' at t/db_dependent/TestBuilder.t line 124. got: '10.10' expected: '10.1' not ok 4 - double - Builder builds same precision as DBIx returns. Failed test 'double - Builder builds same precision as DBIx returns.' at t/db_dependent/TestBuilder.t line 131. got: '10.10' expected: '10.1' Looks like you failed 4 tests of 4. not ok 4 - _gen_real formatting Failed test '_gen_real formatting' --- t/db_dependent/TestBuilder.t | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) --- a/t/db_dependent/TestBuilder.t +++ a/t/db_dependent/TestBuilder.t @@ -19,6 +19,7 @@ use Modern::Perl; +use Test::MockModule; use Test::More tests => 13; use Test::Warn; use File::Basename qw(dirname); @@ -84,7 +85,7 @@ subtest 'Build all sources' => sub { subtest 'Test length of some generated fields' => sub { - plan tests => 3; + plan tests => 4; # Test the length of a returned character field my $bookseller = $builder->build({ source => 'Aqbookseller' }); @@ -96,6 +97,43 @@ subtest 'Test length of some generated fields' => sub { my $item = $builder->build({ source => 'Item' }); is( $item->{replacementprice}, sprintf("%.2f", $item->{replacementprice}), "The number of decimals for floats should not be more than 2" ); + + subtest '_gen_real formatting' => sub { + plan tests => 4; + + my $module = Test::MockModule->new('t::lib::TestBuilder'); + $module->mock(_gen_real => sub { + return '10.10'; + }); + $builder = t::lib::TestBuilder->new; + + my $accountline = $builder->build({ source => 'Accountline' }); + is( $accountline->{amountoutstanding}, + sprintf("%.6f", $accountline->{amountoutstanding}), + "There can be more decimals when the column size allows it." ); + + my $rs = $schema->source('Accountline')->resultset; + my $accountline_dbix = $rs->find($accountline->{accountlines_id}); + is( $accountline->{amountoutstanding}, + $accountline_dbix->amountoutstanding, + "decimal - Builder builds same format as DBIx returns." ); + + my $aqorder = $builder->build({ source => 'Aqorder' }); + $rs = $schema->source('Aqorder')->resultset; + my $aqorder_dbix = $rs->find($aqorder->{ordernumber}); + is( $aqorder->{discount}, $aqorder_dbix->discount, + "float - Builder builds same precision as DBIx returns." ); + + my $statistic = $builder->build({ source => 'Statistic' }); + $rs = $schema->source('Statistic')->resultset; + my $statistic_dbix = $rs->search({ + datetime => $statistic->{datetime} })->next; + is( $statistic->{value}, $statistic_dbix->value, + "double - Builder builds same precision as DBIx returns." ); + + $module->unmock('_gen_real'); + $builder = t::lib::TestBuilder->new; + }; }; --