Skip to content
Browse files

rename 'Record' to 'Entity' in line with new Aura.Sql UnitOfWork func…

…tionality
  • Loading branch information...
1 parent 0a150ef commit c8be9c57affc3a81bb8d2886cad8e95ed1bd1bd4 @pmjones pmjones committed Nov 12, 2012
Showing with 404 additions and 397 deletions.
  1. +28 −28 README.md
  2. +2 −2 TODO.md
  3. +5 −5 src.php
  4. +3 −3 src/Aura/Marshal/Collection/GenericCollection.php
  5. +2 −2 src/Aura/Marshal/Data.php
  6. +9 −9 src/Aura/Marshal/{Record → Entity}/Builder.php
  7. +4 −4 src/Aura/Marshal/{Record → Entity}/BuilderInterface.php
  8. +3 −3 src/Aura/Marshal/{Record/GenericRecord.php → Entity/GenericEntity.php}
  9. +1 −1 src/Aura/Marshal/{Record → Entity}/MagicArrayAccessTrait.php
  10. +1 −1 src/Aura/Marshal/{Record → Entity}/MagicPropertyTrait.php
  11. +9 −9 src/Aura/Marshal/Manager.php
  12. +2 −2 src/Aura/Marshal/Proxy/GenericProxy.php
  13. +1 −1 src/Aura/Marshal/Proxy/ProxyInterface.php
  14. +4 −4 src/Aura/Marshal/Relation/AbstractRelation.php
  15. +8 −8 src/Aura/Marshal/Relation/BelongsTo.php
  16. +1 −1 src/Aura/Marshal/Relation/Builder.php
  17. +6 −6 src/Aura/Marshal/Relation/HasMany.php
  18. +5 −5 src/Aura/Marshal/Relation/HasManyThrough.php
  19. +8 −8 src/Aura/Marshal/Relation/HasOne.php
  20. +4 −4 src/Aura/Marshal/Relation/RelationInterface.php
  21. +9 −9 src/Aura/Marshal/Type/Builder.php
  22. +101 −101 src/Aura/Marshal/Type/GenericType.php
  23. +7 −7 tests/Aura/Marshal/CollectionTest.php
  24. +92 −0 tests/Aura/Marshal/EntityTest.php
  25. +2 −2 tests/Aura/Marshal/{MockRecord.php → MockEntity.php}
  26. +9 −0 tests/Aura/Marshal/MockEntityBuilder.php
  27. +0 −9 tests/Aura/Marshal/MockRecordBuilder.php
  28. +1 −1 tests/Aura/Marshal/MockRelation.php
  29. +0 −92 tests/Aura/Marshal/RecordTest.php
  30. +4 −4 tests/Aura/Marshal/RelationTest.php
  31. +73 −66 tests/Aura/Marshal/TypeTest.php
View
56 README.md
@@ -33,7 +33,7 @@ XML, CSV, Mongo, or anything else, and load it into Aura Marshal.)
With Aura Marshal, you use the data retrieval tools of your choice and write
your own queries to retrieve data from a data source. You then load that
-result data into an entity type object, and it creates record and collection
+result data into an entity type object, and it creates entity and collection
objects for you based on a mapping scheme you define for it.
Aura Marshal makes it easy to avoid the N+1 problem when working with a domain
@@ -56,9 +56,9 @@ model, especially in legacy codebases.
Aura Marshal works by using `Type` objects (which define the entity types in
the domain model). Each `Type` has a definition indicating its identity field,
-how to build records and collections, and the relationships to other `Type`
+how to build entities and collections, and the relationships to other `Type`
objects. The `Type` objects are accessed through a type `Manager`. You load
-data into each `Type` in the `Manager`, then you retrieve records and
+data into each `Type` in the `Manager`, then you retrieve entities and
collections from each `Type`.
Example Schema
@@ -144,20 +144,20 @@ Defining Relationships
Aura Marshal recognizes four kinds of relationships between types:
-- `has_one`: A one-to-one relationship where the native record is the owner of
- one foreign record.
+- `has_one`: A one-to-one relationship where the native entity is the owner of
+ one foreign entity.
-- `belongs_to`: A many-to-one relationship where the native record is owned by
- one foreign record. (The foreign record might be the owner of many other
- records.)
+- `belongs_to`: A many-to-one relationship where the native entity is owned by
+ one foreign entity. (The foreign entity might be the owner of many other
+ entities.)
-- `has_many`: A one-to-many relationship where the native record is the owner
- of many foreign records.
+- `has_many`: A one-to-many relationship where the native entity is the owner
+ of many foreign entities.
-- `has_many_through`: A many-to-many relationship where each native record is
- linked to many foreign records; at the same time, each foreign record is
- linked to many native records. This kind of relationship requires an
- association mapping type through which the native and foreign records are
+- `has_many_through`: A many-to-many relationship where each native entity is
+ linked to many foreign entities; at the same time, each foreign entity is
+ linked to many native entities. This kind of relationship requires an
+ association mapping type through which the native and foreign entities are
linked to each other.
Let's add the simpler relationships to our `Manager` using the `setRelation()`
@@ -373,14 +373,14 @@ Reading Data
------------
Now that the domain model has been loaded with data, we can read out the
-record objects, with related data wired up for us automatically.
+entity objects, with related data wired up for us automatically.
```php
<?php
// get a collection of the post IDs we just loaded
$posts = $manager->posts->getCollection($post_ids);
-// loop through posts collection, getting a post record each time
+// loop through posts collection, getting a post entity each time
foreach ($posts as $post) {
// address the native and foreign fields
@@ -408,41 +408,41 @@ foreach ($posts as $post) {
Advanced Usage
==============
-Record and Collection Builders
+Entity and Collection Builders
------------------------------
-We have a good amount of control over how the type objects create records and
+We have a good amount of control over how the type objects create entities and
collections. The instantiation responsibilities are delegated to builder
-objects. We can tell the type object what builders to use for record and
-collection objects by specifying `'record_builder'` and `'collection_builder'`
+objects. We can tell the type object what builders to use for entity and
+collection objects by specifying `'entity_builder'` and `'collection_builder'`
values when defining the type. Similarly, we can tell the type object that
-the record builder will generate a particular class of object; this lets the
-type object know when the loaded data has been converted to a record object.
+the entity builder will generate a particular class of object; this lets the
+type object know when the loaded data has been converted to a entity object.
```php
<?php
$manager->setType('posts', [
// the field with the unique identifying value
'identity_field' => 'id',
- // an object to build records; default is a new instance of
- // Aura\Marshal\Record\Builder
- 'record_builder' => new \Vendor\Package\Posts\RecordBuilder,
+ // an object to build entities; default is a new instance of
+ // Aura\Marshal\Entity\Builder
+ 'entity_builder' => new \Vendor\Package\Posts\EntityBuilder,
// an object to build collections; default is a new instance of
// Aura\Marshal\Collection\Builder
'collection_builder' => new \Vendor\Package\Posts\CollectionBuilder,
]);
```
-The builders should implement `Aura\Marshal\Record\BuilderInterface` and
+The builders should implement `Aura\Marshal\Entity\BuilderInterface` and
`Aura\Marshal\Collection\CollectionInterface`, respectively.
Indexing
--------
-By default, the `Type` objects do not index the values when loading records.
+By default, the `Type` objects do not index the values when loading entities.
You are likely to see a performance improvement when Aura Marshal wires up
related collections if you add indexes for native fields used in
relationships. For example, you could tell the `posts_tags` assocation mapping
@@ -462,7 +462,7 @@ not need indexing). Typically this is needed only on a type that `belongs_to`
another type.
Indexes are created *only at `load()` time*. They are not updated when the
-record object is modified.
+entity object is modified.
All-At-Once Definition
View
4 TODO.md
@@ -1,9 +1,9 @@
-- Do we need a "detach record" method that also removes it from indexes?
+- Do we need a "detach entity" method that also removes it from indexes?
- How can we make IDs update? Is that something for the UnitOfWork to do
as it goes? Would make rolling back more complex.
-- rename Record to Entity? Or, in SQL, rename Entity to Record?
+- rename Entity to Entity? Or, in SQL, rename Entity to Entity?
- can we remove Manager from the relation proper, and leave it only for the
relation builder? would inject the actual type object dependencies, not the
View
10 src.php
@@ -10,11 +10,11 @@
require __DIR__ . '/src/Aura/Marshal/Proxy/Builder.php';
require __DIR__ . '/src/Aura/Marshal/Proxy/ProxyInterface.php';
require __DIR__ . '/src/Aura/Marshal/Proxy/GenericProxy.php';
-require __DIR__ . '/src/Aura/Marshal/Record/MagicArrayAccessTrait.php';
-require __DIR__ . '/src/Aura/Marshal/Record/MagicPropertyTrait.php';
-require __DIR__ . '/src/Aura/Marshal/Record/BuilderInterface.php';
-require __DIR__ . '/src/Aura/Marshal/Record/Builder.php';
-require __DIR__ . '/src/Aura/Marshal/Record/GenericRecord.php';
+require __DIR__ . '/src/Aura/Marshal/Entity/MagicArrayAccessTrait.php';
+require __DIR__ . '/src/Aura/Marshal/Entity/MagicPropertyTrait.php';
+require __DIR__ . '/src/Aura/Marshal/Entity/BuilderInterface.php';
+require __DIR__ . '/src/Aura/Marshal/Entity/Builder.php';
+require __DIR__ . '/src/Aura/Marshal/Entity/GenericEntity.php';
require __DIR__ . '/src/Aura/Marshal/Relation/RelationInterface.php';
require __DIR__ . '/src/Aura/Marshal/Relation/AbstractRelation.php';
require __DIR__ . '/src/Aura/Marshal/Relation/BelongsTo.php';
View
6 src/Aura/Marshal/Collection/GenericCollection.php
@@ -15,7 +15,7 @@
/**
*
- * Represents a generic collection of records.
+ * Represents a generic collection of entities.
*
* @package Aura.Marshal
*
@@ -34,8 +34,8 @@ class GenericCollection extends Data
public function getFieldValues($field)
{
$values = [];
- foreach ($this->data as $offset => $record) {
- $values[$offset] = $record->$field;
+ foreach ($this->data as $offset => $entity) {
+ $values[$offset] = $entity->$field;
}
return $values;
}
View
4 src/Aura/Marshal/Data.php
@@ -18,10 +18,10 @@
*
* - the generic type object, where $data represents an IdentityMap;
*
- * - the generic record object, where $data represents the record fields; and
+ * - the generic entity object, where $data represents the entity fields; and
*
* - the generic collection object, where $data represents an array of
- * records.
+ * entities.
*
* @package Aura.Marshal
*
View
18 src/Aura/Marshal/Record/Builder.php → src/Aura/Marshal/Entity/Builder.php
@@ -8,41 +8,41 @@
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*/
-namespace Aura\Marshal\Record;
+namespace Aura\Marshal\Entity;
use Aura\Marshal\Type\GenericType;
use Aura\Marshal\Proxy\BuilderInterface as ProxyBuilderInterface;
/**
*
- * Creates a new record object for a type.
+ * Creates a new entity object for a type.
*
* @package Aura.Marshal
*
*/
class Builder implements BuilderInterface
{
- protected $class = 'Aura\Marshal\Record\GenericRecord';
+ protected $class = 'Aura\Marshal\Entity\GenericEntity';
/**
*
- * Creates a new record object.
+ * Creates a new entity object.
*
- * @param array|object $data Data to load into the record.
+ * @param array|object $data Data to load into the entity.
*
- * @return GenericRecord
+ * @return GenericEntity
*
*/
public function newInstance(array $data)
{
$class = $this->class;
- $record = new $class;
+ $entity = new $class;
// set fields
foreach ($data as $field => $value) {
- $record->$field = $value;
+ $entity->$field = $value;
}
- return $record;
+ return $entity;
}
}
View
8 src/Aura/Marshal/Record/BuilderInterface.php → src/Aura/Marshal/Entity/BuilderInterface.php
@@ -8,13 +8,13 @@
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*/
-namespace Aura\Marshal\Record;
+namespace Aura\Marshal\Entity;
use Aura\Marshal\Type\GenericType;
/**
*
- * An inteface for RecordBuilder objects.
+ * An inteface for EntityBuilder objects.
*
* @package Aura.Marshal
*
@@ -23,9 +23,9 @@
{
/**
*
- * Creates a new record object.
+ * Creates a new entity object.
*
- * @param mixed $data Data to load into the record.
+ * @param mixed $data Data to load into the entity.
*
*/
public function newInstance(array $data);
View
6 src/Aura/Marshal/Record/GenericRecord.php → src/Aura/Marshal/Entity/GenericEntity.php
@@ -8,18 +8,18 @@
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*/
-namespace Aura\Marshal\Record;
+namespace Aura\Marshal\Entity;
use Aura\Marshal\Data;
/**
*
- * Represents a single record.
+ * Represents a single entity.
*
* @package Aura.Marshal
*
*/
-class GenericRecord extends Data
+class GenericEntity extends Data
{
use MagicArrayAccessTrait;
}
View
2 .../Marshal/Record/MagicArrayAccessTrait.php → .../Marshal/Entity/MagicArrayAccessTrait.php
@@ -1,5 +1,5 @@
<?php
-namespace Aura\Marshal\Record;
+namespace Aura\Marshal\Entity;
use Aura\Marshal\Proxy\ProxyInterface;
View
2 ...ura/Marshal/Record/MagicPropertyTrait.php → ...ura/Marshal/Entity/MagicPropertyTrait.php
@@ -1,5 +1,5 @@
<?php
-namespace Aura\Marshal\Record;
+namespace Aura\Marshal\Entity;
use Aura\Marshal\Proxy\ProxyInterface;
View
18 src/Aura/Marshal/Manager.php
@@ -62,14 +62,14 @@ class Manager
* // the name to use for this type in the manager
* 'some_type_name' => [
*
- * // the identity field in each record
+ * // the identity field in each entity
* 'identity_field' => 'id',
*
* // fields to index against
* 'index_fields' => ['field1', 'field2'],
*
- * // a record builder for the type
- * 'record_builder' => new \Aura\Domain\RecordBuilder,
+ * // a entity builder for the type
+ * 'entity_builder' => new \Aura\Domain\EntityBuilder,
*
* // a collection builder for the type
* 'collection_builder' => new \Aura\Domain\CollectionBuilder,
@@ -103,12 +103,12 @@ class Manager
* // foreign type.
* 'foreign_type' => 'another_type_name',
*
- * // the name of the native (parent) record field to use
- * // when matching foreign (related) records. required.
+ * // the name of the native (parent) entity field to use
+ * // when matching foreign (related) entities. required.
* 'native_field' => 'native_field_name',
*
- * // the name of the foreign (related) record field to use
- * // when matching the native (parent) record. required.
+ * // the name of the foreign (related) entity field to use
+ * // when matching the native (parent) entity. required.
* 'foreign_field' => 'foreign_field_name',
*
* // -------------------------------------------------------
@@ -119,11 +119,11 @@ class Manager
* // and foreign types are mapped to each other.
* 'through_type' => 'mapping_type_name',
*
- * // in the "through" record, the name of the field that
+ * // in the "through" entity, the name of the field that
* // maps to the 'native_field' value
* 'through_native_field' => 'mapping_native_field_name',
*
- * // in the "through" record, the name of the field that
+ * // in the "through" entity, the name of the field that
* // maps to the 'foreign_field' value
* 'through_foreign_field' => 'mapping_foreign_field_name',
* ),
View
4 src/Aura/Marshal/Proxy/GenericProxy.php
@@ -12,8 +12,8 @@ public function __construct(RelationInterface $relation)
$this->relation = $relation;
}
- public function get($record)
+ public function get($entity)
{
- return $this->relation->getForRecord($record);
+ return $this->relation->getForEntity($entity);
}
}
View
2 src/Aura/Marshal/Proxy/ProxyInterface.php
@@ -3,5 +3,5 @@
interface ProxyInterface
{
- public function get($record);
+ public function get($entity);
}
View
8 src/Aura/Marshal/Relation/AbstractRelation.php
@@ -25,7 +25,7 @@
{
/**
*
- * The field in the native record to match against.
+ * The field in the native entity to match against.
*
* @var string
*
@@ -52,7 +52,7 @@
/**
*
- * The field in the foreign record to match against.
+ * The field in the foreign entity to match against.
*
* @var string
*
@@ -70,7 +70,7 @@
/**
*
- * Native and foreign records are mapped to each other through this
+ * Native and foreign entities are mapped to each other through this
* association type.
*
* @var string
@@ -104,7 +104,7 @@
*
* @param string $type The name of the native type.
*
- * @param string $name The name of the record field where the related
+ * @param string $name The name of the entity field where the related
* data will be placed.
*
* @param array $info An array of relationship definition information.
View
16 src/Aura/Marshal/Relation/BelongsTo.php
@@ -12,8 +12,8 @@
/**
*
- * Represents a relationship where the native record belongs to a foreign
- * record; the native record is subordinate to the foreign one.
+ * Represents a relationship where the native entity belongs to a foreign
+ * entity; the native entity is subordinate to the foreign one.
*
* @package Aura.Marshal
*
@@ -22,19 +22,19 @@ class BelongsTo extends AbstractRelation implements RelationInterface
{
/**
*
- * Returns the related foreign record for a native record.
+ * Returns the related foreign entity for a native entity.
*
- * @param mixed $record The native record.
+ * @param mixed $entity The native entity.
*
- * @return GenericRecord
+ * @return GenericEntity
*
*/
- public function getForRecord($record)
+ public function getForEntity($entity)
{
$native_field = $this->native_field;
- return $this->foreign->getRecordByField(
+ return $this->foreign->getEntityByField(
$this->foreign_field,
- $record->$native_field
+ $entity->$native_field
);
}
}
View
2 src/Aura/Marshal/Relation/Builder.php
@@ -43,7 +43,7 @@ class Builder
* @param string $type The name of the native type in the manager.
*
* @param string $name The name of the native field for the related
- * record or collection.
+ * entity or collection.
*
* @param array $info An array of relationship definition information.
*
View
12 src/Aura/Marshal/Relation/HasMany.php
@@ -12,8 +12,8 @@
/**
*
- * Represents a relationship where a native record has many foreign records
- * (i.e., a foreign collection); the foreign records are subordinate to the
+ * Represents a relationship where a native entity has many foreign entities
+ * (i.e., a foreign collection); the foreign entities are subordinate to the
* native one.
*
* @package Aura.Marshal
@@ -23,19 +23,19 @@ class HasMany extends AbstractRelation implements RelationInterface
{
/**
*
- * Returns the related foreign collection for a native record.
+ * Returns the related foreign collection for a native entity.
*
- * @param mixed $record The native record.
+ * @param mixed $entity The native entity.
*
* @return GenericCollection
*
*/
- public function getForRecord($record)
+ public function getForEntity($entity)
{
$native_field = $this->native_field;
return $this->foreign->getCollectionByField(
$this->foreign_field,
- $record->$native_field
+ $entity->$native_field
);
}
}
View
10 src/Aura/Marshal/Relation/HasManyThrough.php
@@ -16,7 +16,7 @@
/**
*
- * Represents a relationship where a native record has many foreign records
+ * Represents a relationship where a native entity has many foreign entities
* (i.e., a foreign collection) mapped through an association type.
*
* @package Aura.Marshal
@@ -26,18 +26,18 @@ class HasManyThrough extends AbstractRelation implements RelationInterface
{
/**
*
- * Returns the related foreign collection for a native record.
+ * Returns the related foreign collection for a native entity.
*
- * @param mixed $record The native record.
+ * @param mixed $entity The native entity.
*
* @return GenericCollection
*
*/
- public function getForRecord($record)
+ public function getForEntity($entity)
{
// first, find the native values in the through type
$native_field = $this->native_field;
- $native_value = $record->$native_field;
+ $native_value = $entity->$native_field;
$through_coll = $this->through->getCollectionByField(
$this->through_native_field,
$native_value
View
16 src/Aura/Marshal/Relation/HasOne.php
@@ -12,8 +12,8 @@
/**
*
- * Represents a relationship where the native record has one of the foreign
- * record; the foreign record is subordinate to the native one.
+ * Represents a relationship where the native entity has one of the foreign
+ * entity; the foreign entity is subordinate to the native one.
*
* @package Aura.Marshal
*
@@ -22,19 +22,19 @@ class HasOne extends AbstractRelation implements RelationInterface
{
/**
*
- * Returns the related foreign record for a native record.
+ * Returns the related foreign entity for a native entity.
*
- * @param mixed $record The native record.
+ * @param mixed $entity The native entity.
*
- * @return GenericRecord
+ * @return GenericEntity
*
*/
- public function getForRecord($record)
+ public function getForEntity($entity)
{
$native_field = $this->native_field;
- return $this->foreign->getRecordByField(
+ return $this->foreign->getEntityByField(
$this->foreign_field,
- $record->$native_field
+ $entity->$native_field
);
}
}
View
8 src/Aura/Marshal/Relation/RelationInterface.php
@@ -21,15 +21,15 @@
{
/**
*
- * Returns the foreign record or collection for a native record.
+ * Returns the foreign entity or collection for a native entity.
*
- * @param mixed $record The record to get the related record or
+ * @param mixed $entity The entity to get the related entity or
* collection for.
*
- * @return GenericRecord|GenericCollection
+ * @return GenericEntity|GenericCollection
*
*/
- public function getForRecord($record);
+ public function getForEntity($entity);
public function getForeignType();
}
View
18 src/Aura/Marshal/Type/Builder.php
@@ -12,7 +12,7 @@
use Aura\Marshal\Collection\Builder as CollectionBuilder;
use Aura\Marshal\Exception;
-use Aura\Marshal\Record\Builder as RecordBuilder;
+use Aura\Marshal\Entity\Builder as EntityBuilder;
use Aura\Marshal\Proxy\Builder as ProxyBuilder;
/**
@@ -31,11 +31,11 @@ class Builder
* The `$info` array should have four keys:
*
* - `'identity_field'` (string): The name of the identity field for
- * records of this type. This key is required.
+ * entities of this type. This key is required.
*
- * - `record_builder` (Record\BuilderInterface): A builder to create
- * record objects for the type. This key is optional, and defaults to a
- * new Record\Builder object.
+ * - `entity_builder` (Entity\BuilderInterface): A builder to create
+ * entity objects for the type. This key is optional, and defaults to a
+ * new Entity\Builder object.
*
* - `collection_builder` (Collection\BuilderInterface): A
* A builder to create collection objects for the type. This key
@@ -51,7 +51,7 @@ public function newInstance($info)
$base = [
'identity_field' => null,
'index_fields' => [],
- 'record_builder' => null,
+ 'entity_builder' => null,
'collection_builder' => null,
'proxy_builder' => null,
];
@@ -62,8 +62,8 @@ public function newInstance($info)
throw new Exception('No identity field specified.');
}
- if (! $info['record_builder']) {
- $info['record_builder'] = new RecordBuilder;
+ if (! $info['entity_builder']) {
+ $info['entity_builder'] = new EntityBuilder;
}
if (! $info['collection_builder']) {
@@ -77,7 +77,7 @@ public function newInstance($info)
$type = new GenericType;
$type->setIdentityField($info['identity_field']);
$type->setIndexFields($info['index_fields']);
- $type->setRecordBuilder($info['record_builder']);
+ $type->setEntityBuilder($info['entity_builder']);
$type->setCollectionBuilder($info['collection_builder']);
$type->setProxyBuilder($info['proxy_builder']);
View
202 src/Aura/Marshal/Type/GenericType.php
@@ -14,14 +14,14 @@
use Aura\Marshal\Data;
use Aura\Marshal\Exception;
use Aura\Marshal\Proxy\BuilderInterface as ProxyBuilderInterface;
-use Aura\Marshal\Record\BuilderInterface as RecordBuilderInterface;
+use Aura\Marshal\Entity\BuilderInterface as EntityBuilderInterface;
use Aura\Marshal\Relation\RelationInterface;
use SplObjectStorage;
/**
*
* Describes a particular type within the domain, and retains an IdentityMap
- * of records for the type. Converts loaded data to record objects lazily.
+ * of entities for the type. Converts loaded data to entity objects lazily.
*
* @package Aura.Marshal
*
@@ -39,7 +39,7 @@ class GenericType extends Data
/**
*
- * The record field representing its unique identifier value. The
+ * The entity field representing its unique identifier value. The
* IdentityMap will be keyed on these values.
*
* @var string
@@ -49,7 +49,7 @@ class GenericType extends Data
/**
*
- * An index of records on the identity field. The format is:
+ * An index of entities on the identity field. The format is:
*
* $index_identity[$identity_value] = $offset;
*
@@ -62,7 +62,7 @@ class GenericType extends Data
/**
*
- * An index of all records added via newRecord(). The format is:
+ * An index of all entities added via newEntity(). The format is:
*
* $index_new[] = $offset;
*
@@ -90,7 +90,7 @@ class GenericType extends Data
/**
*
- * An object store of the initial data for record in the IdentityMap.
+ * An object store of the initial data for entity in the IdentityMap.
*
* @var SplObjectStorage
*
@@ -101,17 +101,17 @@ class GenericType extends Data
/**
*
- * A builder to create record objects for this type.
+ * A builder to create entity objects for this type.
*
* @var object
*
*/
- protected $record_builder;
+ protected $entity_builder;
/**
*
* An array of relationship descriptions, where the key is a
- * field name for the record and the value is a relation object.
+ * field name for the entity and the value is a relation object.
*
* @var array
*
@@ -126,7 +126,7 @@ public function __construct(array $data = [])
/**
*
- * Sets the name of the field that uniquely identifies each record for
+ * Sets the name of the field that uniquely identifies each entity for
* this type.
*
* @param string $identity_field The identity field name.
@@ -141,7 +141,7 @@ public function setIdentityField($identity_field)
/**
*
- * Returns the name of the field that uniquely identifies each record of
+ * Returns the name of the field that uniquely identifies each entity of
* this type.
*
* @return string
@@ -184,28 +184,28 @@ public function getIndexFields()
/**
*
- * Sets the builder object to create record objects.
+ * Sets the builder object to create entity objects.
*
- * @param RecordBuilderInterface $record_builder The builder object.
+ * @param EntityBuilderInterface $entity_builder The builder object.
*
* @return void
*
*/
- public function setRecordBuilder(RecordBuilderInterface $record_builder)
+ public function setEntityBuilder(EntityBuilderInterface $entity_builder)
{
- $this->record_builder = $record_builder;
+ $this->entity_builder = $entity_builder;
}
/**
*
- * Returns the builder that creates record objects.
+ * Returns the builder that creates entity objects.
*
* @return object
*
*/
- public function getRecordBuilder()
+ public function getEntityBuilder()
{
- return $this->record_builder;
+ return $this->entity_builder;
}
/**
@@ -246,7 +246,7 @@ public function getProxyBuilder()
/**
*
- * Loads the IdentityMap for this type with data for record objects.
+ * Loads the IdentityMap for this type with data for entity objects.
*
* Typically, the $data value is a sequential array of associative arrays.
* As long as the $data value can be iterated over and accessed as an
@@ -255,16 +255,16 @@ public function getProxyBuilder()
* The elements from $data will be placed into the IdentityMap and indexed
* according to the value of their identity field.
*
- * You can call load() multiple times, but records already in the
+ * You can call load() multiple times, but entities already in the
* IdentityMap will not be overwritten.
*
* The loaded elements are cast to objects; this allows consistent
- * addressing of elements before and after conversion to record objects.
+ * addressing of elements before and after conversion to entity objects.
*
- * The loaded elements will be converted to record objects by the
- * record builder only as you request them from the IdentityMap.
+ * The loaded elements will be converted to entity objects by the
+ * entity builder only as you request them from the IdentityMap.
*
- * @param array $data Record data to load into the IdentityMap.
+ * @param array $data Entity data to load into the IdentityMap.
*
* @param string $return_field Return values from this field; if empty,
* return values from the identity field (the default).
@@ -289,11 +289,11 @@ public function load(array $data, $return_field = null)
$return_field = $identity_field;
}
- // load each data element as a record
+ // load each data element as a entity
foreach ($data as $initial_data) {
// cast the element to an object for consistent addressing
$initial_data = $initial_data;
- // retain the return value on the record
+ // retain the return value on the entity
$return_values[] = $initial_data[$return_field];
// load into the map
$this->loadData($initial_data, $identity_field, $index_fields);
@@ -303,7 +303,7 @@ public function load(array $data, $return_field = null)
return $return_values;
}
- public function loadRecord(array $initial_data)
+ public function loadEntity(array $initial_data)
{
// what is the identity field for the type?
$identity_field = $this->getIdentityField();
@@ -318,7 +318,7 @@ public function loadRecord(array $initial_data)
$index_fields
);
- // return the record at the offset
+ // return the entity at the offset
return $this->offsetGet($offset);
}
@@ -330,22 +330,22 @@ public function loadCollection(array $data)
// what indexes do we need to track?
$index_fields = array_keys($this->index_fields);
- // the records for the collection
- $records = [];
+ // the entities for the collection
+ $entities = [];
- // load each new record
+ // load each new entity
foreach ($data as $initial_data) {
$offset = $this->loadData(
$initial_data,
$identity_field,
$index_fields
);
- $record = $this->offsetGet($offset);
- $records[] =& $record;
+ $entity = $this->offsetGet($offset);
+ $entities[] =& $entity;
}
- // return a collection of the loaded records
- return $this->collection_builder->newInstance($records);
+ // return a collection of the loaded entities
+ return $this->collection_builder->newInstance($entities);
}
protected function loadData(
@@ -360,24 +360,24 @@ protected function loadData(
return $this->index_identity[$identity_value];
}
- // convert the initial data to a real record in the identity map
- $this->data[] = $this->record_builder->newInstance($initial_data);
+ // convert the initial data to a real entity in the identity map
+ $this->data[] = $this->entity_builder->newInstance($initial_data);
- // get the record and retain initial data
- $record = end($this->data);
- $this->initial_data->attach($record, $initial_data);
+ // get the entity and retain initial data
+ $entity = end($this->data);
+ $this->initial_data->attach($entity, $initial_data);
// build indexes by offset
$offset = key($this->data);
$this->index_identity[$identity_value] = $offset;
foreach ($index_fields as $field) {
- $value = $record->$field;
+ $value = $entity->$field;
$this->index_fields[$field][$value][] = $offset;
}
// set related fields
foreach ($this->getRelations() as $field => $relation) {
- $record->$field = $this->proxy_builder->newInstance($relation);
+ $entity->$field = $this->proxy_builder->newInstance($relation);
}
// done! return the new offset number.
@@ -386,7 +386,7 @@ protected function loadData(
/**
*
- * Returns the array keys for the for the records in the IdentityMap;
+ * Returns the array keys for the for the entities in the IdentityMap;
* the keys were generated at load() time from the identity field values.
*
* @return array
@@ -399,7 +399,7 @@ public function getIdentityValues()
/**
*
- * Returns the values for a particular field for all the records in the
+ * Returns the values for a particular field for all the entities in the
* IdentityMap.
*
* @param string $field The field name to get values for.
@@ -412,27 +412,27 @@ public function getFieldValues($field)
{
$values = [];
$identity_field = $this->getIdentityField();
- foreach ($this->data as $offset => $record) {
- $identity_value = $record->$identity_field;
- $values[$identity_value] = $record->$field;
+ foreach ($this->data as $offset => $entity) {
+ $identity_value = $entity->$identity_field;
+ $values[$identity_value] = $entity->$field;
}
return $values;
}
/**
*
- * Retrieves a single record from the IdentityMap by the value of its
+ * Retrieves a single entity from the IdentityMap by the value of its
* identity field.
*
- * @param int $identity_value The identity value of the record to be
+ * @param int $identity_value The identity value of the entity to be
* retrieved.
*
- * @return object A record object via the record builder.
+ * @return object A entity object via the entity builder.
*
*/
- public function getRecord($identity_value)
+ public function getEntity($identity_value)
{
- // if the record is not in the identity index, exit early
+ // if the entity is not in the identity index, exit early
if (! isset($this->index_identity[$identity_value])) {
return null;
}
@@ -444,8 +444,8 @@ public function getRecord($identity_value)
/**
*
- * Retrieves the first record from the IdentityMap that matches the value
- * of an arbitrary field; it will be converted to a record object
+ * Retrieves the first entity from the IdentityMap that matches the value
+ * of an arbitrary field; it will be converted to a entity object
* if it is not already an object of the proper class.
*
* N.b.: This will not be performant for large sets where the field is not
@@ -455,24 +455,24 @@ public function getRecord($identity_value)
*
* @param mixed $value The value of the field to match on.
*
- * @return object A record object via the record builder.
+ * @return object A entity object via the entity builder.
*
*/
- public function getRecordByField($field, $value)
+ public function getEntityByField($field, $value)
{
// pre-emptively look for an identity field
if ($field == $this->identity_field) {
- return $this->getRecord($value);
+ return $this->getEntity($value);
}
// pre-emptively look for an indexed field for that value
if (isset($this->index_fields[$field])) {
- return $this->getRecordByIndex($field, $value);
+ return $this->getEntityByIndex($field, $value);
}
- // long slow loop through all the records to find a match.
- foreach ($this->data as $offset => $record) {
- if ($record->$field == $value) {
+ // long slow loop through all the entities to find a match.
+ foreach ($this->data as $offset => $entity) {
+ if ($entity->$field == $value) {
return $this->offsetGet($offset);
}
}
@@ -483,17 +483,17 @@ public function getRecordByField($field, $value)
/**
*
- * Retrieves the first record from the IdentityMap matching an index
+ * Retrieves the first entity from the IdentityMap matching an index
* lookup.
*
* @param string $field The indexed field name.
*
* @param string $value The field value to match on.
*
- * @return object A record object via the record builder.
+ * @return object A entity object via the entity builder.
*
*/
- protected function getRecordByIndex($field, $value)
+ protected function getEntityByIndex($field, $value)
{
if (! isset($this->index_fields[$field][$value])) {
return null;
@@ -505,7 +505,7 @@ protected function getRecordByIndex($field, $value)
/**
*
* Retrieves a collection of elements from the IdentityMap by the values
- * of their identity fields; each element will be converted to a record
+ * of their identity fields; each element will be converted to a entity
* object if it is not already an object of the proper class.
*
* @param array $identity_values An array of identity values to retrieve.
@@ -520,7 +520,7 @@ public function getCollection(array $identity_values)
// look up the offset for the identity value
$offset = $this->index_identity[$identity_value];
// assigning by reference keeps the connections
- // when the element is converted to a record
+ // when the element is converted to a entity
$list[] =& $this->data[$offset];
}
return $this->collection_builder->newInstance($list);
@@ -529,7 +529,7 @@ public function getCollection(array $identity_values)
/**
*
* Retrieves a collection of objects from the IdentityMap matching the
- * value of an arbitrary field; these will be converted to records
+ * value of an arbitrary field; these will be converted to entities
* if they are not already objects of the proper class.
*
* The value to be matched can be an array of values, so that you
@@ -566,12 +566,12 @@ public function getCollectionByField($field, $values)
return $this->getCollectionByIndex($field, $values);
}
- // long slow loop through all the records to find a match
+ // long slow loop through all the entities to find a match
$list = [];
- foreach ($this->data as $identity_value => $record) {
- if (in_array($record->$field, $values)) {
+ foreach ($this->data as $identity_value => $entity) {
+ if (in_array($entity->$field, $values)) {
// assigning by reference keeps the connections
- // when the original is converted to a record
+ // when the original is converted to a entity
$list[] =& $this->data[$identity_value];
}
}
@@ -581,14 +581,14 @@ public function getCollectionByField($field, $values)
/**
*
* Looks through the index for a field to retrieve a collection of
- * objects from the IdentityMap; these will be converted to records
+ * objects from the IdentityMap; these will be converted to entities
* if they are not already objects of the proper class.
*
* N.b.: The value to be matched can be an array of values, so that you
* can get many values of the field being matched.
*
* N.b.: The order of the returned collection will match the order of the
- * values being searched, not the order of the records in the IdentityMap.
+ * values being searched, not the order of the entities in the IdentityMap.
*
* @param string $field The field to match on.
*
@@ -606,7 +606,7 @@ protected function getCollectionByIndex($field, $values)
// is there an index for that field value?
if (isset($this->index_fields[$field][$value])) {
// assigning by reference keeps the connections
- // when the original is converted to a record.
+ // when the original is converted to a entity.
foreach ($this->index_fields[$field][$value] as $offset) {
$list[] =& $this->data[$offset];
}
@@ -618,9 +618,9 @@ protected function getCollectionByIndex($field, $values)
/**
*
* Sets a relationship to another type, assigning it to a field
- * name to be used in record objects.
+ * name to be used in entity objects.
*
- * @param string $name The field name to use for the related record
+ * @param string $name The field name to use for the related entity
* or collection.
*
* @param RelationInterface $relation The relationship definition object.
@@ -640,7 +640,7 @@ public function setRelation($name, RelationInterface $relation)
*
* Returns a relationship definition object by name.
*
- * @param string $name The field name to use for the related record
+ * @param string $name The field name to use for the related entity
* or collection.
*
* @return RelationInterface
@@ -658,55 +658,55 @@ public function getRelations()
/**
*
- * Adds a new record to the IdentityMap.
+ * Adds a new entity to the IdentityMap.
*
- * This record will not show up in any indexes, whether by field or
+ * This entity will not show up in any indexes, whether by field or
* by primary key. You will see it only by iterating through the
* IdentityMap. Typically this is used to add to a collection, or
- * to create a new record from user input.
+ * to create a new entity from user input.
*
- * @param array $data Data for the new record.
+ * @param array $data Data for the new entity.
*
* @return object
*
*/
- public function newRecord(array $data = [])
+ public function newEntity(array $data = [])
{
- $record = $this->record_builder->newInstance($data);
+ $entity = $this->entity_builder->newInstance($data);
$this->index_new[] = count($this->data);
- $this->data[] = $record;
- return $record;
+ $this->data[] = $entity;
+ return $entity;
}
/**
*
- * Returns an array of all records in the IdentityMap that have been
+ * Returns an array of all entities in the IdentityMap that have been
* modified.
*
* @return array
*
*/
- public function getChangedRecords()
+ public function getChangedEntities()
{
$list = [];
foreach ($this->index_identity as $identity_value => $offset) {
- $record = $this->data[$offset];
- if ($this->getChangedFields($record)) {
- $list[$identity_value] = $record;
+ $entity = $this->data[$offset];
+ if ($this->getChangedFields($entity)) {
+ $list[$identity_value] = $entity;
}
}
return $list;
}
/**
*
- * Returns an array of all records in the IdentityMap that were created
- * using `newRecord()`.
+ * Returns an array of all entities in the IdentityMap that were created
+ * using `newEntity()`.
*
* @return array
*
*/
- public function getNewRecords()
+ public function getNewEntities()
{
$list = [];
foreach ($this->index_new as $offset) {
@@ -715,26 +715,26 @@ public function getNewRecords()
return $list;
}
- public function getInitialData($record)
+ public function getInitialData($entity)
{
- if ($this->initial_data->contains($record)) {
- return $this->initial_data[$record];
+ if ($this->initial_data->contains($entity)) {
+ return $this->initial_data[$entity];
}
}
- public function getChangedFields($record)
+ public function getChangedFields($entity)
{
// the eventual list of changed fields and values
$changed = [];
- // initial data for this record
- $initial_data = $this->getInitialData($record);
+ // initial data for this entity
+ $initial_data = $this->getInitialData($entity);
// go through all the initial data values
foreach ($initial_data as $field => $old) {
- // what is the new value on the record?
- $new = $record->$field;
+ // what is the new value on the entity?
+ $new = $entity->$field;
// are both old and new values numeric?
$numeric = is_numeric($old) && is_numeric($new);
View
14 tests/Aura/Marshal/CollectionTest.php
@@ -2,7 +2,7 @@
namespace Aura\Marshal;
use Aura\Marshal\Collection\GenericCollection;
use Aura\Marshal\Type\GenericType;
-use Aura\Marshal\Record\Builder as RecordBuilder;
+use Aura\Marshal\Entity\Builder as EntityBuilder;
use Aura\Marshal\Collection\Builder as CollectionBuilder;
use Aura\Marshal\Proxy\Builder as ProxyBuilder;
@@ -64,7 +64,7 @@ public function testObjectsInCollectionAreInIdentityMap()
{
$type = new GenericType;
$type->setIdentityField('id');
- $type->setRecordBuilder(new RecordBuilder);
+ $type->setEntityBuilder(new EntityBuilder);
$type->setCollectionBuilder(new CollectionBuilder);
$ids = [1, 2, 3, 5, 7, 11, 13];
@@ -80,15 +80,15 @@ public function testObjectsInCollectionAreInIdentityMap()
$type->load($data);
// get a collection of all the IDs from the type *before* creating
- // any record objects.
+ // any entity objects.
$collection = $type->getCollection($ids);
- // get a record by ID from the type and change it.
- // note that getRecord() is by identity value, not offset.
- $expect = $type->getRecord(1);
+ // get a entity by ID from the type and change it.
+ // note that getEntity() is by identity value, not offset.
+ $expect = $type->getEntity(1);
$expect->name = 'changed';
- // now get what should be the same record from the collection.
+ // now get what should be the same entity from the collection.
// it should be changed as well.
// note that collection is by offset, not identity value.
$actual = $collection[0];
View
92 tests/Aura/Marshal/EntityTest.php
@@ -0,0 +1,92 @@
+<?php
+namespace Aura\Marshal;
+
+use Aura\Marshal\Entity\GenericEntity;
+use Aura\Marshal\MockEntity;
+use Aura\Marshal\Entity\Builder;
+use Aura\Marshal\MockEntityBuilder;
+use Aura\Marshal\Proxy\Builder as ProxyBuilder;
+use Aura\Marshal\Proxy\GenericProxy;
+
+/**
+ * Test class for Entity.
+ * Generated by PHPUnit on 2011-11-26 at 14:30:57.
+ */
+class EntityTest extends \PHPUnit_Framework_TestCase
+{
+ protected function getData()
+ {
+ return [
+ 'foo' => 'bar',
+ 'baz' => 'dim',
+ 'zim' => 'gir',
+ 'related' => new GenericProxy(new MockRelation),
+ ];
+ }
+
+ protected function newGenericEntity()
+ {
+ $builder = new Builder;
+ return $builder->newInstance($this->getData());
+ }
+
+ protected function newMockEntity()
+ {
+ $builder = new MockEntityBuilder;
+ return $builder->newInstance($this->getData());
+ }
+
+ public function testMagicArrayAccess()
+ {
+ $entity = $this->newGenericEntity();
+
+ // check set/get
+ $entity->irk = 'doom';
+ $this->assertSame('doom', $entity->irk);
+
+ // check isset/unset
+ $this->assertTrue(isset($entity->foo));
+ unset($entity->foo);
+ $this->assertFalse(isset($entity->foo));
+
+ $this->assertFalse(isset($entity->newfield));
+
+ $entity->newfield = 'something';
+ $this->assertTrue(isset($entity->newfield));
+
+ unset($entity->newfield);
+ $this->assertFalse(isset($entity->newfield));
+
+ // check relateds
+ $actual = $entity->related;
+ $expect = (object) ['foreign_field' => 'foreign_value'];
+ $this->assertEquals($expect, $actual);
+ }
+
+ public function testMagicPropertyAccess()
+ {
+ $entity = $this->newMockEntity();
+
+ // check set/get
+ $entity->irk = 'doom';
+ $this->assertSame('doom', $entity->irk);
+
+ // check isset/unset
+ $this->assertTrue(isset($entity->foo));
+ unset($entity->foo);
+ $this->assertFalse(isset($entity->foo));
+
+ $this->assertFalse(isset($entity->newfield));
+
+ $entity->newfield = 'something';
+ $this->assertTrue(isset($entity->newfield));
+
+ unset($entity->newfield);
+ $this->assertFalse(isset($entity->newfield));
+
+ // check relateds
+ $actual = $entity->related;
+ $expect = (object) ['foreign_field' => 'foreign_value'];
+ $this->assertEquals($expect, $actual);
+ }
+}
View
4 tests/Aura/Marshal/MockRecord.php → tests/Aura/Marshal/MockEntity.php
@@ -1,9 +1,9 @@
<?php
namespace Aura\Marshal;
-use Aura\Marshal\Record\MagicPropertyTrait;
+use Aura\Marshal\Entity\MagicPropertyTrait;
-class MockRecord
+class MockEntity
{
use MagicPropertyTrait;
View
9 tests/Aura/Marshal/MockEntityBuilder.php
@@ -0,0 +1,9 @@
+<?php
+namespace Aura\Marshal;
+
+use Aura\Marshal\Entity\Builder;
+
+class MockEntityBuilder extends Builder
+{
+ protected $class = 'Aura\Marshal\MockEntity';
+}
View
9 tests/Aura/Marshal/MockRecordBuilder.php
@@ -1,9 +0,0 @@
-<?php
-namespace Aura\Marshal;
-
-use Aura\Marshal\Record\Builder;
-
-class MockRecordBuilder extends Builder
-{
- protected $class = 'Aura\Marshal\MockRecord';
-}
View
2 tests/Aura/Marshal/MockRelation.php
@@ -5,7 +5,7 @@
class MockRelation implements RelationInterface
{
- public function getForRecord($record)
+ public function getForEntity($entity)
{
return (object) ['foreign_field' => 'foreign_value'];
}
View
92 tests/Aura/Marshal/RecordTest.php
@@ -1,92 +0,0 @@
-<?php
-namespace Aura\Marshal;
-
-use Aura\Marshal\Record\GenericRecord;
-use Aura\Marshal\MockRecord;
-use Aura\Marshal\Record\Builder;
-use Aura\Marshal\MockRecordBuilder;
-use Aura\Marshal\Proxy\Builder as ProxyBuilder;
-use Aura\Marshal\Proxy\GenericProxy;
-
-/**
- * Test class for Record.
- * Generated by PHPUnit on 2011-11-26 at 14:30:57.
- */
-class RecordTest extends \PHPUnit_Framework_TestCase
-{
- protected function getData()
- {
- return [
- 'foo' => 'bar',
- 'baz' => 'dim',
- 'zim' => 'gir',
- 'related' => new GenericProxy(new MockRelation),
- ];
- }
-
- protected function newGenericRecord()
- {
- $builder = new Builder;
- return $builder->newInstance($this->getData());
- }
-
- protected function newMockRecord()
- {
- $builder = new MockRecordBuilder;
- return $builder->newInstance($this->getData());
- }
-
- public function testMagicArrayAccess()
- {
- $record = $this->newGenericRecord();
-
- // check set/get
- $record->irk = 'doom';
- $this->assertSame('doom', $record->irk);
-
- // check isset/unset
- $this->assertTrue(isset($record->foo));
- unset($record->foo);
- $this->assertFalse(isset($record->foo));
-
- $this->assertFalse(isset($record->newfield));
-
- $record->newfield = 'something';
- $this->assertTrue(isset($record->newfield));
-
- unset($record->newfield);
- $this->assertFalse(isset($record->newfield));
-
- // check relateds
- $actual = $record->related;
- $expect = (object) ['foreign_field' => 'foreign_value'];
- $this->assertEquals($expect, $actual);
- }
-
- public function testMagicPropertyAccess()
- {
- $record = $this->newMockRecord();
-
- // check set/get
- $record->irk = 'doom';
- $this->assertSame('doom', $record->irk);
-
- // check isset/unset
- $this->assertTrue(isset($record->foo));
- unset($record->foo);
- $this->assertFalse(isset($record->foo));
-
- $this->assertFalse(isset($record->newfield));
-
- $record->newfield = 'something';
- $this->assertTrue(isset($record->newfield));
-
- unset($record->newfield);
- $this->assertFalse(isset($record->newfield));
-
- // check relateds
- $actual = $record->related;
- $expect = (object) ['foreign_field' => 'foreign_value'];
- $this->assertEquals($expect, $actual);
- }
-}
View
8 tests/Aura/Marshal/RelationTest.php
@@ -142,22 +142,22 @@ public function testGetForeignType()
public function testBelongsTo()
{
- $post = $this->manager->posts->getRecord(1);
+ $post = $this->manager->posts->getEntity(1);
$this->assertSame('1', $post->author->id);
$this->assertSame('Anna', $post->author->name);
}
public function testHasOne()
{
- $post = $this->manager->posts->getRecord(1);
+ $post = $this->manager->posts->getEntity(1);
$this->assertSame('1', $post->meta->id);
$this->assertSame('1', $post->meta->post_id);
$this->assertSame('meta 1', $post->meta->data);
}
public function testHasMany()
{
- $post = $this->manager->posts->getRecord(5);
+ $post = $this->manager->posts->getEntity(5);
$this->assertSame(3, count($post->comments));
$data = include __DIR__ . DIRECTORY_SEPARATOR . 'fixture_data.php';
@@ -176,7 +176,7 @@ public function testHasMany()
public function testHasManyThrough()
{
- $post = $this->manager->posts->getRecord(3);
+ $post = $this->manager->posts->getEntity(3);
$this->assertSame(2, count($post->tags));
$data = include __DIR__ . DIRECTORY_SEPARATOR . 'fixture_data.php';
View
139 tests/Aura/Marshal/TypeTest.php
@@ -2,9 +2,9 @@
namespace Aura\Marshal;
use Aura\Marshal\Collection\Builder as CollectionBuilder;
-use Aura\Marshal\Record\Builder as RecordBuilder;
-use Aura\Marshal\Record\GenericCollection;
-use Aura\Marshal\Record\GenericRecord;
+use Aura\Marshal\Entity\Builder as EntityBuilder;
+use Aura\Marshal\Entity\GenericCollection;
+use Aura\Marshal\Entity\GenericEntity;
use Aura\Marshal\Relation\Builder as RelationBuilder;
use Aura\Marshal\Type\Builder as TypeBuilder;
use Aura\Marshal\Type\GenericType;
@@ -35,7 +35,7 @@ protected function setUp()
$this->type = new GenericType;
$this->type->setIdentityField($info['identity_field']);
$this->type->setIndexFields($info['index_fields']);
- $this->type->setRecordBuilder(new RecordBuilder(new ProxyBuilder));
+ $this->type->setEntityBuilder(new EntityBuilder(new ProxyBuilder));
$this->type->setCollectionBuilder(new CollectionBuilder);
}
@@ -71,11 +71,11 @@ public function testSetAndGetIndexFields()
$this->assertSame($expect, $actual);
}
- public function testSetAndGetRecordBuilder()
+ public function testSetAndGetEntityBuilder()
{
- $builder = new RecordBuilder;
- $this->type->setRecordBuilder($builder);
- $actual = $this->type->getRecordBuilder();
+ $builder = new EntityBuilder;
+ $this->type->setEntityBuilder($builder);
+ $actual = $this->type->getEntityBuilder();
$this->assertSame($builder, $actual);
}
@@ -87,6 +87,14 @@ public function testSetAndGetCollectionBuilder()
$this->assertSame($builder, $actual);
}
+ public function testSetAndGetProxyBuilder()
+ {
+ $builder = new ProxyBuilder;
+ $this->type->setProxyBuilder($builder);
+ $actual = $this->type->getProxyBuilder();
+ $this->assertSame($builder, $actual);
+ }
+
public function testLoadAndGetStorage()
{
$data = $this->loadTypeWithPosts();
@@ -117,73 +125,73 @@ public function testGetFieldValues()
$this->assertSame($expect, $actual);
}
- public function testGetRecord()
+ public function testGetEntity()
{
$data = $this->loadTypeWithPosts();
$expect = (object) $data[2];
- $actual = $this->type->getRecord(3);
+ $actual = $this->type->getEntity(3);
$this->assertSame($expect->id, $actual->id);
$this->assertSame($expect->author_id, $actual->author_id);
$this->assertSame($expect->body, $actual->body);
// get it again for complete code coverage
- $again = $this->type->getRecord(3);
+ $again = $this->type->getEntity(3);
$this->assertSame($actual, $again);
}
- public function testGetRecord_none()
+ public function testGetEntity_none()
{
$data = $this->loadTypeWithPosts();
- $actual = $this->type->getRecord(999);
+ $actual = $this->type->getEntity(999);
$this->assertNull($actual);
}
- public function testGetRecordByField_identity()
+ public function testGetEntityByField_identity()
{
$data = $this->loadTypeWithPosts();
$expect = (object) $data[3];
- $actual = $this->type->getRecordByField('id', 4);
+ $actual = $this->type->getEntityByField('id', 4);
$this->assertSame($expect->id, $actual->id);
$this->assertSame($expect->author_id, $actual->author_id);
$this->assertSame($expect->body, $actual->body);
}
- public function testGetRecordByField_index()
+ public function testGetEntityByField_index()
{
$data = $this->loadTypeWithPosts();
$expect = (object) $data[3];
- $actual = $this->type->getRecordByField('author_id', 2);
+ $actual = $this->type->getEntityByField('author_id', 2);
$this->assertSame($expect->id, $actual->id);
$this->assertSame($expect->author_id, $actual->author_id);
$this->assertSame($expect->body, $actual->body);
}
- public function testGetRecordByField_indexNone()
+ public function testGetEntityByField_indexNone()
{
$data = $this->loadTypeWithPosts();
- $actual = $this->type->getRecordByField('author_id', 'no such value');
+ $actual = $this->type->getEntityByField('author_id', 'no such value');
$this->assertNull($actual);
}
- public function testGetRecordByField_loop()
+ public function testGetEntityByField_loop()
{
$data = $this->loadTypeWithPosts();
$expect = (object) $data[3];
- $actual = $this->type->getRecordByField('fake_field', '88');
+ $actual = $this->type->getEntityByField('fake_field', '88');
$this->assertSame($expect->id, $actual->id);
$this->assertSame($expect->author_id, $actual->author_id);
$this->assertSame($expect->body, $actual->body);
$this->assertSame($expect->fake_field, $actual->fake_field);
}
- public function testGetRecordByField_loopNone()
+ public function testGetEntityByField_loopNone()
{
$data = $this->loadTypeWithPosts();
- $actual = $this->type->getRecordByField('fake_field', 'no such value');
+ $actual = $this->type->getEntityByField('fake_field', 'no such value');
$this->assertNull($actual);
}
@@ -306,116 +314,116 @@ public function testTypeBuilder_noIdentityField()
$type = $type_builder->newInstance([]);
}
- public function testNewRecord()
+ public function testNewEntity()
{
$this->loadTypeWithPosts();
$before = count($this->type);
- // do we actually get a new record back?
- $record = $this->type->newRecord();
- $this->assertInstanceOf('Aura\Marshal\Record\GenericRecord', $record);
+ // do we actually get a new entity back?
+ $entity = $this->type->newEntity();
+ $this->assertInstanceOf('Aura\Marshal\Entity\GenericEntity', $entity);
// has it been added to the identity map?
$expect = $before + 1;
$actual = count($this->type);
$this->assertSame($expect, $actual);
}
- public function testGetChangedRecords()
+ public function testGetChangedEntities()
{
$data = $this->loadTypeWithPosts();
- // change record id 1 and 3
- $record_1 = $this->type->getRecord(1);
- $record_1->fake_field = 'changed';
- $record_3 = $this->type->getRecord(3);
- $record_3->fake_field = 'changed';
+ // change entity id 1 and 3
+ $entity_1 = $this->type->getEntity(1);
+ $entity_1->fake_field = 'changed';
+ $entity_3 = $this->type->getEntity(3);
+ $entity_3->fake_field = 'changed';
- // get record 2 but don't change it
- $record_2 = $this->type->getRecord(2);
- $fake_field = $record_2->fake_field;
- $record_2->fake_field = $fake_field;
+ // get entity 2 but don't change it
+ $entity_2 = $this->type->getEntity(2);
+ $fake_field = $entity_2->fake_field;
+ $entity_2->fake_field = $fake_field;
// now check for changes
$expect = [
- $record_1->id => $record_1,
- $record_3->id => $record_3,
+ $entity_1->id => $entity_1,
+ $entity_3->id => $entity_3,
];
- $actual = $this->type->getChangedRecords();
+ $actual = $this->type->getChangedEntities();
$this->assertSame($expect, $actual);
}
- public function testGetNewRecords()
+ public function testGetNewEntities()
{
$data = $this->loadTypeWithPosts();
$expect = [
- $this->type->newRecord(['fake_field' => 101]),
- $this->type->newRecord(['fake_field' => 102]),
- $this->type->newRecord(['fake_field' => 105]),
+ $this->type->newEntity(['fake_field' => 101]),
+ $this->type->newEntity(['fake_field' => 102]),
+ $this->type->newEntity(['fake_field' => 105]),
];
- $actual = $this->type->getNewRecords();
+ $actual = $this->type->getNewEntities();
$this->assertSame($expect, $actual);