public function testEntityRegistration() { $analogue = get_analogue(); $this->assertFalse($analogue->isRegisteredEntity('AnalogueTest\\App\\Register')); $analogue->register('AnalogueTest\\App\\Register'); $this->assertTrue($analogue->isRegisteredEntity('AnalogueTest\\App\\Register')); $this->setExpectedException('Analogue\\ORM\\Exceptions\\MappingException'); $analogue->register('AnalogueTest\\App\\Register'); $this->setExpectedException('Analogue\\ORM\\Exceptions\\MappingException'); $analogue->register('AnalogueTest\\App\\NonExisting'); }
public function testRepositoryInstantiation() { $analogue = get_analogue(); $entity = new Entity(); $repo = new Repository($analogue->mapper($entity)); $this->assertInstanceOf('Analogue\\ORM\\Repository', $repo); $repo = new Repository($entity); $this->assertInstanceOf('Analogue\\ORM\\Repository', $repo); $repo = new Repository(get_class($entity)); $this->assertInstanceOf('Analogue\\ORM\\Repository', $repo); }
public function testCollectionDictionaryReturnsEntityKeys() { get_analogue(); $entity1 = new Entity(); $entity1->id = 1; $entity2 = new Entity(); $entity2->id = 2; $entity3 = new Entity(); $entity3->id = 3; $c = new Collection(array($entity1, $entity2, $entity3)); $this->assertEquals(array(1, 2, 3), $c->getEntityKeys()); }
public function testGetMapperWithStrings() { $analogue = get_analogue(); $permissionMapper = $analogue->mapper('AnalogueTest\\App\\Permission', 'AnalogueTest\\App\\PermissionMap'); $this->assertInstanceOf('Analogue\\ORM\\System\\Mapper', $permissionMapper); }
public function testStoreAndLoadPolymorphicManyRelations() { $analogue = get_analogue(); $resource = new Resource('Poly'); $u1 = new User('u1', new Role('r1')); $u2 = new User('u2', new Role('r2')); $resource->users = new EntityCollection([$u1, $u2]); $image1 = new Image('i1'); $image2 = new Image('i2'); $resource->images = new EntityCollection([$image1, $image2]); $analogue->mapper($resource)->store($resource); $this->assertGreaterThan(0, $resource->custom_id); $resourceMapper = get_mapper($resource); $id = $resource->custom_id; $res = $resourceMapper->query()->with(['users', 'images'])->find($id); }
function get_mapper($entity) { return get_analogue()->mapper($entity); }