just another orm...
View the Project on GitHub tflori/orm
» API Reference » ORM\Testing\MocksEntityManager
public function ormAddResult(
string $class,
\ORM\Entity $entities,
): \ORM\Testing\EntityFetcherMock\Result|\Mockery\MockInterface
You can specify the query that you expect in the returned result.
Example:
$this->ormAddResult(Article::class, $em, new Article(['title' => 'Foo']))
->where('deleted_at IS NULL')
->where('title', 'Foo');
$entity = $em->fetch('Article::class')
->where('deleted_at IS NULL')
->where('title', 'Foo')
->one();
Returns | ORM\Testing\EntityFetcherMock\Result|Mockery\MockInterface |
Parameter | Type | Description |
---|---|---|
$class |
string | The class of an Entity |
$entities |
ORM\Entity | The entities that will be returned |
ORM\Testing\MocksEntityManager::ormAddResult
public function ormAllowDelete(string|\ORM\Entity $entity): \Mockery\Expectation
If $em is not given it is determined by get_class($entity).
If $entity is a string then it is assumed to be a class name.
Returns | Mockery\Expectation |
Parameter | Type | Description | |
---|---|---|---|
$entity |
**string | ORM\Entity** |
ORM\Testing\MocksEntityManager::ormAllowDelete
public function ormAllowFetch(
string $class,
array $entities = [],
): \Mockery\Expectation[]|\ORM\EntityFetcher[]|\Mockery\MockInterface[]
Mocks an EntityFetcher with $entities as result.
Returns the Expectation for fetch on entityManager and the mocked EntityFetcher
Warning: this method is deprecated. | Returns | Mockery\Expectation[]|ORM\EntityFetcher[]|Mockery\MockInterface[] | |
Parameter | Type | Description |
---|---|---|
$class |
string | The class that should be fetched |
$entities |
array | The entities that get returned from fetcher |
ORM\Testing\MocksEntityManager::ormAllowFetch
public function ormAllowInsert(
string $class,
array $defaultValues = [],
): \Mockery\Expectation
Mocks the calls to sync and insert as they came for save()
method for a new Entity.
If you omit the auto incremented id in defaultValues it is set to a random value between 1 and 2147483647.
The EntityManager gets determined the same way as in Entity and can be overwritten by third parameter here.
Returns | Mockery\Expectation |
Parameter | Type | Description |
---|---|---|
$class |
string | The class that should get created |
$defaultValues |
array | The default values that came from database (for example: the created column |
has by the default the current timestamp; the id is auto incremented…) |
ORM\Testing\MocksEntityManager::ormAllowInsert
public function ormAllowUpdate(
\ORM\Entity|\Mockery\MockInterface $entity,
array $changingData = [],
array $updatedData = [],
): \Mockery\Expectation
Entity has to be a mock use emCreateMockedEntity()
to create it.
Returns | Mockery\Expectation |
Parameter | Type | Description | |
---|---|---|---|
$entity |
**ORM\Entity | Mockery\MockInterface** | |
$changingData |
array | Emulate changing data during update statement (triggers etc) | |
$updatedData |
array | Emulate data changes in database |
ORM\Testing\MocksEntityManager::ormAllowUpdate
public function ormAttributesToData(string $class, array $attributes): array
e. g. : assertSame(['first_name' => 'John'], ormAttributesToArray(User::class, ['firstName' => 'John'])
Note: this method is idempotent
Returns | array |
Parameter | Type | Description |
---|---|---|
$class |
string | |
$attributes |
array |
ORM\Testing\MocksEntityManager::ormAttributesToData
public function ormCreateMockedEntity(
string $class,
array $data = [],
): \Mockery\MockInterface|\ORM\Entity
Note: the entity will get a random primary key if not predefined.
Returns | Mockery\MockInterface|ORM\Entity |
Parameter | Type | Description |
---|---|---|
$class |
string | |
$data |
array |
ORM\Testing\MocksEntityManager::ormCreateMockedEntity
public function ormExpectDelete(string|\ORM\Entity $entity): mixed
If $em is not given it is determined by get_class($entity).
If $entity is a string then it is assumed to be a class name.
Returns | mixed |
Parameter | Type | Description | |
---|---|---|---|
$entity |
**string | ORM\Entity** |
ORM\Testing\MocksEntityManager::ormExpectDelete
public function ormExpectFetch(
string $class,
array $entities = [],
): \Mockery\Mock|\ORM\EntityFetcher
Mocks and expects an EntityFetcher with $entities as result.
Warning: this method is deprecated. | Returns | Mockery\Mock|ORM\EntityFetcher | |
Parameter | Type | Description |
---|---|---|
$class |
string | The class that should be fetched |
$entities |
array | The entities that get returned from fetcher |
ORM\Testing\MocksEntityManager::ormExpectFetch
public function ormExpectInsert(string $class, array $defaultValues = []): mixed
Mocks and expects the calls to sync and insert as they came for save()
method for a new Entity.
If you omit the auto incremented id in defaultValues it is set to a random value between 1 and 2147483647.
The EntityManager gets determined the same way as in Entity and can be overwritten by third parameter here.
Returns | mixed |
Parameter | Type | Description |
---|---|---|
$class |
string | The class that should get created |
$defaultValues |
array | The default values that came from database (for example: the created column |
has by the default the current timestamp; the id is auto incremented…) |
ORM\Testing\MocksEntityManager::ormExpectInsert
public function ormExpectUpdate(
\ORM\Entity|\Mockery\MockInterface $entity,
array $changingData = [],
array $updatedData = [],
): mixed
Entity has to be a mock use emCreateMockedEntity()
to create it.
Returns | mixed |
Parameter | Type | Description | |
---|---|---|---|
$entity |
**ORM\Entity | Mockery\MockInterface** | |
$changingData |
array | Emulate changing data during update statement (triggers etc) | |
$updatedData |
array | Emulate data changes in database |
ORM\Testing\MocksEntityManager::ormExpectUpdate
public function ormGetEntityManagerInstance(
mixed $class,
): \ORM\Testing\EntityManagerMock|\Mockery\MockInterface|\ORM\EntityManager
Returns | ORM\Testing\EntityManagerMock|Mockery\MockInterface|ORM\EntityManager |
Parameter | Type | Description |
---|---|---|
$class |
mixed |
ORM\Testing\MocksEntityManager::ormGetEntityManagerInstance
public function ormInitMock(
array $options = [],
string $driver = 'mysql',
): \Mockery\MockInterface|\ORM\EntityManager
The mock is partial and you can map and act with it as usual. You should overwrite your dependency injector
with the returned mock object. You can also call defineFor*()
on this mock to use this mock for specific
classes.
The PDO object is mocked too. This object should not receive any calls except for quoting. By default it
accepts quote(string)
, setAttribute(*)
and getAttribute(ATTR_DRIVER_NAME)
. To retrieve and expect other
calls you can use getConnection()
from EntityManager mock object.
Returns | Mockery\MockInterface|ORM\EntityManager |
Parameter | Type | Description |
---|---|---|
$options |
array | Options passed to EntityManager constructor |
$driver |
string | Database driver you are using (results in different dbal instance) |
ORM\Testing\MocksEntityManager::ormInitMock