コード例 #1
0
 /**
  * Test for `MySqlQuery::whereRaw()`.
  *
  * @since 1.0.0
  * @access public
  *
  * @requires function Freyja\Database\Query\MySqlQuery::whereRaw
  *
  * @expectedException Freyja\Exceptions\InvalidArgumentException
  * @expectedExceptionMessage Wrong type for argument where. String expected, array given instead.
  */
 public function testWhereRawWithInvalidArgument()
 {
     $query = new MySqlQuery();
     $query->whereRaw(array());
 }
コード例 #2
0
 /**
  * Test for `MySqlDriver::execute()`.
  *
  * @since 1.0.0
  * @access public
  *
  * @requires function Freyja\Database\Driver\MySqlDriver::execute
  */
 public function testExecuteWithEscapedStrings()
 {
     // Load data.
     $connection = $this->getConnection();
     $ds = $this->getDataSet(array('customers'));
     $this->loadDataSet($ds);
     $query = new MySqlQuery();
     $query->table('customers')->select('email')->where('name', 'Tizio');
     $driver = new MySqlDriver();
     $result = $driver->connect('localhost', 'test', 'travis', '')->execute($query);
     $this->assertEquals($result[0]['email'], '*****@*****.**', 'Failed asserting that MySqlDriver::execute correctly execute the specified query.');
 }
コード例 #3
0
ファイル: SchemaTest.php プロジェクト: SqueezyWeb/Database
 /**
  * Test for `Schema::create()`.
  *
  * @since 1.0.0
  * @access public
  *
  * @requires function Freyja\Database\Schema\Schema::__construct
  * @requires function Freyja\Database\Database::__construct
  * @requires function Freyja\Database\Database::connect
  * @requires function Freyja\Database\Driver\MySqlDriver::connect
  * @requires function Freyja\Database\Schema\Schema::create
  */
 public function testCreate()
 {
     // Load data.
     $ds = $this->getDataSet(array('customers'));
     $this->loadDataSet($ds);
     // Set accessbiility to object property.
     $reflection_schema = new ReflectionProperty('Freyja\\Database\\Schema\\Schema', 'schema');
     $reflection_schema->setAccessible(true);
     $prod_id = new Field('product_id');
     $prod_id->varchar(200);
     $name = new Field('name');
     $name->varchar(200);
     $quantity = new Field('quantity');
     $quantity->varchar(200);
     $prods = new Table('products', array($prod_id, $name, $quantity));
     $db = new Database(new MySqlDriver());
     $schema = new Schema($db->connect('localhost', 'test', 'travis', ''));
     $schema->create($prods);
     $query = new MySqlQuery();
     $query->table('products')->insert(array('product_id', 'name', 'quantity'), array(array(null, null, null)));
     $db->execute($query);
     $query_table = $this->getConnection()->createQueryTable('products', 'SELECT * FROM products');
     $expected_table = new \PHPUnit_Extensions_Database_DataSet_YamlDataSet(dirname(__FILE__) . '/fixtures/products.yml');
     $this->assertTablesEqual($query_table, $expected_table->getTable('products'));
     $expected_schema = array('fields' => array('product_id' => array('type' => 'VARCHAR(200)', 'default' => null, 'NOT NULL' => false, 'UNSIGNED' => false, 'AUTO_INCREMENT' => false), 'name' => array('type' => 'VARCHAR(200)', 'default' => null, 'NOT NULL' => false, 'UNSIGNED' => false, 'AUTO_INCREMENT' => false), 'quantity' => array('type' => 'VARCHAR(200)', 'default' => null, 'NOT NULL' => false, 'UNSIGNED' => false, 'AUTO_INCREMENT' => false)), 'primary' => array(), 'foreign' => array(), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'engine' => 'InnoDB');
     $retr_schema = $reflection_schema->getValue($schema);
     $this->assertEquals($expected_schema, $retr_schema['tables']['products'], 'Failed asserting that Schema::create() correctly update the database schema.');
     $this->getConnection()->getConnection()->exec('DROP TABLE IF EXISTS products');
 }
コード例 #4
0
ファイル: DatabaseTest.php プロジェクト: SqueezyWeb/Database
 /**
  * Test for `Database::execute()` and `Database::first()`.
  *
  * @since 1.0.0
  * @access public
  *
  * @requires function Freyja\Database\Database::__construct
  * @requires function Freyja\Database\Database::execute
  * @requires function Freyja\Database\Database::first
  */
 public function testExecuteAndFirst()
 {
     // Load data.
     $ds = $this->getDataSet(array('customers'));
     $this->loadDataSet($ds);
     $query = new MySqlQuery();
     $query->table('customers')->select(array());
     $driver = new MySqlDriver();
     $db = new Database($driver);
     $result = $db->connect('localhost', 'test', 'travis', '')->execute($query)->first();
     $expected_result = array('customer_id' => '1', 'name' => 'Tizio', 'surname' => 'Caio', 'email' => '*****@*****.**');
     $this->assertEquals($result, $expected_result, 'Failed asserting that Database correctly execute and retrieve the result of a query.');
 }