Skip to content

Latest commit

 

History

History
161 lines (94 loc) · 3.84 KB

File metadata and controls

161 lines (94 loc) · 3.84 KB
layout doc
title Doctrine2 Module - Codeception - Documentation

Doctrine2 Module

For additional reference, please review the source

Allows integration and testing for projects with Doctrine2 ORM.

Doctrine2 uses EntityManager to perform all database operations. As the module uses active connection and active entity manager, instance of this object should be passed to this module.

It can be done in bootstrap file, by setting static $em property:

{% highlight php %}

findOneBy() call for current repository. * `param` $entity * `param array` $params #### flushToDatabase Performs $em->flush(); #### grabFromRepository Selects field value from repository. It builds query based on array of parameters. You can use entity associations to build complex queries. Example: {% highlight php %} grabFromRepository('User', 'email', array('name' => 'davert')); ?>

{% endhighlight %}

@version 1.1

  • param $entity
  • param $field
  • param array $params @return array

haveFakeRepository

Mocks the repository.

With this action you can redefine any method of any repository. Please, note: this fake repositories will be accessible through entity manager till the end of test.

Example:

{% highlight php %}

haveFakeRepository('Entity\User', array('findByUsername' => function($username) { return null; })); {% endhighlight %} This creates a stub class for Entity\User repository with redefined method findByUsername, which will always return the NULL value. * `param` $classname * `param array` $methods #### haveInRepository Persists record into repository. This method crates an entity, and sets its properties directly (via reflection). Setters of entity won't be executed, but you can create almost any entity and save it to database. Returns id using `getId` of newly created entity. {% highlight php %} $I->haveInRepository('Entity\User', array('name' => 'davert')); {% endhighlight %} #### persistEntity Adds entity to repository and flushes. You can redefine it's properties with the second parameter. Example: {% highlight php %} persistEntity(new \Entity\User, array('name' => 'Miles')); $I->persistEntity($user, array('name' => 'Miles')); {% endhighlight %} * `param` $obj * `param array` $values #### seeInRepository Flushes changes to database executes a query defined by array. It builds query based on array of parameters. You can use entity associations to build complex queries. Example: {% highlight php %} seeInRepository('User', array('name' => 'davert')); $I->seeInRepository('User', array('name' => 'davert', 'Company' => array('name' => 'Codegyre'))); $I->seeInRepository('Client', array('User' => array('Company' => array('name' => 'Codegyre'))); ?>

{% endhighlight %}

Fails if record for given criteria can't be found,

  • param $entity
  • param array $params

 

Module reference is taken from the source code. Help us to improve documentation. Edit module reference