Fey::ORM::Mock - Mock Fey::ORM based classes so you can test without a DBMS
version 0.06
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');
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.
Fey::ORM
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.
DBD::Mock
This class provides the following methods:
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.
Fey::ORM::Schema
It also replaces the schema class's existing Fey::DBIManager object with one that has a single DBD::Mock handle.
Fey::DBIManager
The schema class name that was passed to the constructor.
Returns the Fey::ORM::Mock::Recorder object that records all inserts, updates, and deletes for tables in this schema.
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.
$class->new()
Note that any attribute values you pass to the constructor will override seeded values.
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.
bug-fey-mock@rt.cpan.org
Dave Rolsky <autarch@urth.org>
This software is Copyright (c) 2010 by Dave Rolsky.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Fey::ORM::Mock, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Fey::ORM::Mock
CPAN shell
perl -MCPAN -e shell install Fey::ORM::Mock
For more information on module installation, please visit the detailed CPAN module installation guide.