SYNOPSIS

use Test::More;
use Local::Test qw( test_backend init_backend );

subtest 'test my backend' => \&test_backend, $backend_object,
    schema => { ... },
    $list_objects,
    $set_object,
    $create_object;

DESCRIPTION

This module contains helper routines for testing Yancy.

SEE ALSO

Test::Builder

my ( $url, $backend, %out_items ) = init_backend( $schema, %items );

Initialize a backend for testing with the given items. This routine will check the TEST_YANCY_BACKEND environment variable for connection details, if any. Otherwise, it will create a Yancy::Backend::Memory object for mock testing.

NOTE: This routine will delete all existing data in the given schema!

my $result = test_backend(
    $backend, $schema_name, $schema,
    $list, $create, $set_to,
);

Test that a backend works properly. $backend is a backend object. $schema_name is the schema name to test. $schema is the JSON schema. $list is a list of objects already in the backend. $create is a new object to test creating an object. $set_to is values the newly-create object will be set to, before being deleted.

backend_common( $backend, \&insert_item, $schema );

Runs various tests on the given Yancy::Backend instance. The code is a backend-specific procedure to create items, probably a closure.

my %schema = load_fixtures( 'foreign-key-field', 'auth' );

Load the given test fixtures for the database we're currently testing (loaded from "init_backend" using the TEST_YANCY_BACKEND environment variable). Test fixtures are directories with the given files:

schema.json     - The JSON schema
*.sql           - The SQL schema, named for the backend ("sqlite", "pg", "mysql")

Returns the combined schema ready to be passed-in to a backend or the Yancy plugin.

4 POD Errors

The following errors were encountered while parsing the POD:

Around line 36:

Unknown directive: =sub

Around line 364:

Unknown directive: =sub

Around line 772:

Unknown directive: =sub

Around line 1223:

Unknown directive: =sub