示例#1
0
 public function setUp()
 {
     parent::setUp();
     $this->deps = Test\Factory::managerNoteDefault();
     $this->manager = $this->deps->manager;
     TableBuilder::create($this->deps->connector, $this->deps->mapper, [MappedFieldNameLeft::class, MappedFieldNameAssoc::class, MappedFieldNameRight::class]);
 }
 /**
  * @covers Amiss\Sql\TableBuilder::buildFields
  * @group tablebuilder
  */
 public function testCreateTableWithCustomTypeUsesTypeHandler()
 {
     $this->mapper->addTypeHandler(new TestCreateWithCustomTypeTypeHandler(), 'slappywag');
     $pattern = "\n            CREATE TABLE `bar` (\n                `testCreateId` INTEGER NOT NULL AUTO_INCREMENT,\n                `foo1` OH YEAH,\n                `foo2` OH YEAH,\n                `pants` int unsigned not null,\n                PRIMARY KEY (`testCreateId`)\n            ) ENGINE=InnoDB;\n        ";
     $last = TableBuilder::createSQL($this->connector, $this->mapper, $this->class);
     $this->assertLoose($pattern, $last[0]);
 }
 /**
  * @covers Amiss\Sql\TableBuilder::buildFields
  * @group tablebuilder
  */
 public function testCreateTableWithCustomTypeUsesTypeHandler()
 {
     $this->mapper->addTypeHandler(new RecordCreateCustomTypeWithEmptyColumnTypeHandler(), 'int');
     $pattern = "\n            CREATE TABLE `bar` (\n                `id` INTEGER NOT NULL AUTO_INCREMENT,\n                `foo1` int,\n                PRIMARY KEY (`id`)\n            ) ENGINE=InnoDB;\n        ";
     $last = TableBuilder::createSQL($this->connector, $this->mapper, $this->class);
     $this->assertLoose($pattern, $last[0]);
 }
示例#4
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;
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->manager = $this->getContainer()->get(sprintf('amiss.manager.%s', $input->getOption('manager')));
     $directory = $input->hasArgument('directory') ? $input->getArgument('directory') : $this->getContainer()->get('kernel')->getRootDir() . "/../src";
     $classes = $this->getClassesInDir($directory);
     $count = 0;
     $output->writeln("Creating table(s) for:");
     foreach ($classes as $class) {
         try {
             $tableBuilder = new TableBuilder($this->manager, $class);
             $tableBuilder->createTable();
             $output->writeln(sprintf("  - <comment>%s</comment> <info>OK</info>", $class));
             $count++;
         } catch (PDOException $e) {
             $output->writeln(sprintf("  - <comment>%s</comment> <fg=red>KO</> (%s)", $class, $e->getMessage()));
         } catch (Exception $e) {
             $output->writeln(sprintf("  - <comment>%s</comment> N/A (unmapped class)", $class));
             // No way to know if it's a database error or just an unmapped class
         }
     }
     $output->writeln(sprintf("Created <info>%d</info> table%s successfully", $count, $count > 1 ? "s" : ""));
 }
示例#6
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)");
 }
示例#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 ($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;
 }
 public function setUp()
 {
     $this->deps = Test\Factory::managerNoteDefault();
     $this->manager = $this->deps->manager;
     $this->ns = 'Amiss\\Demo\\AssocDifferentFieldColumn';
     $tb = TableBuilder::create($this->manager->connector, $this->manager->mapper, [$this->ns . '\\Event', $this->ns . '\\Artist', $this->ns . '\\EventArtist']);
     $manager = $this->manager;
     $manager->insertTable($this->ns . '\\Event', ['id' => 1, 'name' => 'event1']);
     $manager->insertTable($this->ns . '\\Event', ['id' => 2, 'name' => 'event2']);
     $manager->insertTable($this->ns . '\\Event', ['id' => 3, 'name' => 'event3']);
     $manager->insertTable($this->ns . '\\Artist', ['id' => 1, 'name' => 'artist1']);
     $manager->insertTable($this->ns . '\\Artist', ['id' => 2, 'name' => 'artist2']);
     $manager->insertTable($this->ns . '\\Artist', ['id' => 3, 'name' => 'artist3']);
     $manager->insertTable($this->ns . '\\EventArtist', ['eventId' => 1, 'artistId' => 1]);
     $manager->insertTable($this->ns . '\\EventArtist', ['eventId' => 1, 'artistId' => 2]);
     $manager->insertTable($this->ns . '\\EventArtist', ['eventId' => 2, 'artistId' => 2]);
     $manager->insertTable($this->ns . '\\EventArtist', ['eventId' => 2, 'artistId' => 3]);
 }
示例#9
0
 public function testCreateTable()
 {
     $deps = Test\Factory::managerNoteDefault();
     $deps->mapper->addTypeHandler(new \Amiss\Sql\Type\Autoinc(), 'autoinc');
     $deps->mapper->defaultTableNameTranslator = function ($name) {
         return 'test_' . $name;
     };
     try {
         \Amiss\Demo\Active\DemoRecord::_reset();
         \Amiss\Demo\Active\DemoRecord::setManager($deps->manager);
         TableBuilder::create($deps->connector, $deps->mapper, Demo\Active\EventRecord::class);
         $er = new Demo\Active\EventRecord();
         $er->name = 'foo bar';
         $er->slug = 'foobar';
         $er->save();
         $this->assertTrue(true);
     } finally {
         \Amiss\Demo\Active\DemoRecord::_reset();
     }
 }
示例#10
0
 /**
  * @group tablebuilder
  */
 public function testCreateTableFailsWhenConnectorIsNotPDOKConnector()
 {
     $this->deps->connector = new \PDO('sqlite::memory:');
     if (version_compare(PHP_VERSION, "7.0.0-dev") >= 0) {
         $this->setExpectedException('TypeError');
     } else {
         $this->setExpectedException('PHPUnit_Framework_Error');
     }
     TableBuilder::create($this->deps->connector, $this->deps->mapper, __NAMESPACE__ . '\\TestNoFieldsCreate');
 }