public function testCustomType()
 {
     $mapper = \Amiss\Sql\Factory::createMapper();
     $mapper->addTypeHandler(new TestCustomFieldTypeHandler(), 'foo');
     $deps = \Amiss\Test\Factory::managerNoteModelCustom('
         /** :amiss = true; */
         class TestCustomFieldTypeModel
         {
             /** :amiss = {"field": {"primary": true, "type": "autoinc" }}; */
             public $testCustomFieldTypeRecordId;
             
             /**
              * :amiss = {"field": {"type": "foo bar"}};
              */
             public $yep1;
         }
     ', (object) ['mapper' => $mapper]);
     $class = $deps->classes['TestCustomFieldTypeModel'];
     $r = new $class();
     $r->yep1 = 'foo';
     $deps->manager->save($r);
     $r = $deps->manager->getById($class, 1);
     // this will have passed through the prepareValueForDb first, then
     // through the handleValueFromDb method
     $this->assertEquals('value-db-foo', $r->yep1);
 }
 public function setUp()
 {
     parent::setUp();
     $this->connector = new \Amiss\Test\Helper\TestConnector('mysql:xx');
     $this->mapper = \Amiss\Sql\Factory::createMapper();
     $this->manager = new \Amiss\Sql\Manager($this->connector, $this->mapper);
     $this->class = __NAMESPACE__ . '\\TestCreateWithCustomType';
 }
Example #3
0
 public static function managerArraysModelCustom($map)
 {
     $mapper = new \Amiss\Mapper\Arrays($map);
     $config = ['date' => ['dbTimeZone' => 'UTC', 'appTimeZone' => 'UTC']];
     $deps = (object) ['mapper' => $mapper];
     $mapper->typeHandlers = \Amiss\Sql\Factory::createTypeHandlers($config);
     $deps = self::managerNoteDefault($deps);
     TableBuilder::create($deps->connector, $mapper, array_keys($map));
     return $deps;
 }
 public function setUp()
 {
     parent::setUp();
     \Amiss\Sql\ActiveRecord::_reset();
     $this->connector = new \Amiss\Test\Helper\TestConnector('mysql:xx');
     $this->mapper = \Amiss\Sql\Factory::createMapper(array());
     $this->manager = new \Amiss\Sql\Manager($this->connector, $this->mapper);
     \Amiss\Sql\ActiveRecord::setManager($this->manager);
     $this->class = __NAMESPACE__ . '\\TestCreateCustomTypeWithEmptyColumnTypeRecord';
 }
Example #5
0
 public function setUp()
 {
     parent::setUp();
     $this->connector = new \PDOK\Connector('sqlite::memory:');
     $this->connector->exec("ATTACH DATABASE ':memory:' AS schema_one;");
     $this->connector->exec("ATTACH DATABASE ':memory:' AS schema_two;");
     $this->connector->exec("CREATE TABLE schema_one.table_one(id INTEGER PRIMARY KEY AUTOINCREMENT, oneName STRING, twoId INTEGER)");
     $this->connector->exec("CREATE TABLE schema_two.table_two(id INTEGER PRIMARY KEY AUTOINCREMENT, twoName STRING)");
     $this->manager = \Amiss\Sql\Factory::createManager($this->connector);
     $this->mapper = $this->manager->mapper;
 }
Example #6
0
 function setUp()
 {
     $this->db = new \PDOK\Connector('sqlite::memory:');
     $this->db->exec("CREATE TABLE child(id INTEGER, parentId INTEGER)");
     $this->db->exec("CREATE TABLE parent(id INTEGER)");
     $this->db->exec("INSERT INTO child VALUES(1, 1)");
     $this->db->exec("INSERT INTO child VALUES(2, 1)");
     $this->db->exec("INSERT INTO parent VALUES(1)");
     $this->mapper = new \Amiss\Mapper\Note();
     $this->manager = new \Amiss\Sql\Manager($this->db, $this->mapper);
     $this->manager->relators = \Amiss\Sql\Factory::createRelators();
 }
Example #7
0
 public function setUp()
 {
     $this->db = new \PDOK\Connector('sqlite::memory:');
     $this->mapper = $this->createDefaultMapper();
     $this->manager = new \Amiss\Sql\Manager($this->db, $this->mapper);
     $this->manager->relators = \Amiss\Sql\Factory::createRelators();
     foreach ([Demo\Artist::class, Demo\ArtistType::class] as $c) {
         TableBuilder::create($this->manager->connector, $this->mapper, $c);
     }
     $this->manager->connector->exec("INSERT INTO artist (artistId, artistTypeId) VALUES(1, 1)");
     $this->manager->connector->exec("INSERT INTO artist (artistId, artistTypeId) VALUES(2, 1)");
     $this->manager->connector->exec("INSERT INTO artist_type (artistTypeId) VALUES(1)");
 }
Example #8
0
 public function setUp()
 {
     $this->db = new \PDOK\Connector('sqlite::memory:');
     $this->mapper = $this->createDefaultMapper();
     $this->manager = new \Amiss\Sql\Manager($this->db, $this->mapper);
     $this->manager->relators = \Amiss\Sql\Factory::createRelators();
     foreach ($this->mapper->mappings as $class => $meta) {
         TableBuilder::create($this->manager->connector, $this->mapper, $class);
     }
     $this->manager->connector->exec("INSERT INTO test_child(id, parentId) VALUES(1, 1)");
     $this->manager->connector->exec("INSERT INTO test_child(id, parentId) VALUES(2, 1)");
     $this->manager->connector->exec("INSERT INTO test_parent(id, grandParentId) VALUES(1, 1)");
     $this->manager->connector->exec("INSERT INTO test_grand_parent(id) VALUES(1)");
     $this->db->queries = 0;
 }
Example #9
0
 /**
  * @covers Amiss\Sql\ActiveRecord::__callStatic
  */
 public function testAssignRelatedStaticArray()
 {
     $manager = $this->getMock('Amiss\\Sql\\Manager', array('getRelated'), array($this->deps->connector, $this->deps->mapper));
     $manager->relators = \Amiss\Sql\Factory::createRelators();
     \Amiss\Sql\ActiveRecord::setManager($manager);
     $child1 = new TestRelatedChild();
     $child1->childId = 6;
     $child1->parentId = 1;
     $child2 = new TestRelatedChild();
     $child2->childId = 7;
     $child2->parentId = 2;
     $input = [$child1, $child2];
     $manager->expects($this->once())->method('getRelated')->with($this->equalTo($input), $this->equalTo('parent'))->will($this->returnValue([999, 777]));
     TestRelatedChild::assignRelated($input, 'parent');
     $this->assertEquals(999, $child1->parent);
     $this->assertEquals(777, $child2->parent);
 }