From: Brandon L. Black Date: Tue, 29 May 2007 19:20:56 +0000 (+0000) Subject: converted the vendor tests to use schema objects intead of schema classes X-Git-Tag: v0.08010~150^2~44 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3ff5b74063e6bb299d8a7443df0e864254ea44b9;p=dbsrgits%2FDBIx-Class.git converted the vendor tests to use schema objects intead of schema classes also moved some of the final "DROP TABLE" stuff into END blocks to drop them more reliably --- diff --git a/t/71mysql.t b/t/71mysql.t index 3bbdaa1..a326dda 100644 --- a/t/71mysql.t +++ b/t/71mysql.t @@ -15,9 +15,9 @@ plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test plan tests => 5; -DBICTest::Schema->compose_namespace('MySQLTest' => $dsn, $user, $pass); +my $schema = DBICTest::Schema->connect($dsn, $user, $pass); -my $dbh = MySQLTest->schema->storage->dbh; +my $dbh = $schema->storage->dbh; $dbh->do("DROP TABLE IF EXISTS artist;"); @@ -25,17 +25,18 @@ $dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY #'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', ''); -MySQLTest::Artist->load_components('PK::Auto'); +# This is in Core now, but it's here just to test that it doesn't break +$schema->class('Artist')->load_components('PK::Auto'); # test primary key handling -my $new = MySQLTest::Artist->create({ name => 'foo' }); +my $new = $schema->resultset('Artist')->create({ name => 'foo' }); ok($new->artistid, "Auto-PK worked"); # test LIMIT support for (1..6) { - MySQLTest::Artist->create({ name => 'Artist ' . $_ }); + $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); } -my $it = MySQLTest::Artist->search( {}, +my $it = $schema->resultset('Artist')->search( {}, { rows => 3, offset => 2, order_by => 'artistid' } @@ -80,9 +81,11 @@ SKIP: { $test_type_info->{charfield}->{data_type} = 'VARCHAR'; } - my $type_info = MySQLTest->schema->storage->columns_info_for('artist'); + my $type_info = $schema->storage->columns_info_for('artist'); is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); } # clean up our mess -$dbh->do("DROP TABLE artist"); +END { + $dbh->do("DROP TABLE artist") if $dbh; +} diff --git a/t/72pg.t b/t/72pg.t index a3239ca..f05229b 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -12,7 +12,7 @@ use DBICTest; use warnings; use base 'DBIx::Class'; - __PACKAGE__->load_components(qw/PK::Auto Core/); + __PACKAGE__->load_components(qw/Core/); __PACKAGE__->table('casecheck'); __PACKAGE__->add_columns(qw/id name NAME uc_name/); __PACKAGE__->column_info_from_storage(1); @@ -30,21 +30,22 @@ plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test' plan tests => 8; DBICTest::Schema->load_classes( 'Casecheck' ); -DBICTest::Schema->compose_namespace('PgTest' => $dsn, $user, $pass); +my $schema = DBICTest::Schema->connect($dsn, $user, $pass); -my $dbh = PgTest->schema->storage->dbh; -PgTest->schema->source("Artist")->name("testschema.artist"); +my $dbh = $schema->storage->dbh; +$schema->source("Artist")->name("testschema.artist"); $dbh->do("CREATE SCHEMA testschema;"); $dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));"); ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table'); -PgTest::Artist->load_components('PK::Auto'); +# This is in Core now, but it's here just to test that it doesn't break +$schema->class('Artist')->load_components('PK::Auto'); -my $new = PgTest::Artist->create({ name => 'foo' }); +my $new = $schema->resultset('Artist')->create({ name => 'foo' }); is($new->artistid, 1, "Auto-PK worked"); -$new = PgTest::Artist->create({ name => 'bar' }); +$new = $schema->resultset('Artist')->create({ name => 'bar' }); is($new->artistid, 2, "Auto-PK worked"); @@ -69,7 +70,7 @@ my $test_type_info = { }; -my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist'); +my $type_info = $schema->storage->columns_info_for('testschema.artist'); my $artistid_defval = delete $type_info->{artistid}->{default_value}; like($artistid_defval, qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/, @@ -77,16 +78,20 @@ like($artistid_defval, is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); -my $name_info = PgTest::Casecheck->column_info( 'name' ); +my $name_info = $schema->source('Casecheck')->column_info( 'name' ); is( $name_info->{size}, 1, "Case sensitive matching info for 'name'" ); -my $NAME_info = PgTest::Casecheck->column_info( 'NAME' ); +my $NAME_info = $schema->source('Casecheck')->column_info( 'NAME' ); is( $NAME_info->{size}, 2, "Case sensitive matching info for 'NAME'" ); -my $uc_name_info = PgTest::Casecheck->column_info( 'uc_name' ); +my $uc_name_info = $schema->source('Casecheck')->column_info( 'uc_name' ); is( $uc_name_info->{size}, 3, "Case insensitive matching info for 'uc_name'" ); -$dbh->do("DROP TABLE testschema.artist;"); -$dbh->do("DROP TABLE testschema.casecheck;"); -$dbh->do("DROP SCHEMA testschema;"); +END { + if($dbh) { + $dbh->do("DROP TABLE testschema.artist;"); + $dbh->do("DROP TABLE testschema.casecheck;"); + $dbh->do("DROP SCHEMA testschema;"); + } +} diff --git a/t/73oracle.t b/t/73oracle.t index 7ca5c41..5f4d67a 100644 --- a/t/73oracle.t +++ b/t/73oracle.t @@ -13,9 +13,9 @@ plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. plan tests => 6; -DBICTest::Schema->compose_namespace('OraTest' => $dsn, $user, $pass); +my $schema = DBICTest::Schema->connect($dsn, $user, $pass); -my $dbh = OraTest->schema->storage->dbh; +my $dbh = $schema->storage->dbh; eval { $dbh->do("DROP SEQUENCE artist_seq"); @@ -42,18 +42,20 @@ $dbh->do(qq{ END; }); -OraTest::Artist->load_components('PK::Auto'); -OraTest::CD->load_components('PK::Auto::Oracle'); -OraTest::Track->load_components('PK::Auto::Oracle'); +# This is in Core now, but it's here just to test that it doesn't break +$schema->class('Artist')->load_components('PK::Auto'); +# These are compat shims for PK::Auto... +$schema->class('CD')->load_components('PK::Auto::Oracle'); +$schema->class('Track')->load_components('PK::Auto::Oracle'); # test primary key handling -my $new = OraTest::Artist->create({ name => 'foo' }); +my $new = $schema->resultset('Artist')->create({ name => 'foo' }); is($new->artistid, 1, "Oracle Auto-PK worked"); # test join with row count ambiguity -my $cd = OraTest::CD->create({ cdid => 1, artist => 1, title => 'EP C', year => '2003' }); -my $track = OraTest::Track->create({ trackid => 1, cd => 1, position => 1, title => 'Track1' }); -my $tjoin = OraTest::Track->search({ 'me.title' => 'Track1'}, +my $cd = $schema->resultset('CD')->create({ cdid => 1, artist => 1, title => 'EP C', year => '2003' }); +my $track = $schema->resultset('Track')->create({ trackid => 1, cd => 1, position => 1, title => 'Track1' }); +my $tjoin = $schema->resultset('Track')->search({ 'me.title' => 'Track1'}, { join => 'cd', rows => 2 } ); @@ -61,8 +63,8 @@ my $tjoin = OraTest::Track->search({ 'me.title' => 'Track1'}, is($tjoin->next->title, 'Track1', "ambiguous column ok"); # check count distinct with multiple columns -my $other_track = OraTest::Track->create({ trackid => 2, cd => 1, position => 1, title => 'Track2' }); -my $tcount = OraTest::Track->search( +my $other_track = $schema->resultset('Track')->create({ trackid => 2, cd => 1, position => 1, title => 'Track2' }); +my $tcount = $schema->resultset('Track')->search( {}, { select => [{count => {distinct => ['position', 'title']}}], @@ -74,9 +76,9 @@ is($tcount->next->get_column('count'), 2, "multiple column select distinct ok"); # test LIMIT support for (1..6) { - OraTest::Artist->create({ name => 'Artist ' . $_ }); + $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); } -my $it = OraTest::Artist->search( {}, +my $it = $schema->resultset('Artist')->search( {}, { rows => 3, offset => 2, order_by => 'artistid' } @@ -88,8 +90,12 @@ $it->next; is( $it->next, undef, "next past end of resultset ok" ); # clean up our mess -$dbh->do("DROP SEQUENCE artist_seq"); -$dbh->do("DROP TABLE artist"); -$dbh->do("DROP TABLE cd"); -$dbh->do("DROP TABLE track"); +END { + if($dbh) { + $dbh->do("DROP SEQUENCE artist_seq"); + $dbh->do("DROP TABLE artist"); + $dbh->do("DROP TABLE cd"); + $dbh->do("DROP TABLE track"); + } +} diff --git a/t/745db2.t b/t/745db2.t index 82d3c2c..6ddb1cd 100644 --- a/t/745db2.t +++ b/t/745db2.t @@ -14,27 +14,26 @@ plan skip_all => 'Set $ENV{DBICTEST_DB2_DSN}, _USER and _PASS to run this test' plan tests => 6; -DBICTest::Schema->compose_namespace('DB2Test' => $dsn, $user, $pass); +my $schema = DBICTest::Schema->connect($dsn, $user, $pass); -my $dbh = DB2Test->schema->storage->dbh; +my $dbh = $schema->storage->dbh; $dbh->do("DROP TABLE artist", { RaiseError => 0, PrintError => 0 }); $dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10));"); -#'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', ''); - -DB2Test::Artist->load_components('PK::Auto'); +# This is in core, just testing that it still loads ok +$schema->class('Artist')->load_components('PK::Auto'); # test primary key handling -my $new = DB2Test::Artist->create({ name => 'foo' }); +my $new = $schema->resultset('Artist')->create({ name => 'foo' }); ok($new->artistid, "Auto-PK worked"); # test LIMIT support for (1..6) { - DB2Test::Artist->create({ name => 'Artist ' . $_ }); + $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); } -my $it = DB2Test::Artist->search( {}, +my $it = $schema->resultset('Artist')->search( {}, { rows => 3, order_by => 'artistid' } @@ -64,11 +63,10 @@ my $test_type_info = { }; -my $type_info = DB2Test->schema->storage->columns_info_for('artist'); +my $type_info = $schema->storage->columns_info_for('artist'); is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); - - # clean up our mess -$dbh->do("DROP TABLE artist"); - +END { + $dbh->do("DROP TABLE artist") if $dbh; +} diff --git a/t/746db2_400.t b/t/746db2_400.t index 745673b..9ebe7cc 100644 --- a/t/746db2_400.t +++ b/t/746db2_400.t @@ -17,25 +17,26 @@ plan skip_all => 'Set $ENV{DBICTEST_DB2_400_DSN}, _USER and _PASS to run this te plan tests => 6; -DBICTest::Schema->compose_namespace('DB2Test' => $dsn, $user, $pass); +my $schema = DBICTest::Schema->connect($dsn, $user, $pass); -my $dbh = DB2Test->schema->storage->dbh; +my $dbh = $schema->storage->dbh; $dbh->do("DROP TABLE artist", { RaiseError => 0, PrintError => 0 }); $dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10))"); -DB2Test::Artist->load_components('PK::Auto'); +# Just to test loading, already in Core +$schema->class('Artist')->load_components('PK::Auto'); # test primary key handling -my $new = DB2Test::Artist->create({ name => 'foo' }); +my $new = $schema->resultset('Artist')->create({ name => 'foo' }); ok($new->artistid, "Auto-PK worked"); # test LIMIT support for (1..6) { - DB2Test::Artist->create({ name => 'Artist ' . $_ }); + $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); } -my $it = DB2Test::Artist->search( {}, +my $it = $schema->resultset('Artist')->search( {}, { rows => 3, order_by => 'artistid' } @@ -65,11 +66,11 @@ my $test_type_info = { }; -my $type_info = DB2Test->schema->storage->columns_info_for('artist'); +my $type_info = $schema->storage->columns_info_for('artist'); is_deeply($type_info, $test_type_info, 'columns_info_for - column data types'); - - # clean up our mess -$dbh->do("DROP TABLE artist"); +END { + $dbh->do("DROP TABLE artist") if $dbh; +} diff --git a/t/74mssql.t b/t/74mssql.t index 0bb43b6..1e86e2d 100644 --- a/t/74mssql.t +++ b/t/74mssql.t @@ -18,28 +18,30 @@ my $storage_type = '::DBI::MSSQL'; $storage_type = '::DBI::Sybase::MSSQL' if $dsn =~ /^dbi:Sybase:/; # Add more for others in the future when they exist (ODBC? ADO? JDBC?) -DBICTest::Schema->storage_type($storage_type); -DBICTest::Schema->compose_namespace( 'MSSQLTest' => $dsn, $user, $pass ); +my $schema = DBICTest::Schema->clone; +$schema->storage_type($storage_type); +$schema->connection($dsn, $user, $pass); -my $dbh = MSSQLTest->schema->storage->dbh; +my $dbh = $schema->storage->dbh; $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist"); $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(255));"); -MSSQLTest::Artist->load_components('PK::Auto::MSSQL'); +# Just to test compat shim, Auto is in Core +$schema->class('Artist')->load_components('PK::Auto::MSSQL'); # Test PK -my $new = MSSQLTest::Artist->create( { name => 'foo' } ); +my $new = $schema->resultset('Artist')->create( { name => 'foo' } ); ok($new->artistid, "Auto-PK worked"); # Test LIMIT for (1..6) { - MSSQLTest::Artist->create( { name => 'Artist ' . $_ } ); + $schema->resultset('Artist')->create( { name => 'Artist ' . $_ } ); } -my $it = MSSQLTest::Artist->search( { }, +my $it = $schema->resultset('Artist')->search( { }, { rows => 3, offset => 2, order_by => 'artistid' @@ -52,3 +54,8 @@ $it->next; $it->next; is( $it->next, undef, "next past end of resultset ok" ); +# clean up our mess +END { + $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist") + if $dbh; +} diff --git a/t/93nobindvars.t b/t/93nobindvars.t index b4e1adc..f90cf7d 100644 --- a/t/93nobindvars.t +++ b/t/93nobindvars.t @@ -28,29 +28,27 @@ plan tests => 4; $INC{'DBIx/Class/Storage/DBI/MySQLNoBindVars.pm'} = 1; } -DBICTest::Schema->storage(undef); # just in case? -DBICTest::Schema->storage_type('::DBI::MySQLNoBindVars'); -DBICTest::Schema->compose_namespace('MySQLTest' => $dsn, $user, $pass); +my $schema = DBICTest::Schema->clone; +$schema->storage_type('::DBI::MySQLNoBindVars'); +$schema->connection($dsn, $user, $pass); -my $dbh = MySQLTest->schema->storage->dbh; +my $dbh = $schema->storage->dbh; $dbh->do("DROP TABLE IF EXISTS artist;"); $dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));"); -#'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', ''); - -MySQLTest::Artist->load_components('PK::Auto'); +$schema->class('Artist')->load_components('PK::Auto'); # test primary key handling -my $new = MySQLTest::Artist->create({ name => 'foo' }); +my $new = $schema->resultset('Artist')->create({ name => 'foo' }); ok($new->artistid, "Auto-PK worked"); # test LIMIT support for (1..6) { - MySQLTest::Artist->create({ name => 'Artist ' . $_ }); + $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); } -my $it = MySQLTest::Artist->search( {}, +my $it = $schema->resultset('Artist')->search( {}, { rows => 3, offset => 2, order_by => 'artistid' } @@ -62,4 +60,6 @@ $it->next; is( $it->next, undef, "next past end of resultset ok" ); # clean up our mess -$dbh->do("DROP TABLE artist"); +END { + $dbh->do("DROP TABLE artist"); +}