summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
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;