Exemplo n.º 1
0
 public function setUp()
 {
     try {
         $this->db = ezcDbInstance::get();
         if ($this->db === false) {
             $this->markTestSkipped("You must provide a database to runtests.php.");
         }
         $tables = array(self::$table => new ezcDbSchemaTable(array(self::$fieldId => new ezcDbSchemaField('integer', false, true, null, true), self::$fieldUser => new ezcDbSchemaField('text', 32, true), self::$fieldPassword => new ezcDbSchemaField('text', 64, true), self::$fieldName => new ezcDbSchemaField('text', 64, true), self::$fieldCountry => new ezcDbSchemaField('text', 32, true)), array(self::$fieldUser => new ezcDbSchemaIndex(array(self::$fieldUser => new ezcDbSchemaIndexField()), false, false))));
         $schema = new ezcDbSchema($tables);
         $schema->writeToDb($this->db);
     } catch (Exception $e) {
         // Oracle seems to skip every other test if the next line is enabled
         // $this->markTestSkipped( "Cannot create test table '" . self::$table . "'. " . $e->getMessage() );
     }
     if (!isset($this->db)) {
         $this->markTestSkipped("You must provide a database to runtests.php. Run runtests.php --help to see how to specify a database.");
     }
     try {
         $query = new ezcQueryInsert($this->db);
         $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('1'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('jan.modaal'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(sha1('qwerty')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Jan Modaal'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('NL'));
         $stmt = $query->prepare();
         $stmt->execute();
         $query = new ezcQueryInsert($this->db);
         $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('2'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('john.doe'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(crypt('foobar', 'jo')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('John Doe'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('US'));
         $stmt = $query->prepare();
         $stmt->execute();
         $query = new ezcQueryInsert($this->db);
         $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('3'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('zhang.san'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue(md5('asdfgh')))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Zhang San'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('CN'));
         $stmt = $query->prepare();
         $stmt->execute();
         $query = new ezcQueryInsert($this->db);
         $query->insertInto($this->db->quoteIdentifier(self::$table))->set($this->db->quoteIdentifier(self::$fieldId), $query->bindValue('4'))->set($this->db->quoteIdentifier(self::$fieldUser), $query->bindValue('hans.mustermann'))->set($this->db->quoteIdentifier(self::$fieldPassword), $query->bindValue('abcdef'))->set($this->db->quoteIdentifier(self::$fieldName), $query->bindValue('Hans Mustermann'))->set($this->db->quoteIdentifier(self::$fieldCountry), $query->bindValue('DE'));
         $stmt = $query->prepare();
         $stmt->execute();
     } catch (Exception $e) {
         $this->markTestSkipped("Cannot insert test values into table '" . self::$table . "'. " . $e->getMessage());
     }
 }
Exemplo n.º 2
0
 public function testAddingAutoIncrementField()
 {
     $dbh = $this->db;
     $schema1 = new ezcDbSchema(array('table10801' => new ezcDbSchemaTable(array('id' => ezcDbSchemaField::__set_state(array('type' => 'integer', 'length' => false, 'notNull' => false, 'default' => 0, 'autoIncrement' => false, 'unsigned' => false)), 'text' => new ezcDbSchemaField('text')))));
     $schema2 = new ezcDbSchema(array('table10801' => new ezcDbSchemaTable(array('id' => ezcDbSchemaField::__set_state(array('type' => 'integer', 'length' => false, 'notNull' => true, 'default' => null, 'autoIncrement' => true, 'unsigned' => false)), 'text' => new ezcDbSchemaField('text')))));
     $schema1->writeToDb($dbh);
     $diff = ezcDbSchemaComparator::compareSchemas($schema1, $schema2);
     $diff->applyToDb($dbh);
     $q = $dbh->createInsertQuery();
     $stmt = $q->insertInto($dbh->quoteIdentifier('table10801'))->set($dbh->quoteIdentifier('text'), $q->bindValue('text'))->prepare();
     $stmt->execute();
     $q = $dbh->createSelectQuery();
     $stmt = $q->select('*')->from($dbh->quoteIdentifier('table10801'))->prepare();
     $stmt->execute();
     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $this->assertEquals(1, $result[0]['id']);
 }
Exemplo n.º 3
0
 public function testWriteWithUnsupportedType()
 {
     $tables = array('prefix_bugdb_comments' => new ezcDbSchemaTable(array('email' => new ezcDbSchemaField('slartibartfast', 32)), array()));
     $schema = new ezcDbSchema($tables);
     try {
         $schema->writeToDb($this->db);
         self::fail("Expected exception is not thrown.");
     } catch (ezcDbSchemaUnsupportedTypeException $e) {
         self::assertRegexp("@The field type 'slartibartfast' is not supported with the '(.*)' handler.@", $e->getMessage());
     }
 }