正在为 Dancer2 配置 Test::DBIx::Class::Schema 到应用程序
Falling to configure Test::DBIx::Class::Schema for a Dancer2 to app
我正在尝试 运行 使用 Test::DBIx::Class::Schema.
对我的 Dancer2
应用架构进行健全性测试
我创建了一个 test.t
并放置在我的主应用程序目录中(不在 /t
文件夹中)。该文件如下所示:
#!/usr/bin/perl
use Test::More 'no_plan';
use Test::DBIx::Class::Schema;
use Dancer2::Test app => ['PearlBee'];
use lib 'lib';
use lib::PearlBee::Model::Schema;
use strict;
use warnings;
# the order is important
BEGIN {
use_ok 'Test::DBIx::Class::Schema';
#use_ok 'lib::PearlBee::Model::Schema';
use_ok 'Dancer2::Test', app => 'PearlBee';
use_ok 'lib::PearlBee::Model::Schema';# apps => ['PearlBee'];
#
#use_ok 'DBICx::TestDatabase';
}
#my $schema = DBICx::TestDatabase->new('lib::PearlBee::Model::Schema');
my $schematest = Test::DBIx::Class::Schema->new(
{
# required
dsn => 'dbi:mysql:PearlBee;host=localhost;', # or use schema option
namespace => 'lib::PearlBee::Model::Schema',
moniker => 'user',
# optional
username => 'root',
password => '1',
glue => 'Result',
#test_missing => 1,
}
);
$schematest->methods(
{
columns => [
qw[
id
salt
]
],
resultsets => [
qw[ User
]
],
}
);
$schematest->run_tests();
我崩溃了,输出如下:
Can't locate object method "connect" via package "lib::PearlBee::Model::Schema"
请帮我理解一下。
这些行看起来很有趣:
use lib 'lib';
use lib::PearlBee::Model::Schema;
第一个好像还行。我明白您为什么要将 'lib' 添加到 @INC
。但是这样做之后,我希望第二行是:
use PearlBee::Model::Schema;
您似乎不太可能需要在模块名称前面加上 lib::
。但也许您的目录结构比我假设的更复杂。 PearlBee 模式模块在哪里?
更新: 另外请注意,Dancer2::Test documentation 的最新版本是这样说的:
DEPRECATED. Please use Plack::Test instead as shown in the SYNOPSIS!
This module will warn for a while until we actually remove it. This is
to provide enough time to fully remove it from your system.
我建议您遵循该建议。
我正在尝试 运行 使用 Test::DBIx::Class::Schema.
对我的 Dancer2
应用架构进行健全性测试
我创建了一个 test.t
并放置在我的主应用程序目录中(不在 /t
文件夹中)。该文件如下所示:
#!/usr/bin/perl
use Test::More 'no_plan';
use Test::DBIx::Class::Schema;
use Dancer2::Test app => ['PearlBee'];
use lib 'lib';
use lib::PearlBee::Model::Schema;
use strict;
use warnings;
# the order is important
BEGIN {
use_ok 'Test::DBIx::Class::Schema';
#use_ok 'lib::PearlBee::Model::Schema';
use_ok 'Dancer2::Test', app => 'PearlBee';
use_ok 'lib::PearlBee::Model::Schema';# apps => ['PearlBee'];
#
#use_ok 'DBICx::TestDatabase';
}
#my $schema = DBICx::TestDatabase->new('lib::PearlBee::Model::Schema');
my $schematest = Test::DBIx::Class::Schema->new(
{
# required
dsn => 'dbi:mysql:PearlBee;host=localhost;', # or use schema option
namespace => 'lib::PearlBee::Model::Schema',
moniker => 'user',
# optional
username => 'root',
password => '1',
glue => 'Result',
#test_missing => 1,
}
);
$schematest->methods(
{
columns => [
qw[
id
salt
]
],
resultsets => [
qw[ User
]
],
}
);
$schematest->run_tests();
我崩溃了,输出如下:
Can't locate object method "connect" via package "lib::PearlBee::Model::Schema"
请帮我理解一下。
这些行看起来很有趣:
use lib 'lib';
use lib::PearlBee::Model::Schema;
第一个好像还行。我明白您为什么要将 'lib' 添加到 @INC
。但是这样做之后,我希望第二行是:
use PearlBee::Model::Schema;
您似乎不太可能需要在模块名称前面加上 lib::
。但也许您的目录结构比我假设的更复杂。 PearlBee 模式模块在哪里?
更新: 另外请注意,Dancer2::Test documentation 的最新版本是这样说的:
DEPRECATED. Please use Plack::Test instead as shown in the SYNOPSIS!
This module will warn for a while until we actually remove it. This is to provide enough time to fully remove it from your system.
我建议您遵循该建议。