public function testEagerLoadBelongsToSimpleMany() { // Find kid with id `3` $kid3 = Model\Kid::with('user')->find(3); // Consist $this->assertInstanceOf('Gas\\ORM', $kid3); $this->assertInstanceOf('Gas\\Data', $kid3->record); // Check result $this->assertEquals($kid3->id, '3'); $this->assertEquals($kid3->name, 'Abraham Jones'); $this->assertEquals($kid3->age, '3'); // Grab related father (user) $kid3_father = $kid3->user(); // Consist $this->assertInstanceOf('Gas\\ORM', $kid3_father); $this->assertInstanceOf('Gas\\Data', $kid3_father->record); // Check results, this should be `Derek Jones` with `2` as his id // and `derek` as his username $this->assertEquals($kid3_father->id, '2'); $this->assertEquals($kid3_father->name, 'Derek Jones'); $this->assertEquals($kid3_father->username, 'derek'); // Since the third parameter for kid <-> user relationship // contain `select:id,name,username` for pre-process relation // Other fields should be null $this->assertNull($kid3_father->email); }
public function testBelongsToFinder() { // Find a belongs-to record $dad_of_kid1 = Model\Kid::find(1)->user(); $this->assertInternalType('object', $dad_of_kid1); $this->assertTrue($dad_of_kid1 instanceof Gas\ORM); }
/** * @see Model\User (./tests/dummyModels/user.php) * @see Model\Kid (./tests/dummyModels/kid.php) * @see Model\Job (./tests/dummyModels/job.php) * @see Model\Job\User (./tests/dummyModels/job/user.php) * @see Model\Role (./tests/dummyModels/role.php) * @see Model\Role\User (./tests/dummyModels/role/user.php) */ public function setUp() { Model\User::setUp(); Model\Kid::setUp(); Model\Job::setUp(); Model\Job\User::setUp(); Model\Role::setUp(); Model\Role\User::setUp(); }
$gasdir = implode(DIRECTORY_SEPARATOR, $fragdir); // Catch Base Directory if (defined('ROOTPATH')) { array_splice($fragdir, -2); } else { array_splice($fragdir, -3); } $basedir = implode(DIRECTORY_SEPARATOR, $fragdir); // Define the PATH and ENVIRONMENT define('ENVIRONMENT', 'testing'); if (defined('ROOTPATH')) { define('APPPATH', $basedir . DIRECTORY_SEPARATOR); define('BASEPATH', APPPATH . 'vendor' . DIRECTORY_SEPARATOR . 'CodeIgniter' . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR); } else { define('APPPATH', $basedir . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR); define('BASEPATH', $basedir . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR); } // Define Gas ORM configuration for unit testing $config = array('models_path' => array('Model' => __DIR__ . DIRECTORY_SEPARATOR . 'dummyModels'), 'cache_request' => FALSE, 'auto_create_models' => FALSE, 'auto_create_tables' => FALSE); // Include Gas ORM configuration and Bootstrap include_once $gasdir . DIRECTORY_SEPARATOR . 'bootstrap.php'; // Initialize all Model's setup Model\Job\User::setUp(); Model\Role\User::setUp(); Model\Job::setUp(); Model\Kid::setUp(); Model\Role::setUp(); Model\User::setUp(); Model\Wife::setUp(); // Reconnect Gas\Core::connect(DB_GROUP);