/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { parent::setUp(); $sf = \Gacela\Gacela::instance()->getDatasource('sf'); $adapter = new \ReflectionProperty($sf, '_adapter'); $adapter->setAccessible(true); $this->object = $adapter->getValue($sf); }
/** * For some reason this only passes when run in isolation * If I run the full test suite then it fails */ public function testAsArrayLessThan100Milliseconds() { $start = microtime(true); $col = \Gacela\Gacela::instance()->findAll('Test'); $col->asArray('id', 'testName', 'started'); $end = microtime(true); $time = $end - $start; $this->assertLessThan(0.03, $time, 'Elapsed time: ' . round($time, 3)); }
public function testLoadResourceWithMemcache() { $memcache = new \Memcache(); $memcache->addServer('127.0.0.1', 11211); $memcache->flush(); \Gacela\Gacela::instance()->enableCache($memcache); $this->assertFalse($memcache->get('test_resource_test')); $test = $this->object->loadResource('test'); $this->assertEquals($test, $memcache->get('test_resource_test')); }
/** * @depends testInsertWithDependent */ public function testDeleteWithDependent() { $this->new = $this->new; $mapper = \Gacela\Gacela::instance()->loadMapper('peep'); $mapper->save($this->changed, $this->new, $this->old); $this->assertNotNull($mapper->find($this->new['code'])->code); $this->assertTrue($mapper->delete($this->new)); $record = $mapper->find($this->new['code']); $this->assertNull($record->code); $test = \Gacela\Gacela::instance()->getDataSource('test'); $rs = $test->query($test->loadResource('contacts'), 'SELECT * FROM contacts'); $this->assertSame(0, $rs->rowCount()); }
public function testSaveUpdateWhenOriginalDataEmpty() { $start = microtime(true); $former = array('start' => date('c'), 'method' => 'POST', 'url' => '/unittest', 'request' => ''); $data = array_merge($former, array('end' => null, 'response' => null, 'status' => null, 'elapsed' => null)); $mapper = \Gacela\Gacela::instance()->loadMapper('Log'); $rs = $mapper->save(array_keys($former), $data, array()); $this->assertInternalType('array', $rs); $this->assertSame(array_keys($data), array_keys($rs)); $latter = array('end' => date('c'), 'response' => '', 'status' => 200, 'elapsed' => microtime(true) - $start); $changed = array_keys($latter); $data = array_merge($rs, $latter); $rs = $mapper->save(array_keys($latter), $data, array()); $this->assertInternalType('array', $rs); $this->assertSame(array_keys($data), array_keys($rs)); }
public function getConnection() { $test = \Gacela\Gacela::instance()->getDataSource('test'); $test->loadResource('peeps'); $r = new \ReflectionClass($test); $p = $r->getProperty('_adapter'); $p->setAccessible(true); $p = $p->getValue($test); $pr = new \ReflectionClass($p); $c = $pr->getProperty('_conn'); $c->setAccessible(true); $pdo = $c->getValue($p); if (is_null($this->conn)) { $this->conn = $this->createDefaultDBConnection($pdo); } return $this->conn; }
public function loadConnection() { if (!class_exists('\\SforceEnterpriseClient')) { require_once $this->_config->soapclient_path . 'SforceEnterpriseClient.php'; } if (is_null($this->_conn)) { $this->_conn = new \SforceEnterpriseClient(); $this->_conn->createConnection($this->_config->wsdl_path); $this->_conn->login($this->_config->username, $this->_config->password); $this->_columns = \Gacela\Gacela::instance()->cacheMetaData($this->_config->name . '_columns'); if (!$this->_columns) { $this->_columns = $this->describeSObjects($this->_config->objects); if (!is_array($this->_columns)) { $this->_columns = array($this->_columns); } \Gacela\Gacela::instance()->cacheMetaData($this->_config->name . '_columns', $this->_columns); } } }
/** * @param array $value * @return Collection */ public function search(array $value) { $data = array(); $prop = new \ReflectionProperty($this->current(), '_data'); $prop->setAccessible(true); foreach ($this as $row) { $rs = true; foreach ($value as $key => $val) { if ($row->{$key} != $val) { $rs = false; break; } } if ($rs === true) { $data[] = $prop->getValue($row); } } return \Gacela\Gacela::instance()->makeCollection($this->_mapper, $data); }
protected function _loadConfig($name, $skip = false) { if ($skip) { return null; } // Pull from the config file if enabled $config = \Gacela\Gacela::instance()->loadConfig($name); if (is_array($config)) { $_meta = array_merge(array('name' => $name, 'primary' => array(), 'relations' => array(), 'columns' => array()), $config); foreach ($_meta['columns'] as $key => $array) { $_meta['columns'][$key] = (object) array_merge(self::$_meta, $array); } foreach ($_meta['relations'] as $k => $relation) { $_meta['relations'][$k] = (object) $relation; } return $_meta; } return null; }
public function loadConnection() { if (!$this->_conn) { parent::loadConnection(); $this->_columns = \Gacela\Gacela::instance()->cacheMetaData($this->_config->schema . '_columns'); if (!$this->_columns) { $sql = "SELECT *\n\t\t\t\t\t\tFROM information_schema.COLUMNS\n\t\t\t\t\t\tWHERE TABLE_SCHEMA = DATABASE()"; $this->_columns = $this->query($sql)->fetchAll(\PDO::FETCH_OBJ); \Gacela\Gacela::instance()->cacheMetaData($this->_config->schema . '_columns', $this->_columns); } } // Moved out of __construct to allow for lazy loading of config data $this->_relationships = \Gacela\Gacela::instance()->cacheMetaData($this->_config->schema . '_relationships'); if (!$this->_relationships) { $fk = 'fk' . static::$_separator . '%' . static::$_separator . '%'; $sql = "\n\t\t\t\tSELECT\n\t\t\t\t\tTABLE_NAME AS keyTable,\n\t\t\t\t\tGROUP_CONCAT(COLUMN_NAME) AS keyColumns,\n\t\t\t\t\tREFERENCED_TABLE_NAME AS refTable,\n\t\t\t\t\tGROUP_CONCAT(REFERENCED_COLUMN_NAME) AS refColumns,\n\t\t\t\t\tCONSTRAINT_NAME AS constraintName\n\t\t\t\tFROM information_schema.key_column_usage\n\t\t\t\tWHERE TABLE_SCHEMA = DATABASE()\n\t\t\t\tAND CONSTRAINT_NAME LIKE '{$fk}'\n\t\t\t\tAND REFERENCED_TABLE_NAME IS NOT NULL\n\t\t\t\tGROUP BY constraintName\n\t\t\t\t"; $this->_relationships = $this->query($sql)->fetchAll(\PDO::FETCH_OBJ); \Gacela\Gacela::instance()->cacheMetaData($this->_config->schema . '_relationships', $this->_relationships); } }
public function testEmptyCollection() { $data = array(); $collection = new Arr(\Gacela\Gacela::instance()->loadMapper('test'), $data); foreach ($collection as $row) { $this->fail('Empty Collection should not iterate'); } }
/** * @param \stdClass|null $data * @return bool */ public function validate(array $data = null) { if ($data) { $this->setData($data); } $this->_primeData(); foreach (static::$meta[$this->_mapper]['fields'] as $key => $meta) { $rs = \Gacela\Gacela::instance()->getField($meta->type)->validate($meta, $this->_data[$key]); if ($rs !== true) { $this->_errors[$key] = $rs; } } if (count($this->_errors)) { return false; } return true; }
public function testEmptyCollection() { $data = $this->source->query($this->source->loadResource('tests'), "SELECT * FROM tests WHERE id < 0"); $collection = new Statement(\Gacela\Gacela::instance()->loadMapper('test'), $data); foreach ($collection as $row) { $this->fail('Empty Collection should not iterate'); } }
public static function tearDownAfterClass() { \Gacela\Gacela::reset(); }
/** * @covers Gacela\Mapper\Mapper::getFields */ public function testGetFields() { $resource = \Gacela\Gacela::instance()->getDataSource('test')->loadResource('tests'); $this->assertEquals($resource->getFields(), $this->object->getFields()); }
public function testColumnsCached() { $this->assertInternalType('array', \Gacela\Gacela::instance()->cacheMetaData('test_columns')); }
public function testInitDependentWithSequencedPrimaryKey() { $mapper = \Gacela\Gacela::instance()->loadMapper('Object'); $fields = $mapper->getFields(); $this->assertTrue($fields['metaId']->sequenced); }
public function setUp() { parent::setUp(); $this->object = \Gacela\Gacela::instance()->getDataSource('test'); }
public function testFindRelationOfCachedObject() { $courses = \Gacela\Gacela::instance()->findAll('Course'); $c2 = \Gacela\Gacela::instance()->findAll('Course'); foreach ($c2 as $course) { $this->assertInstanceOf('App\\Model\\Teacher', $course->teacher); } }
/** * @param \Gacela\Criteria * @return Query\Sql */ public function getQuery(\Gacela\Criteria $criteria = null) { $class = \Gacela\Gacela::instance()->autoload("DataSource\\Query\\Sql"); return new $class($criteria); }
protected function _gacela() { return \Gacela\Gacela::instance(); }
public function setUp() { parent::setUp(); $this->object = \Gacela\Gacela::instance()->loadMapper('Customer'); $this->object->setCacheable(false); }
<?php set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__DIR__) . '/'); require_once 'library/Gacela/Gacela.php'; $gacela = \Gacela\Gacela::instance(); function pwp($data) { $b = debug_backtrace(); $file = $b[0]['file']; echo '<pre>'; echo 'line:' . $b[0]['line'] . ' ' . $file . "\n"; print_r($data); echo '</pre>'; } require_once 'Test/TestCase.php';
/** * @covers Gacela::registerDataSource * @covers Gacela::getDataSource * @dataProvider providerSources */ public function testRegisterDataSource($config, $class) { $source = \Gacela\Gacela::createDataSource($config); $this->object->registerDataSource($source); $this->assertInstanceOf($class, $this->object->getDataSource($config['name'])); }
protected function setUp() { parent::setUp(); $this->object = \Gacela\Gacela::instance()->getDataSource('sf'); }
public function test__getRelation() { $object = \Gacela\Gacela::instance()->find('Student', 1); $this->assertSame('Gryffindor', $object->house->houseName); }
public function setUp() { $this->object = $this->getMockForAbstractClass('Gacela\\DataSource\\Adapter\\Adapter', array(\Gacela\Gacela::instance(), array('type' => 'mysql', 'schema' => 'test', 'username' => 'gacela', 'password' => 'gacela', 'host' => 'localhost'))); }
/** * @see \Gacela\DataSource\iDataSource::loadResource() */ public function loadResource($name, $force = false) { $cached = \Gacela\Gacela::instance()->cacheMetaData('resource_' . $name); if (!$cached || $force) { $class = \Gacela\Gacela::instance()->autoload("DataSource\\Resource"); $cached = new $class($this->_adapter->load($name, $force)); \Gacela\Gacela::instance()->cacheMetaData($this->_config->name . '_resource_' . $name, $cached); } return $cached; }