File: 01-basic-constructor.t

package info (click to toggle)
libpgobject-simple-role-perl 2.000002-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 136 kB
  • ctags: 13
  • sloc: perl: 159; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,421 bytes parent folder | download | duplicates (3)
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
#########

package test1;
use Moo;
with('PGObject::Simple::Role');

has 'id' => (is => 'ro');
has 'foo' => (is => 'ro');
has 'bar' => (is => 'ro');
has 'baz' => (is => 'ro');

package test2;
use Moo;
with('PGObject::Simple::Role');

has 'id' => (is => 'ro');

sub _get_dbh {
    return 1;
}

sub _get_prefix { 'foo' };

##########

package main;

use Test::More tests => 14;
use Test::Exception;
use DBI;

my %args = (
   id => 3, 
   foo => 'test1',
   bar => 'test2',
   baz => 33,
   biz => 112,
);

my $obj;

lives_ok {$obj = test1->new(%args)} 'created new object without crashing';
ok(eval {$obj->isa('test1')}, 'ISA test passed');
is($obj->id, 3, 'attribute id passed');
is($obj->funcprefix, '', 'Got correct function prefix(empty)');
is($obj->_registry, undef, 'Undefined registry at first');
is($obj->foo, 'test1', 'attribute foo passed');
is($obj->bar, 'test2', 'attribute bar passed');
is($obj->baz, 33, 'attribute baz passed');
ok(!defined($obj->can('biz')), 'No dbh method exists');
throws_ok {$obj->_build__dbh(1)} qr/Subclasses MUST set/, 
          'Threw exception, "Subclasses MUST set"';

lives_ok {$obj = test2->new(%args)} 'created new object without crashing';
is($obj->funcprefix, 'foo', 'Got correct function prefix');
throws_ok {$obj->_dbh} qr/Expected a database handle/, 
          'Threw exception, "Expected a database handle"';
lives_ok {$obj->set_dbh(4) } 'set-dbh goes through isa check';