Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement namespaces.

  • Loading branch information...
commit 4fc630d6cf7daa8eb58eb8675332b747c289deee 1 parent af6ca57
@DrPheltRight DrPheltRight authored
Showing with 330 additions and 191 deletions.
  1. +3 −1 classes/{ → Gignite/TheCure/Collections}/Collection.php
  2. +3 −1 classes/{Collection → Gignite/TheCure/Collections}/Iterable.php
  3. +5 −1 classes/{Collection → Gignite/TheCure/Collections}/Model.php
  4. +1 −0  classes/{ → Gignite/TheCure/Connections}/Connection.php
  5. +9 −3 classes/{Connection → Gignite/TheCure/Connections}/Mongo.php
  6. +1 −0  classes/{ → Gignite/TheCure}/Field.php
  7. +10 −1 classes/{ → Gignite/TheCure}/IdentityMap.php
  8. +5 −1 classes/{MapperActions.php → Gignite/TheCure/Mapper/Actions.php}
  9. +5 −1 classes/{MapperConnection.php → Gignite/TheCure/Mapper/ConnectionSetGet.php}
  10. +8 −4 classes/{MapperContainer.php → Gignite/TheCure/Mapper/Container.php}
  11. +15 −3 classes/{ → Gignite/TheCure/Mappers}/Mapper.php
  12. +7 −4 classes/{Mapper/Array.php → Gignite/TheCure/Mappers/Mock.php}
  13. +7 −1 classes/{Mapper → Gignite/TheCure/Mappers}/Mongo.php
  14. +122 −0 classes/Gignite/TheCure/Models/Magic.php
  15. +3 −1 classes/{ → Gignite/TheCure/Models}/Model.php
  16. +10 −0 classes/Gignite/TheCure/Relation/Add.php
  17. +4 −0 classes/Gignite/TheCure/Relation/FieldNotFoundException.php
  18. +4 −0 classes/Gignite/TheCure/Relation/NotFoundException.php
  19. +10 −0 classes/Gignite/TheCure/Relation/Remove.php
  20. +10 −0 classes/Gignite/TheCure/Relation/Set.php
  21. +10 −8 classes/{Relationship → Gignite/TheCure/Relationships}/OneToMany.php
  22. +9 −7 classes/{Relationship → Gignite/TheCure/Relationships}/OneToOne.php
  23. +6 −2 classes/{ → Gignite/TheCure/Relationships}/Relationship.php
  24. +0 −97 classes/Model/Magic.php
  25. +0 −3  classes/RelationFieldNotFoundException.php
  26. +0 −3  classes/RelationNotFoundException.php
  27. +0 −7 classes/Relationship/Add.php
  28. +0 −7 classes/Relationship/Remove.php
  29. +0 −7 classes/Relationship/Set.php
  30. +25 −13 phpunit.php
  31. +4 −1 test/CollectionIterableTest.php
  32. +4 −1 test/CollectionModelTest.php
  33. +2 −0  test/CollectionTest.php
  34. +2 −0  test/IdentityMapTest.php
  35. +2 −0  test/MapperArrayTest.php
  36. +4 −3 test/MapperContainerTest.php
  37. +4 −1 test/MapperMongoTest.php
  38. +2 −1  test/ModelMagicTest.php
  39. +9 −5 test/RelationshipOneToManyTest.php
  40. +5 −3 test/RelationshipOneToOneTest.php
View
4 classes/Collection.php → classes/Gignite/TheCure/Collections/Collection.php
@@ -11,7 +11,9 @@
* @copyright Luke Morton, 2011
* @license MIT
*/
-class Collection implements Iterator, Countable {
+namespace Gignite\TheCure\Collections;
+
+class Collection implements \Iterator, \Countable {
protected $i;
View
4 classes/Collection/Iterable.php → classes/Gignite/TheCure/Collections/Iterable.php
@@ -12,7 +12,9 @@
* @copyright Luke Morton, 2011
* @license MIT
*/
-class Collection_Iterable extends Collection {
+namespace Gignite\TheCure\Collections;
+
+class Iterable extends Collection {
public function current()
{
View
6 classes/Collection/Model.php → classes/Gignite/TheCure/Collections/Model.php
@@ -12,7 +12,11 @@
* @copyright Luke Morton, 2011
* @license MIT
*/
-class Collection_Model extends Collection_Iterable {
+namespace Gignite\TheCure\Collections;
+
+use Gignite\TheCure\IdentityMap;
+
+class Model extends Iterable {
protected $identities;
View
1  classes/Connection.php → classes/Gignite/TheCure/Connections/Connection.php
@@ -1,4 +1,5 @@
<?php
+namespace Gignite\TheCure\Connections;
interface Connection {
View
12 classes/Connection/Mongo.php → classes/Gignite/TheCure/Connections/Mongo.php
@@ -1,6 +1,7 @@
<?php
+namespace Gignite\TheCure\Connections;
-class Connection_Mongo implements Connection {
+class Mongo implements Connection {
protected $connection;
@@ -11,12 +12,17 @@ public function __construct(array $config)
protected function config($key, $default = NULL)
{
- return Arr::get($this->config, $key, $default);
+ if (isset($this->config[$key]))
+ {
+ return $this->config[$key];
+ }
+
+ return $default;
}
protected function connect()
{
- return new Mongo($this->config('connection', 'mongodb://127.0.0.1'));
+ return new \Mongo($this->config('connection', 'mongodb://127.0.0.1'));
}
public function get()
View
1  classes/Field.php → classes/Gignite/TheCure/Field.php
@@ -1,4 +1,5 @@
<?php
+namespace Gignite\TheCure;
class Field {
View
11 classes/IdentityMap.php → classes/Gignite/TheCure/IdentityMap.php
@@ -1,4 +1,8 @@
<?php
+namespace Gignite\TheCure;
+
+use Gignite\TheCure\Models\Model;
+
/**
* Describe the identities handled in a session
*
@@ -53,7 +57,12 @@ public function has(Model $model)
public function get($class, $id)
{
- return Arr::get($this->identities, $this->key($class, $id));
+ $key = $this->key($class, $id);
+
+ if (isset($this->identities[$key]))
+ {
+ return $this->identities[$key];
+ }
}
public function set(Model $model)
View
6 classes/MapperActions.php → classes/Gignite/TheCure/Mapper/Actions.php
@@ -6,7 +6,11 @@
* @category Mapper
* @copyright Gignite, 2012
*/
-interface MapperActions {
+namespace Gignite\TheCure\Mapper;
+
+use Gignite\TheCure\Models\Model;
+
+interface Actions {
/**
* Find a Collection of records.
View
6 classes/MapperConnection.php → classes/Gignite/TheCure/Mapper/ConnectionSetGet.php
@@ -6,7 +6,11 @@
* @category Mapper
* @copyright Gignite, 2012
*/
-interface MapperConnection {
+namespace Gignite\TheCure\Mapper;
+
+use Gignite\TheCure\Connections\Connection;
+
+interface ConnectionSetGet {
/**
* Get/set the connection.
View
12 classes/MapperContainer.php → classes/Gignite/TheCure/Mapper/Container.php
@@ -13,7 +13,11 @@
* @category Container
* @copyright Gignite, 2012
*/
-class MapperContainer {
+namespace Gignite\TheCure\Mapper;
+
+use Gignite\TheCure\IdentityMap;
+
+class Container {
protected $config;
@@ -54,9 +58,9 @@ public function config(array $config = NULL)
{
if ($this->config === NULL
AND class_exists('Kohana')
- AND isset(Kohana::$config))
+ AND isset(\Kohana::$config))
{
- $config = Kohana::$config->load("mappers.{$this->type()}");
+ $config = \Kohana::$config->load("mappers.{$this->type()}");
}
return $this->config;
@@ -110,7 +114,7 @@ public function mapper($class)
{
$mapper = new $class;
- if ($mapper instanceOf MapperConnection)
+ if ($mapper instanceOf ConnectionSetGet)
{
$mapper->connection($this->connection());
}
View
18 classes/Mapper.php → classes/Gignite/TheCure/Mappers/Mapper.php
@@ -1,4 +1,11 @@
<?php
+namespace Gignite\TheCure\Mappers;
+
+use Gignite\TheCure\Mapper\Actions as MapperActions;
+use Gignite\TheCure\IdentityMap;
+use Gignite\TheCure\Models\Model;
+use Gignite\TheCure\Collections\Collection;
+use Gignite\TheCure\Collections\Model as ModelCollection;
abstract class Mapper implements MapperActions {
@@ -24,7 +31,12 @@ public function config($config, $default = NULL)
}
elseif ($this->config)
{
- return Arr::get($this->config, $config, $default);
+ if (isset($this->config[$config]))
+ {
+ return $this->config[$config];
+ }
+
+ return $default;
}
}
@@ -69,13 +81,13 @@ protected function create_collection($suffix, $where, $callback)
}
else
{
- throw new InvalidArgumentException;
+ throw new \InvalidArgumentException;
}
}
$cursor = call_user_func($callback, $where);
$class = $this->model_class($suffix);
- return new Collection_Model($cursor, $this->identities(), $class);
+ return new ModelCollection($cursor, $this->identities(), $class);
}
/**
View
11 classes/Mapper/Array.php → classes/Gignite/TheCure/Mappers/Mock.php
@@ -1,6 +1,9 @@
<?php
+namespace Gignite\TheCure\Mappers;
-abstract class Mapper_Array extends Mapper {
+use Gignite\TheCure\Models\Model;
+
+abstract class Mock extends Mapper {
public $data = array();
@@ -54,7 +57,7 @@ function($where) use ($collection)
{
$found = array();
- Mapper_Array::each_where(
+ Mock::each_where(
$collection,
$where,
function ($record) use ($collection, & $found)
@@ -62,7 +65,7 @@ function ($record) use ($collection, & $found)
$found[$record] = $collection[$record];
});
- return new ArrayIterator($found);
+ return new \ArrayIterator($found);
});
}
@@ -82,7 +85,7 @@ function ($where) use ($collection)
elseif ($where)
{
$found = NULL;
- Mapper_Array::each_where(
+ Mock::each_where(
$collection,
$where,
function ($record) use ($collection, & $found)
View
8 classes/Mapper/Mongo.php → classes/Gignite/TheCure/Mappers/Mongo.php
@@ -1,6 +1,12 @@
<?php
+namespace Gignite\TheCure\Mappers;
-abstract class Mapper_Mongo extends Mapper implements MapperConnection {
+use Gignite\TheCure\Connections\Connection;
+use Gignite\TheCure\Mapper\ConnectionSetGet;
+use Gignite\TheCure\Mappers\Mapper;
+use Gignite\TheCure\Models\Model;
+
+abstract class Mongo extends Mapper implements ConnectionSetGet {
protected $connection;
View
122 classes/Gignite/TheCure/Models/Magic.php
@@ -0,0 +1,122 @@
+<?php
+namespace Gignite\TheCure\Models;
+
+use Gignite\TheCure\Mapper\Container;
+use Gignite\TheCure\Relationships\Relationship;
+use Gignite\TheCure\Relationships\Relation;
+
+/**
+ * [!!] This file is full of sin
+ */
+abstract class Magic extends Model {
+
+ public static function fields()
+ {
+ return array();
+ }
+
+ protected $__container;
+
+ public function __container(Container $container = NULL)
+ {
+ if ($container === NULL)
+ {
+ return $this->__container;
+ }
+
+ $this->__container = $container;
+ }
+
+ private function relation_action($fields, $method, array $args = NULL)
+ {
+ if (isset($fields[$method]) AND $args)
+ {
+ $verb = 'Set';
+ $key = $method;
+ }
+ else
+ {
+ $verb = current(explode('_', $method));
+ $key = substr($method, strlen($verb) + 1);
+ }
+
+ $interface = ucfirst($verb);
+ $interface = "Gignite\\TheCure\\Relation\\{$interface}";
+
+ if (interface_exists($interface)
+ AND isset($fields[$key])
+ AND $fields[$key] instanceOf $interface)
+ {
+ return array($fields[$key], $verb);
+ }
+ }
+
+ // private function add_relation($fields, $method)
+ // {
+ // if (strpos($method, 'add') === 0
+ // AND $field = Arr::get($fields, substr($method, 4))
+ // AND $field instanceOf Relation\Add)
+ // {
+ // return $field;
+ // }
+ // }
+
+ // private function remove_relation($fields, $method)
+ // {
+ // if (strpos($method, 'remove') === 0
+ // AND $field = Arr::get($fields, substr($method, 7))
+ // AND $field instanceOf Relation\Remove)
+ // {
+ // return $field;
+ // }
+ // }
+
+ // private function set_relation($fields, $method, array $args)
+ // {
+ // if ($field = Arr::get($fields, $method)
+ // AND $field instanceOf Relation\Set
+ // AND $args)
+ // {
+ // return $field;
+ // }
+ // }
+
+ public function __call($method, $args)
+ {
+ $fields = static::fields();
+ $object = $this->__object();
+
+ if (isset($fields[$method]) AND ! $args)
+ {
+ $field = $fields[$method];
+
+ if (isset($object->{$field->name()}))
+ {
+ $value = $object->{$field->name()};
+ }
+ else
+ {
+ $value = NULL;
+ }
+
+ if ($field instanceOf Relationship)
+ {
+ return $field->find($this->__container(), $value);
+ }
+ else
+ {
+ return $value;
+ }
+ }
+ elseif ($field_action = $this->relation_action($fields, $method, $args))
+ {
+ list($field, $action) = $field_action;
+ $field->{$action}($this->__container(), $object, $args[0]);
+ }
+ else
+ {
+ throw new \BadMethodCallException;
+ }
+ }
+
+}
View
4 classes/Model.php → classes/Gignite/TheCure/Models/Model.php
@@ -21,6 +21,8 @@
* @category Model
* @copyright Gignite, 2012
*/
+namespace Gignite\TheCure\Models;
+
abstract class Model {
protected $__object;
@@ -37,7 +39,7 @@ public function __object($object = NULL)
{
if ($this->__object === NULL)
{
- $this->__object = new StdClass;
+ $this->__object = new \StdClass;
}
return $this->__object;
View
10 classes/Gignite/TheCure/Relation/Add.php
@@ -0,0 +1,10 @@
+<?php
+namespace Gignite\TheCure\Relation;
+
+use Gignite\TheCure\Mapper\Container;
+
+interface Add {
+
+ public function add(Container $container, $object, $relation);
+
+}
View
4 classes/Gignite/TheCure/Relation/FieldNotFoundException.php
@@ -0,0 +1,4 @@
+<?php
+namespace Gignite\TheCure\Relation;
+
+class FieldNotFoundException extends \Exception {}
View
4 classes/Gignite/TheCure/Relation/NotFoundException.php
@@ -0,0 +1,4 @@
+<?php
+namespace Gignite\TheCure\Relation;
+
+class NotFoundException extends \Exception {}
View
10 classes/Gignite/TheCure/Relation/Remove.php
@@ -0,0 +1,10 @@
+<?php
+namespace Gignite\TheCure\Relation;
+
+use Gignite\TheCure\Mapper\Container;
+
+interface Remove {
+
+ public function remove(Container $container, $object, $relation);
+
+}
View
10 classes/Gignite/TheCure/Relation/Set.php
@@ -0,0 +1,10 @@
+<?php
+namespace Gignite\TheCure\Relation;
+
+use Gignite\TheCure\Mapper\Container;
+
+interface Set {
+
+ public function set(Container $container, $object, $relation);
+
+}
View
18 classes/Relationship/OneToMany.php → classes/Gignite/TheCure/Relationships/OneToMany.php
@@ -1,17 +1,19 @@
<?php
+namespace Gignite\TheCure\Relationships;
-class Relationship_OneToMany
- extends Relationship
- implements Relationship_Add, Relationship_Remove {
+use Gignite\TheCure\Mapper\Container;
+use Gignite\TheCure\Relation;
- public function find(MapperContainer $container, $ids)
+class OneToMany extends Relationship implements Relation\Add, Relation\Remove {
+
+ public function find(Container $container, $ids)
{
return $this->mapper($container)->find($this->model_suffix(), array(
'_id' => array('$in' => $ids),
));
}
- public function add(MapperContainer $container, $model, $relation)
+ public function add(Container $container, $model, $relation)
{
$relation_object = $relation->__object();
@@ -31,7 +33,7 @@ public function add(MapperContainer $container, $model, $relation)
$object->{$this->name()}[] = $relation->__object()->_id;
}
- public function remove(MapperContainer $container, $model, $relation)
+ public function remove(Container $container, $model, $relation)
{
$model_object = $model->__object();
@@ -48,10 +50,10 @@ public function remove(MapperContainer $container, $model, $relation)
}
}
- throw new RelationNotFoundException;
+ throw new Relation\NotFoundException;
}
- throw new RelationFieldNotFoundException;
+ throw new Relation\FieldNotFoundException;
}
}
View
16 classes/Relationship/OneToOne.php → classes/Gignite/TheCure/Relationships/OneToOne.php
@@ -1,15 +1,17 @@
<?php
+namespace Gignite\TheCure\Relationships;
-class Relationship_OneToOne
- extends Relationship
- implements Relationship_Set, Relationship_Remove {
+use Gignite\TheCure\Mapper\Container;
+use Gignite\TheCure\Relation;
- public function find(MapperContainer $container, $id)
+class OneToOne extends Relationship implements Relation\Set, Relation\Remove {
+
+ public function find(Container $container, $id)
{
return $this->mapper($container)->find_one($this->model_suffix(), $id);
}
- public function set(MapperContainer $container, $model, $relation)
+ public function set(Container $container, $model, $relation)
{
$relation_object = $relation->__object();
@@ -22,7 +24,7 @@ public function set(MapperContainer $container, $model, $relation)
$model->__object()->{$this->name()} = $relation->__object()->_id;
}
- public function remove(MapperContainer $container, $model, $relation)
+ public function remove(Container $container, $model, $relation)
{
$model_object = $model->__object();
@@ -32,7 +34,7 @@ public function remove(MapperContainer $container, $model, $relation)
return;
}
- throw new RelationFieldNotFoundException;
+ throw new Relation\FieldNotFoundException;
}
}
View
8 classes/Relationship.php → ...es/Gignite/TheCure/Relationships/Relationship.php
@@ -1,4 +1,8 @@
<?php
+namespace Gignite\TheCure\Relationships;
+
+use Gignite\TheCure\Field;
+use Gignite\TheCure\Mapper\Container;
abstract class Relationship extends Field {
@@ -43,11 +47,11 @@ protected function mapper_suffix()
return $this->mapper_suffix;
}
- protected function mapper(MapperContainer $container)
+ protected function mapper(Container $container)
{
return $container->mapper($this->mapper_suffix());
}
- abstract public function find(MapperContainer $container, $value);
+ abstract public function find(Container $container, $value);
}
View
97 classes/Model/Magic.php
@@ -1,97 +0,0 @@
-<?php
-/**
- * [!!] This file is full of sin
- */
-abstract class Model_Magic extends Model {
-
- public static function fields()
- {
- return array();
- }
-
- protected $__container;
-
- public function __container(MapperContainer $container = NULL)
- {
- if ($container === NULL)
- {
- return $this->__container;
- }
-
- $this->__container = $container;
- }
-
- private function add_relation($fields, $method)
- {
- if (strpos($method, 'add') === 0
- AND $field = Arr::get($fields, substr($method, 4))
- AND $field instanceOf Relationship_Add)
- {
- return $field;
- }
- }
-
- private function remove_relation($fields, $method)
- {
- if (strpos($method, 'remove') === 0
- AND $field = Arr::get($fields, substr($method, 7))
- AND $field instanceOf Relationship_Remove)
- {
- return $field;
- }
- }
-
- private function set_relation($fields, $method, array $args)
- {
- if ($field = Arr::get($fields, $method)
- AND $field instanceOf Relationship_Set
- AND $args)
- {
- return $field;
- }
- }
-
- public function __call($method, $args)
- {
- $fields = static::fields();
- $object = $this->__object();
-
- if ($field = $this->add_relation($fields, $method))
- {
- $field->add($this->__container(), $object, $args[0]);
- }
- elseif ($field = $this->remove_relation($fields, $method))
- {
- $field->remove($this->__container(), $object, $args[0]);
- }
- elseif ($field = $this->set_relation($fields, $method, $args))
- {
- $field->set($this->__container(), $object, $args[0]);
- }
- elseif ($field = Arr::get($fields, $method))
- {
- if (isset($object->{$field->name()}))
- {
- $value = $object->{$field->name()};
- }
- else
- {
- $value = NULL;
- }
-
- if ($field instanceOf Relationship)
- {
- return $field->find($this->__container(), $value);
- }
- else
- {
- return $value;
- }
- }
- else
- {
- throw new BadMethodCallException;
- }
- }
-
-}
View
3  classes/RelationFieldNotFoundException.php
@@ -1,3 +0,0 @@
-<?php
-
-class RelationFieldNotFoundException extends Exception {}
View
3  classes/RelationNotFoundException.php
@@ -1,3 +0,0 @@
-<?php
-
-class RelationNotFoundException extends Exception {}
View
7 classes/Relationship/Add.php
@@ -1,7 +0,0 @@
-<?php
-
-interface Relationship_Add {
-
- public function add(MapperContainer $container, $object, $relation);
-
-}
View
7 classes/Relationship/Remove.php
@@ -1,7 +0,0 @@
-<?php
-
-interface Relationship_Remove {
-
- public function remove(MapperContainer $container, $object, $relation);
-
-}
View
7 classes/Relationship/Set.php
@@ -1,7 +0,0 @@
-<?php
-
-interface Relationship_Set{
-
- public function set(MapperContainer $container, $object, $relation);
-
-}
View
38 phpunit.php
@@ -31,16 +31,28 @@
Kohana::modules(array('the-cure' => __DIR__.'/'));
+use Gignite\TheCure\Mapper\Container;
+use Gignite\TheCure\Mapper\ConnectionSetGet;
+use Gignite\TheCure\Connections\Connection;
+use Gignite\TheCure\Mappers\Mock as MockMapper;
+use Gignite\TheCure\Mappers\Mongo as MongoMapper;
+use Gignite\TheCure\Field;
+use Gignite\TheCure\Models\Model;
+use Gignite\TheCure\Models\Magic as MagicModel;
+use Gignite\TheCure\Relation;
+use Gignite\TheCure\Relationships\Relationship;
+use Gignite\TheCure\Relationships\OneToMany;
+
class Model_User extends Model {}
class Model_User_Admin extends Model_User {}
-class Model_User_Magic extends Model_Magic {
+class Model_User_Magic extends MagicModel {
public static function fields()
{
return parent::fields() + array(
'name' => new Field('name'),
- 'friends' => new Relationship_OneToMany('friends', array(
+ 'friends' => new OneToMany('friends', array(
'mapper_suffix' => 'User',
'model_suffix' => 'Magic',
)),
@@ -49,7 +61,7 @@ public static function fields()
}
-class Model_User_MockableRelation extends Model_Magic {
+class Model_User_MockableRelation extends MagicModel {
public static $relation;
@@ -60,11 +72,11 @@ public static function fields()
);
}
- public function __container(MapperContainer $container = NULL)
+ public function __container(Container $container = NULL)
{
if ($this->__container === NULL)
{
- parent::__container(new MapperContainer('Array'));
+ parent::__container(new Container('Array'));
}
return parent::__container();
@@ -73,7 +85,7 @@ public function __container(MapperContainer $container = NULL)
}
class Relationship_Mock extends Relationship
- implements Relationship_Add, Relationship_Remove, Relationship_Set {
+ implements Relation\Add, Relation\Remove, Relation\Set {
protected $method_called;
@@ -82,32 +94,32 @@ public function method_called()
return $this->method_called;
}
- public function find(MapperContainer $container, $value)
+ public function find(Container $container, $value)
{
$this->method_called = 'find';
}
- public function add(MapperContainer $container, $object, $relation)
+ public function add(Container $container, $object, $relation)
{
$this->method_called = 'add';
}
- public function remove(MapperContainer $container, $object, $relation)
+ public function remove(Container $container, $object, $relation)
{
$this->method_called = 'remove';
}
- public function set(MapperContainer $container, $object, $relation)
+ public function set(Container $container, $object, $relation)
{
$this->method_called = 'set';
}
}
-class Mapper_Mongo_User extends Mapper_Mongo {}
-class Mapper_Array_User extends Mapper_Array {}
+class Mapper_Mongo_User extends MongoMapper {}
+class Mapper_Array_User extends MockMapper {}
-class Mapper_ConnectionTest_User implements MapperConnection {
+class Mapper_ConnectionTest_User implements ConnectionSetGet {
protected $connection;
View
5 test/CollectionIterableTest.php
@@ -10,11 +10,14 @@
* @copyright Luke Morton, 2011
* @license MIT
*/
+use Gignite\TheCure\Collections\Collection;
+use Gignite\TheCure\Collections\Iterable as IterableCollection;
+
class CollectionIterableTest extends CollectionTest {
public function testConstruct()
{
- return new Collection_Iterable(
+ return new IterableCollection(
new Collection(array(
array('id' => 1),
array('id' => 2),
View
5 test/CollectionModelTest.php
@@ -11,11 +11,14 @@
* @copyright Luke Morton, 2011
* @license MIT
*/
+use Gignite\TheCure\IdentityMap;
+use Gignite\TheCure\Collections\Model as ModelCollection;
+
class CollectionModelTest extends CollectionTest {
public function testConstruct()
{
- return new Collection_Model(
+ return new ModelCollection(
new ArrayIterator(array(
(object) array('_id' => 0),
(object) array('_id' => 1),
View
2  test/CollectionTest.php
@@ -10,6 +10,8 @@
* @copyright Luke Morton, 2011
* @license MIT
*/
+use Gignite\TheCure\Collections\Collection;
+
class CollectionTest extends PHPUnit_Framework_TestCase {
public function testConstruct()
View
2  test/IdentityMapTest.php
@@ -10,6 +10,8 @@
* @copyright Luke Morton, 2011
* @license MIT
*/
+use Gignite\TheCure\IdentityMap;
+
class IdentityMapTest extends PHPUnit_Framework_TestCase {
protected $domain;
View
2  test/MapperArrayTest.php
@@ -10,6 +10,8 @@
* @copyright Luke Morton, 2011
* @license MIT
*/
+use Gignite\TheCure\IdentityMap;
+
class MapperArrayTest extends MapperTest {
protected static $mapper;
View
7 test/MapperContainerTest.php
@@ -1,10 +1,11 @@
<?php
+use Gignite\TheCure\Mapper\Container;
class MapperContainerTest extends PHPUnit_Framework_TestCase {
public function testMapper()
{
- $container = new MapperContainer('Array');
+ $container = new Container('Array');
$this->assertInstanceOf(
'Mapper_Array_User',
$container->mapper('User'));
@@ -12,7 +13,7 @@ public function testMapper()
public function testMapperConnection()
{
- $container = new MapperContainer('ConnectionTest');
+ $container = new Container('ConnectionTest');
$this->assertInstanceOf(
'Mapper_ConnectionTest_User',
$container->mapper('User'));
@@ -20,7 +21,7 @@ public function testMapperConnection()
public function testItShouldSetAndGetConfig()
{
- $container = new MapperContainer('Array');
+ $container = new Container('Array');
$expectedConfig = array();
$container->config($expectedConfig);
$this->assertSame($expectedConfig, $container->config());
View
5 test/MapperMongoTest.php
@@ -10,6 +10,9 @@
* @copyright Luke Morton, 2011
* @license MIT
*/
+use Gignite\TheCure\IdentityMap;
+use Gignite\TheCure\Connections\Mongo as MongoConnection;
+
class MapperMongoTest extends MapperTest {
protected static $mapper;
@@ -52,7 +55,7 @@ protected static function mapper()
if (static::$mapper === NULL)
{
$mapper = new Mapper_Mongo_User;
- $mapper->connection(new Connection_Mongo(static::config()));
+ $mapper->connection(new MongoConnection(static::config()));
$mapper->identities(new IdentityMap);
$mapper->config(array('query_options' => array('safe' => TRUE)));
static::$mapper = $mapper;
View
3  test/ModelMagicTest.php
@@ -1,4 +1,5 @@
<?php
+use Gignite\TheCure\Mapper\Container;
class ModelMagicTest extends PHPUnit_Framework_TestCase {
@@ -8,7 +9,7 @@ protected function container()
{
if ($this->container === NULL)
{
- $container = new MapperContainer('Array');
+ $container = new Container('Array');
$jim = new Model_User_Magic;
$jim->__container($container);
View
14 test/RelationshipOneToManyTest.php
@@ -1,4 +1,6 @@
<?php
+use Gignite\TheCure\Mapper\Container;
+use Gignite\TheCure\Relationships\OneToMany;
class RelationshipOneToManyTest extends PHPUnit_Framework_TestCase {
@@ -8,12 +10,12 @@ protected function relationship()
'mapper_suffix' => 'User',
'model_suffix' => 'Admin',
);
- return new Relationship_OneToMany('friends', $config);
+ return new OneToMany('friends', $config);
}
protected function container()
{
- return new MapperContainer('Array');
+ return new Container('Array');
}
public function testItShouldFindACollectionOfRelatedModels()
@@ -21,7 +23,9 @@ public function testItShouldFindACollectionOfRelatedModels()
$container = $this->container();
$container->mapper('User')->save(new Model_User_Admin);
$collection = $this->relationship()->find($container, array(0, 1));
- $this->assertInstanceOf('Collection', $collection);
+ $this->assertInstanceOf(
+ 'Gignite\TheCure\Collections\Collection',
+ $collection);
}
public function testItShouldSaveAnRelatedObjectWhenAddingRelation()
@@ -72,7 +76,7 @@ public function testItShouldRemoveAnObjectIDFromAnotherObjectsArray($args)
}
/**
- * @expectedException RelationFieldNotFoundException
+ * @expectedException Gignite\TheCure\Relation\FieldNotFoundException
*/
public function testItShouldThrowExceptionWhenRelationArrayNotExists()
{
@@ -83,7 +87,7 @@ public function testItShouldThrowExceptionWhenRelationArrayNotExists()
}
/**
- * @expectedException RelationNotFoundException
+ * @expectedException Gignite\TheCure\Relation\NotFoundException
*/
public function testItShouldThrowExceptionWhenRelatedObjectIDNotInArray()
{
View
8 test/RelationshipOneToOneTest.php
@@ -1,4 +1,6 @@
<?php
+use Gignite\TheCure\Mapper\Container;
+use Gignite\TheCure\Relationships\OneToOne;
class RelationshipOneToOnelTest extends PHPUnit_Framework_TestCase {
@@ -8,12 +10,12 @@ protected function relationship()
'mapper_suffix' => 'User',
'model_suffix' => 'Admin',
);
- return new Relationship_OneToOne('best_friend', $config);
+ return new OneToOne('best_friend', $config);
}
protected function container()
{
- return new MapperContainer('Array');
+ return new Container('Array');
}
public function testItShouldFindARelatedModel()
@@ -73,7 +75,7 @@ public function testItShouldRemoveRelationOnObject($args)
}
/**
- * @expectedException RelationFieldNotFoundException
+ * @expectedException Gignite\TheCure\Relation\FieldNotFoundException
*/
public function testItShouldThrowExceptionWhenRelationFieldNotExists()
{
Please sign in to comment.
Something went wrong with that request. Please try again.