public function testTransactionRollbackOnError()
 {
     $this->connection->execute('DROP TABLE IF EXISTS test');
     $this->connection->execute('CREATE TABLE test (id INT(10) PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255)) ENGINE=InnoDB');
     $this->connection->start();
     $this->connection->execute("INSERT INTO test VALUES (1, 'Mike')");
     $this->connection->execute("INSERT INTO test VALUES (2, 'John')");
     $this->connection->execute("INSERT INTO test VALUES (3, 'Bill')");
     try {
         $this->connection->execute('NO SQL SYNTAX');
     } catch (QueryException $e) {
     }
     $r = $this->connection->execute('SELECT COUNT(id) FROM test')->fetchResult();
     $this->assertEquals('0', $r);
     $this->connection->execute('DROP TABLE IF EXISTS test');
 }
Exemple #2
0
 protected function setUp()
 {
     /** @var $cache CacheInterface */
     $cache = $this->getMock('\\Grace\\Cache\\CacheInterface');
     $this->connection = new Connection(TEST_MYSQLI_HOST, TEST_MYSQLI_PORT, TEST_MYSQLI_NAME, TEST_MYSQLI_PASSWORD, TEST_MYSQLI_DATABASE);
     $typeConverter = new TypeConverter();
     $this->orm = new Grace($this->connection, new ClassNameProvider('Grace\\Tests\\ORM\\Plug'), new ModelObserver(), $typeConverter, (new Loader(__DIR__ . '/Resources/models', $typeConverter))->getConfig(), $cache);
     $this->finder = $this->orm->getFinder('TaxiPassenger');
     $this->connection->execute('DROP TABLE IF EXISTS "TaxiPassenger"');
     $this->connection->execute('CREATE TABLE "TaxiPassenger" ("id" INT(10) PRIMARY KEY AUTO_INCREMENT, "name" VARCHAR(255), "phone" VARCHAR(255))');
     $this->connection->execute('INSERT INTO "TaxiPassenger" VALUES (1, \'Mike Smit\', \'1234567\')');
     $this->connection->execute('INSERT INTO "TaxiPassenger" VALUES (2, \'Jack Smit\', \'1234567\')');
     $this->connection->execute('INSERT INTO "TaxiPassenger" VALUES (3, \'Arnold Schwarzenegger\', \'1234567\')');
 }