/**
  * Test for the edge case that there is data that looks like a placeholder
  * but it is not
  */
 public function testPlaceholdersWithFixedData()
 {
     $expected = array('age');
     $query = PDOFactory::Get("INSERT INTO owners (name, age) VALUES (':name', :age)");
     $this->assertEquals($expected, $query->placeholders(), "Failed on ':name'");
     $query = PDOFactory::Get("INSERT INTO owners (name, age) VALUES (':name is weird', :age)");
     $this->assertEquals($expected, $query->placeholders(), "Failed on ':name is weird'");
     $query = PDOFactory::Get("INSERT INTO owners (name, age) VALUES (\"my:name\", :age)");
     $this->assertEquals($expected, $query->placeholders(), "Failed on \"my:name\"");
     $query = PDOFactory::Get("INSERT INTO owners (name, age) VALUES ('This is my :name and not yours', :age)");
     $this->assertEquals($expected, $query->placeholders(), "Failed on 'This is my :name and not yours'");
     $query = PDOFactory::Get("INSERT INTO owners (age, name) VALUES (:age, 'This is my :name and not yours')");
     $this->assertEquals($expected, $query->placeholders(), "Failed on 'This is my :name and not yours' as last parameter");
     $query = PDOFactory::Get("INSERT INTO  `cars` (\n            `id` ,\n            `brand` ,\n            `colour` ,\n            `doors` ,\n            `owner_id` ,\n            `name` ,\n            `age`\n            ) VALUES (\n            :id ,\n            \"My fancy brand\" ,\n            :colour ,\n            :doors ,\n            :owner_id ,\n            'peter',\n            :age)");
     $expected = array('id', 'colour', 'doors', 'owner_id', 'age');
     $this->assertEquals($expected, $query->placeholders(), "Failed on complex multi-line, multiple quotes query");
 }
Example #2
0
 public function tearDown()
 {
     PDOFactory::Get("TRUNCATE TABLE `cars`")->execute();
 }
<?php

namespace FlexibleORMTests;

use FlexibleORMTests\Mock\CachedCar;
use FlexibleORMTests\Mock\CachedElephant;
use FlexibleORMTests\Mock\CachedOwner;
use ORM\PDOFactory;
use ORM\Utilities\Cache\APCCache;
use Owner;
require_once 'ORMTest.php';
PDOFactory::GetFactory()->startProfiling();
/**
 * Test class for ORM_Model
 *
 * @note This tests that CachedORMModelTest behaves exactly as ORM_Model and that
 *      it caches objects correctly
 */
class CachedORMModelTest extends ORMTest
{
    protected function tearDown()
    {
        $freds = Owner::FindAllByName('Fred');
        $freds->delete();
    }
    public function testTableName()
    {
        $this->assertEquals('cars', CachedCar::TableName());
    }
    public function testFind()
    {
Example #4
0
 /**
  * @expectedException \ORM\Exceptions\FieldDoesNotExistException
  */
 public function testDescribeUnknownField()
 {
     $factory = PDOFactory::GetFactory();
     $factory->describeField('cars', 'idontexist');
 }
Example #5
0
 /**
  * Get the possible values of an ENUM field
  *
  * \note Only works for MySQL ENUM datatypes
  *
  * This is useful for rapid development as it allows you to only change the
  * ENUM values at the SQL side, but it is going to be slightly slower and
  * cause higer database load. If using this in production cache the result.
  *
  * @param string $fieldName
  *      The name of the database field you wish to check. If it is not an
  *      ENUM field, an empty array will be returned.
  * @return array
  *      Array of strings containing the valid field values. Is indexed from 1
  *      to match the MYSQL index. Will be empty if it cannot determine values
  *      (ie it's not a MySQL table or it's not an ENUM field).
  */
 public static function PossibleValues($fieldName)
 {
     $fieldName = static::TranslatePropertyToField($fieldName);
     $query = PDOFactory::Get('SHOW COLUMNS FROM `' . static::TableName() . '` LIKE "' . $fieldName . '"');
     $query->execute();
     $results = $query->fetch();
     $fields = array();
     if (preg_match_all('/\'(.*?)\'/', $results[1], $fieldsZeroIndexed)) {
         // Convert to 1-indexed array
         $fields = array_combine(range(1, count($fieldsZeroIndexed[1])), $fieldsZeroIndexed[1]);
     }
     return $fields;
 }