Example #1
0
 public function setUp()
 {
     $this->deps = Test\Factory::managerArraysModelCustom(['Test' => ['class' => 'stdClass', 'fields' => ['id' => ['primary' => true], 'linkedId' => ['index' => true]], 'relations' => ['link' => ['one', 'of' => 'Test', 'from' => 'linkedId', 'mode' => 'auto']]]]);
     $this->deps->manager->insertTable('Test', ['id' => 1, 'linkedId' => 2]);
     $this->deps->manager->insertTable('Test', ['id' => 2, 'linkedId' => 2]);
     $this->deps->manager->connector->queries = 0;
 }
Example #2
0
 function setUp()
 {
     $this->deps = $deps = Test\Factory::managerArraysModelCustom(['Pants' => ['table' => 'yep', 'class' => 'stdClass', 'fields' => ['foo' => true, 'bar' => true, 'baz' => true]]]);
     $deps->manager->insertTable('Pants', ['foo' => 'abc', 'bar' => '123', 'baz' => '!!!']);
     $deps->manager->insertTable('Pants', ['foo' => 'bcd', 'bar' => '234', 'baz' => '@@@']);
     $deps->manager->insertTable('Pants', ['foo' => 'cde', 'bar' => '345', 'baz' => '###']);
 }
Example #3
0
 public function testObjectToProperties()
 {
     $deps = Test\Factory::managerArraysModelCustom(['Pants' => ['class' => 'stdClass', 'fields' => ['id' => ['name' => 'i_d'], 'yep' => ['name' => 'y_e_p'], 'otre' => ['name' => 'o_t_r_e']]]]);
     $array = ['id' => 1, 'yep' => 'hello', 'otre' => (object) ['hello' => 'world']];
     $object = (object) $array;
     $meta = $deps->mapper->getMeta('Pants');
     $props = $deps->mapper->mapObjectToProperties($object, $meta);
     $this->assertEquals($array, $props);
 }
 function setUp()
 {
     $map = ['Pants' => ['class' => 'stdClass', 'table' => 'pants', 'fields' => ['id' => ['primary' => true, 'type' => 'autoinc']], 'relations' => ['other' => ['one', 'of' => 'Other']]], 'Other' => ['class' => 'stdClass', 'table' => 'other', 'fields' => ['id' => ['primary' => true, 'type' => 'autoinc']]]];
     $map['Trou'] = $map['Pants'];
     $map['Trou']['table'] = 'trou';
     unset($map['Trou']['relations']);
     $this->deps = Test\Factory::managerArraysModelCustom($map);
     $manager = $this->deps->manager;
     $manager->insertTable('Other', ['id' => 1]);
     $manager->insertTable('Trou', ['id' => 1]);
 }
Example #5
0
 function setUp()
 {
     parent::setUp();
     $mappings = ['foo' => ['table' => 'foo', 'class' => 'stdClass', 'fields' => ['fooId' => true, 'foo' => true]], 'bar' => ['table' => 'bar', 'class' => 'stdClass', 'fields' => ['barId' => true, 'fooId' => true, 'bar' => true]]];
     $this->deps = Factory::managerArraysModelCustom($mappings);
     $this->deps->mapper->mappings['baz'] = ['table' => 'baz', 'class' => 'stdClass', 'fields' => ['fooId' => true, 'barId' => true, 'foo' => true, 'bar' => true]];
     $this->deps->connector->query("\n            CREATE VIEW baz AS\n                SELECT bar.fooId, bar.barId, foo.foo, bar.bar FROM bar\n                INNER JOIN foo ON foo.fooId = bar.fooId\n        ");
     $this->deps->manager->insertTable('foo', ['fooId' => 1, 'foo' => 'a']);
     $this->deps->manager->insertTable('foo', ['fooId' => 2, 'foo' => 'b']);
     $this->deps->manager->insertTable('bar', ['fooId' => 1, 'barId' => 1, 'bar' => 'a']);
     $this->deps->manager->insertTable('bar', ['fooId' => 1, 'barId' => 2, 'bar' => 'b']);
 }
Example #6
0
 public function setUp()
 {
     parent::setUp();
     $this->deps = Test\Factory::managerArraysModelCustom(['Parent' => ['class' => 'stdClass', 'table' => 't1', 'fields' => ['id' => ['primary' => true], 'orderedId' => ['index' => true]], 'relations' => ['ordered' => ['one', 'of' => 'Ordered', 'from' => 'orderedId']]], 'Ordered' => ['class' => 'stdClass', 'table' => 't2', 'primary' => 'id', 'fields' => ['id' => true, 'yep' => true, 'sort' => true], 'defaultOrder' => 'sort']]);
     $this->manager = $this->deps->manager;
     $this->manager->insertTable('Ordered', ['id' => 1, 'yep' => 2, 'sort' => 3]);
     $this->manager->insertTable('Ordered', ['id' => 2, 'yep' => 2, 'sort' => 2]);
     $this->manager->insertTable('Ordered', ['id' => 3, 'yep' => 2, 'sort' => 1]);
     $this->manager->insertTable('Parent', ['id' => 1, 'orderedId' => 2]);
     $this->manager->insertTable('Parent', ['id' => 2, 'orderedId' => 1]);
     $this->manager->insertTable('Parent', ['id' => 3, 'orderedId' => 3]);
 }
Example #7
0
 protected static function managerNestedSetArrays($map)
 {
     $deps = Test\Factory::managerArraysModelCustom($map);
     $deps->nsManager = \Amiss\Ext\NestedSet\Manager::createWithDefaults($deps->manager);
     return $deps;
 }
 function testCreate()
 {
     $d = Test\Factory::managerArraysModelCustom(['Pants' => ['table' => 'ORDER BY', 'class' => 'stdClass', 'fields' => ['foo' => true]]]);
     return $d;
 }
Example #9
0
 /**
  * @group acceptance
  * @group manager 
  * @group getById
  */
 public function testGetByIdMultiNamed()
 {
     $d = Test\Factory::managerArraysModelCustom(['Pants' => ['class' => 'stdClass', 'primary' => ['foo', 'bar'], 'fields' => ['foo' => true, 'bar' => true]]]);
     $d->manager->insertTable('Pants', ['foo' => 2, 'bar' => 1]);
     $result = $d->manager->getById('Pants', ['bar' => 1, 'foo' => 2]);
     $this->assertEquals(2, $result->foo);
     $this->assertEquals(1, $result->bar);
 }
Example #10
0
 /**
  * Select using an array where clause, but using values that get mapped through
  * a type handler.
  */
 public function testListByTypePropertyIn()
 {
     $deps = Test\Factory::managerArraysModelCustom(['Pants' => ['class' => 'stdClass', 'table' => 't1', 'primary' => 'id', 'fields' => ['id' => ['type' => 'autoinc'], 'd' => ['type' => 'date']]]]);
     $d1 = new \DateTime('2015-01-01', new \DateTimeZone('UTC'));
     $d2 = new \DateTime('2015-01-02', new \DateTimeZone('UTC'));
     $deps->manager->insertTable('Pants', ['d' => $d1]);
     $deps->manager->insertTable('Pants', ['d' => $d2]);
     $deps->manager->insertTable('Pants', ['d' => new \DateTime('2015-01-03', new \DateTimeZone('UTC'))]);
     $result = $deps->manager->getList('Pants', ['where' => ['d' => [$d1, $d2]]]);
     $this->assertEquals($d1, $result[0]->d);
     $this->assertEquals($d2, $result[1]->d);
 }