Skip to content
Aleksandar Jovanovic edited this page Apr 4, 2015 · 5 revisions

DbMockLibrary\DataContainer

DataContainer extends Base class and is therefore singleton as well. It provides most basic features for handling dummy data. On its own, it is not terribly useful for the users, but its features form the backbone of the library, while providing nice code separation.

Mock data should be a three-dimensional array, in order to simulate database with collections which contain rows, which contain fields, though there are no formal restrictions, other then that it has to be an array. Example:

[
  'collection1' => [], // empty collection
  'collection2' => [
    'row1' => ['field1' => 1]
    'row2' => ['field1' => 2, 'field1' => [1, true]]
  ]
]

Dummy data represents schemaless database (such as MongoDB) and provides no referential integrity features, at the moment, but those features are implemented to a degree in the DependencyHandler class.

Library will always use encapsulating array as a database, its sub-arrays as collections (or tables in SQL terminology) and their sub-arrays as documents (rows in SQL terminology). All those terms are used interchangeably in this wiki, to emphasize implementation neutrality of the library. Usage examples

For additional help, look at the tests, additional input scenarios are tested. initDataContainer

Initializes dummy data.

DataContainer::initDataContainer(['collection1' => ['row1' => ['field1' => 1]]]);

resetData

Resets data to the starting state, by undoing any changes dummy data might have suffered after initialization. Should be done during tear down process of any test which manipulated dummy data, so that next test can work with clean data.

DataContainer::resetData();