The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Fey::ORM::Mock - Mock Fey::ORM based classes so you can test without a DBMS

VERSION

version 0.06

SYNOPSIS

    use Fey::ORM::Mock;
    use MyApp::Schema;

    my $mock = Fey::ORM::Mock->new( schema_class => 'MyApp::Schema' );

    $mock->seed_class( 'MyApp::User' =>
                       { user_id => 42,
                         name    => 'Doug',
                       },
                       ...
                     );

    # gets seeded data first
    my $user = User->new( ... );

    $user = User->insert( ... );
    $user->update( ... );

    my @actions = $mock->recorder()->actions_for_class('User');

DESCRIPTION

This class lets you mock a set of Fey::ORM based classes. You can seed data for each class's constructor, as well as track all inserts, update, and deletes for each class.

This is all done at a higher level than is possible just using DBD::Mock. Instead of dealing with SQL and DBI's data structures, you are able to work with the named attributes of each class.

METHODS

This class provides the following methods:

Fey::ORM::Mock->new( schema_class => $class )

Given a schema class (one which uses Fey::ORM::Schema), this method adds a mocking layer to the schema class and all of its tables' associated classes. If a table does not have an associated class, it will simply be skipped.

It also replaces the schema class's existing Fey::DBIManager object with one that has a single DBD::Mock handle.

$mock->schema_class()

The schema class name that was passed to the constructor.

$mock->recorder()

Returns the Fey::ORM::Mock::Recorder object that records all inserts, updates, and deletes for tables in this schema.

$mock->seed_class( $class => \%attr, \%attr, ... )

This method accepts a class name and one or more hash references. Each hash reference should consist of some or all of the class's attributes and associated values.

These seeded hash references will be used the next time $class->new() is called without the "_from_query" parameter. This prevents an attempt to fetch data from the database handle.

Note that any attribute values you pass to the constructor will override seeded values.

BUGS

Please report any bugs or feature requests to bug-fey-mock@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

AUTHOR

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2010 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)