PHP Class Phactory\Mongo\Phactory

Datei anzeigen Open project: chriskite/phactory Class Usage Examples

Protected Properties

Property Type Description
$_blueprints * Array of collection name => Blueprint
$_db * Mongo database object

Public Methods

Method Description
__construct ( MongoDB $mongo ) Constructs a Phactory object for testing MongoDB databases
build ( $blueprint_name, $overrides = [] ) * Build a document as an array, optionally overriding some or all of the default values.
buildWithAssociations ( $blueprint_name, $associations = [], $overrides = [] ) * Build a document as an array, optionally overriding some or all of the default values.
create ( $blueprint_name, $overrides = [] ) * Instantiate a document in the specified collection, optionally overriding some or all of the default values.
createWithAssociations ( $blueprint_name, $associations = [], $overrides = [] ) * Instantiate a document in the specified collection, optionally overriding some or all of the default values.
define ( $blueprint_name, $defaults, $associations = [] ) * Define the default values to use when constructing a document in the specified collection.
defineBlueprint ( $blueprint_name, $defaults, $associations = [] ) * alias for define per @jblotus pull request eventually we should just rename the original function
embedsMany ( $collection_name ) * Create an embeds-many association object for use in define().
embedsOne ( $collection_name ) * Create an embeds-one association object for use in define().
get ( $collection_name, $query ) * Get a document from the database as an array.
getAll ( $collection_name, $query = [] ) * Get results from the database as a cursor.
getDb ( ) * Get the Mongo database object.
recall ( ) * Delete created documents from the database.
reset ( ) * Delete created objects from the database, clear defined blueprints, and clear stored inflection exceptions.
setDb ( MongoDB $db ) * Set the Mongo object to use for database connection.
setInflection ( $singular, $plural ) * Specify an exception for collection name inflection.

Method Details

__construct() public method

Constructs a Phactory object for testing MongoDB databases
public __construct ( MongoDB $mongo )
$mongo MongoDB A MongoDB database connection to test with

build() public method

The document is not saved to the database.
public build ( $blueprint_name, $overrides = [] )
$blueprint_name name of the blueprint
$overrides key => value pairs of column => value

buildWithAssociations() public method

The document is not saved to the database.
public buildWithAssociations ( $blueprint_name, $associations = [], $overrides = [] )
$blueprint_name name of the blueprint to use
$associations [collection name] => [array]
$overrides key => value pairs of field => value

create() public method

The document is saved to the database and returned as an array.
public create ( $blueprint_name, $overrides = [] )
$blueprint_name name of the blueprint
$overrides key => value pairs of column => value

createWithAssociations() public method

The document is saved to the database, and returned as an array.
public createWithAssociations ( $blueprint_name, $associations = [], $overrides = [] )
$blueprint_name name of the blueprint to use
$associations [collection name] => [array]
$overrides key => value pairs of field => value

define() public method

* Define the default values to use when constructing a document in the specified collection.
public define ( $blueprint_name, $defaults, $associations = [] )
$blueprint_name singular name of the collection in the database
$defaults key => value pairs of field => value, or a phactory_blueprint
$associations array of phactory_associations

defineBlueprint() public method

* alias for define per @jblotus pull request eventually we should just rename the original function
public defineBlueprint ( $blueprint_name, $defaults, $associations = [] )

embedsMany() public method

* Create an embeds-many association object for use in define().
public embedsMany ( $collection_name )
$collection_name the singular name of the collection to associate with

embedsOne() public method

* Create an embeds-one association object for use in define().
public embedsOne ( $collection_name )
$collection_name the singular name of the collection to associate with

get() public method

* Get a document from the database as an array.
public get ( $collection_name, $query )
$collection_name name of the collection
$query a MongoDB query

getAll() public method

* Get results from the database as a cursor.
public getAll ( $collection_name, $query = [] )
$collection_name name of the collection
$query a MongoDB query

getDb() public method

* Get the Mongo database object.
public getDb ( )

recall() public method

* Delete created documents from the database.
public recall ( )

reset() public method

* Delete created objects from the database, clear defined blueprints, and clear stored inflection exceptions.
public reset ( )

setDb() public method

* Set the Mongo object to use for database connection.
public setDb ( MongoDB $db )
$db MongoDB Mongo object

setInflection() public method

For example, if your collection of fish is called 'fishes', call setInflection('fish', 'fishes')
public setInflection ( $singular, $plural )
$singular singular form of the word.
$plural plural form of the word.

Property Details

$_blueprints protected_oe property

* Array of collection name => Blueprint
protected $_blueprints

$_db protected_oe property

* Mongo database object
protected $_db