summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-07-27 11:03:04 -0500
committerJesse Luehrs <doy@tozt.net>2011-07-27 11:38:56 -0500
commit2d95b92582166f711e05c973f3e22950bbce6b2f (patch)
tree8b6306d7973c494f8739c40251ab83b70b4a0428 /t
parent5660beb67176142342f9392ebbb21066e7e084b6 (diff)
downloadbread-board-declare-2d95b92582166f711e05c973f3e22950bbce6b2f.tar.gz
bread-board-declare-2d95b92582166f711e05c973f3e22950bbce6b2f.zip
allow specifying parameters for services (not sure how i missed this)
Diffstat (limited to 't')
-rw-r--r--t/parameters.t71
1 files changed, 71 insertions, 0 deletions
diff --git a/t/parameters.t b/t/parameters.t
new file mode 100644
index 0000000..2c37629
--- /dev/null
+++ b/t/parameters.t
@@ -0,0 +1,71 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+
+{
+ package Schema;
+ use Moose;
+}
+
+{
+ package Thing;
+ use Moose;
+
+ has schema => (
+ is => 'ro',
+ isa => 'Schema',
+ required => 1,
+ );
+
+ has foo => (
+ is => 'ro',
+ required => 1,
+ );
+
+ has bar => (
+ is => 'ro',
+ required => 1,
+ );
+}
+
+{
+ package Model;
+ use Moose;
+ use Bread::Board::Declare;
+
+ has schema => (
+ is => 'ro',
+ isa => 'Schema',
+ );
+
+ has thing => (
+ is => 'ro',
+ isa => 'Thing',
+ dependencies => ['schema'],
+ parameters => ['foo', 'bar'],
+ );
+}
+
+my $m = Model->new;
+like(
+ exception { $m->thing },
+ qr/Mandatory parameters .* missing/,
+ "error with unsatisfied parameters"
+);
+is(
+ exception {
+ my $thing = $m->resolve(
+ service => 'thing',
+ parameters => { foo => 'a', bar => 'b' },
+ );
+ is($thing->foo, 'a');
+ is($thing->bar, 'b');
+ isa_ok($thing->schema, 'Schema');
+ },
+ undef,
+ "no error with satisfied parameters"
+);
+
+done_testing;