Example #1
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 #2
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 #3
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 #4
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);
 }