function test_should_establish_multiple_connections() { if(AK_PHP5){ $db_settings = Ak::convert('yaml', 'array', AK_CONFIG_DIR.DS.'database.yml'); $db_settings['sqlite_databases'] = array( 'database_file' => AK_TMP_DIR.DS.'testing_sqlite_database.sqlite', 'type' => 'sqlite' ); file_put_contents(AK_CONFIG_DIR.DS.'database.yml', Ak::convert('array', 'yaml', $db_settings)); $this->installAndIncludeModels(array('TestOtherConnection')); Ak::import('test_other_connection'); $OtherConnection = new TestOtherConnection(array('name'=>'Delia')); $this->assertTrue($OtherConnection->save()); $this->installAndIncludeModels(array('DummyModel'=>'id,name')); $Dummy = new DummyModel(); $this->assertNotEqual($Dummy->getConnection(), $OtherConnection->getConnection()); unset($db_settings['sqlite_databases']); file_put_contents(AK_CONFIG_DIR.DS.'database.yml', Ak::convert('array', 'yaml', $db_settings)); } }
protected function doTest($attributes) { $model = new DummyModel($attributes); $model_attributes = $model->getAttributes(); $this->assertEquals($attributes['dont_encrypt'], $model->attributes['dont_encrypt']); $this->assertStringStartsWith('__ELOCRYPT__:', $model->attributes['encrypt_me']); $this->assertEquals($attributes['encrypt_me'], $model_attributes['encrypt_me']); }
public function test_should_establish_multiple_connections() { $db_file_existed = false; if (file_exists(AkConfig::getDir('config') . DS . 'database.yml')) { $db_file_existed = true; $db_settings = Ak::convert('yaml', 'array', AkConfig::getDir('config') . DS . 'database.yml'); } $db_settings['sqlite_databases'] = array('database_file' => AK_TMP_DIR . DS . 'testing_sqlite_database.sqlite', 'type' => 'sqlite'); file_put_contents(AkConfig::getDir('config') . DS . 'database.yml', Ak::convert('array', 'yaml', $db_settings)); @unlink(AK_TMP_DIR . DS . 'testing_sqlite_database.sqlite'); $this->installAndIncludeModels(array('TestOtherConnection')); Ak::import('test_other_connection'); $OtherConnection = new TestOtherConnection(array('name' => 'Delia')); $this->assertTrue($OtherConnection->save()); $this->installAndIncludeModels(array('DummyModel' => 'id,name')); $Dummy = new DummyModel(); $this->assertNotEqual($Dummy->getConnection(), $OtherConnection->getConnection()); unset($db_settings['sqlite_databases']); if ($db_file_existed) { file_put_contents(AkConfig::getDir('config') . DS . 'database.yml', Ak::convert('array', 'yaml', $db_settings)); } else { unlink(AkConfig::getDir('config') . DS . 'database.yml'); } }
/** * @group UsingDB * @covers BaseRssModel::processItems */ public function testProcessItems() { $dummy = new DummyModel(); $dummy->setTestFixDuplicatedTimestamps(true); $processItems = self::getFn($dummy, 'processItems'); $realData = $this->getRealData(); $expectedProcessedData = $this->getExpectedProcessedRealData(); $processedData = $processItems($realData); // Assert that all timestamps are unique $this->assertEquals(count($processedData), $this->countUniqueTimestamps($processedData)); // Asserts that number of elements in $processedData is the same as in $expectedProcessedData $this->assertEquals(count($expectedProcessedData), count($processedData)); foreach ($expectedProcessedData as $key => $expectedValue) { // Asserts that all expected keys are present in $processedData $this->assertNotEmpty($processedData[$key]); // Assert equality of expected and actual elements, which corresponding to $key $actualValue = $processedData[$key]; $this->assertEquals($expectedValue, $actualValue); } }
/** * @covers ::getProvider * @covers ::setProvider */ public function testGetSet() { $provider = new FromArray(true, 'validation'); DummyModel::setProvider($provider); $this->assertSame($provider, DummyModel::getProvider()); }
public function testCanJsonifyWithToJson() { $model = new DummyModel(array('hidden' => 'foo', 'foo' => 'bar')); $this->assertEquals('{"foo":"bar"}', $model->toJson()); }
/** * @covers ::getBuilder * @covers ::setBuilder */ public function testGetSet() { $builder = new V1Model(); DummyModel::setBuilder($builder); $this->assertSame($builder, DummyModel::getBuilder()); }