File: 20_shim.t

package info (click to toggle)
liborlite-perl 1.97-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 524 kB
  • sloc: perl: 3,693; sql: 97; makefile: 2
file content (99 lines) | stat: -rw-r--r-- 1,656 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

# Test that the shim => 1 option works

BEGIN {
	$|  = 1;
	$^W = 1;
}

use Test::More tests => 12;
use File::Spec::Functions ':ALL';
use t::lib::Test;





#####################################################################
# Set up for testing

# Connect
my $file = test_db();
my $dbh  = create_ok(
	file    => catfile(qw{ t 02_basics.sql }),
	connect => [ "dbi:SQLite:$file" ],
);

# Create the test package
eval <<"END_PERL"; die $@ if $@;
package Foo::Bar;

use strict;
use ORLite {
	file => '$file',
	shim => 1,
};

1;
END_PERL

CLASS: {
	package Foo::Bar::TableOne;

	use vars qw{$INCREMENT};
	BEGIN {
		$INCREMENT = 0;
	}

	# Overload new to increment the counter
	sub new {
		my $self = shift->SUPER::new(@_);
		$INCREMENT++;
		return $self;
	}

	1;
}

is( $Foo::Bar::TableOne::INCREMENT, 0, '->new calls = 0' );





#####################################################################
# Tests for the base package update methods

isa_ok(
	Foo::Bar::TableOne->create(
		col1 => 1,
		col2 => 'foo',
	),
	'Foo::Bar::TableOne',
);
is( $Foo::Bar::TableOne::INCREMENT, 1, '->new calls = 1' );

isa_ok(
	Foo::Bar::TableOne->create(
		col1 => 2,
		col2 => 'bar',
	),
	'Foo::Bar::TableOne',
);
is( Foo::Bar::TableOne->count, 2, 'Found 2 rows' );
is( $Foo::Bar::TableOne::INCREMENT, 2, '->new calls = 2' );

is(
	Foo::Bar::TableOne->count,
	2,
	'Count found 2 rows',
);
is( $Foo::Bar::TableOne::INCREMENT, 2, '->new calls = 2' );

SCOPE: {
	my $object = Foo::Bar::TableOne->load(1);
	isa_ok( $object, 'Foo::Bar::TableOne' );
	isa_ok( $object, 'Foo::Bar::TableOne::Shim' );
	is( $Foo::Bar::TableOne::INCREMENT, 2, '->new calls = 3' );
}