<commit_before><?php

class CM_Model_AbstractTest extends CMTest_TestCase {

	public static function setupBeforeClass() {
		CM_Db_Db::exec("CREATE TABLE IF NOT EXISTS `modelMock` (
				`id` INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
				`foo` VARCHAR(32)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8;
		");
		CM_Db_Db::exec("CREATE TABLE IF NOT EXISTS `modelThasIsAnAssetMock` (
				`id` INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
				`modelMockId` INT UNSIGNED NOT NULL,
				`bar` VARCHAR(32),
				KEY (`modelMockId`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8;
		");
	}

	public static function tearDownAfterClass() {
		parent::tearDownAfterClass();
		CM_Db_Db::exec("DROP TABLE `modelMock`");
		CM_Db_Db::exec("DROP TABLE `modelThasIsAnAssetMock`");
	}

	public function setup() {
		$modelMock = CM_ModelMock::create(array('foo' => 'bar1'));
	}

	public function tearDown() {
		CM_Db_Db::truncate('modelMock');
		CM_Db_Db::truncate('modelThasIsAnAssetMock');
		CMTest_TH::clearEnv();
	}

	public function testConstruct() {
		$modelMock = CM_ModelMock::create(array('foo' => 'bar1'));
		$modelMock = new CM_ModelMock($modelMock->getId());
		$this->assertEquals('bar1', $modelMock->getFoo());
	}

	public function testCache() {
		$modelMock = CM_ModelMock::create(array('foo' => 'bar1'));
		$modelMock = new CM_ModelMock($modelMock->getId());
		$this->assertEquals('bar1', $modelMock->getFoo());
		CM_Db_Db::update('modelMock', array('foo' => 'bar2'), array('id' => $modelMock->getId()));
		$modelMock = new CM_ModelMock($modelMock->getId());
		$this->assertEquals('bar1', $modelMock->getFoo());
		$modelMock->_change();
		$modelMock = new CM_ModelMock($modelMock->getId());
		$this->assertEquals('bar2', $modelMock->getFoo());
	}

	public function testCacheHit() {
		$data = array('foo' => 12, 'bar' => 13);
		$id = array('id' => 55);

		$cache = $this->getMockBuilder('CM_Model_StorageAdapter_AbstractAdapter')->setMethods(array('load'))->getMockForAbstractClass();
		$cache->expects($this->once())->method('load')->with($id)->will($this->returnValue($data));
		/** @var CM_Model_StorageAdapter_AbstractAdapter $cache */

		$model = $this->getMockBuilder('CM_Model_Abstract')->setMethods(array('getCache',
			'getIdRaw'))->disableOriginalConstructor()->getMockForAbstractClass();
		$model->expects($this->any())->method('getCache')->will($this->returnValue($cache));
		$model->expects($this->any())->method('getIdRaw')->will($this->returnValue($id));
		/** @var CM_Model_Abstract $model */

		$this->assertSame($data, $model->_get());
	}

	public function testCacheMiss() {
		$data = array('foo' => 12, 'bar' => 13);
		$id = array('id' => 55);

		$cache = $this->getMockBuilder('CM_Model_StorageAdapter_AbstractAdapter')->setMethods(array('load', 'save'))->getMockForAbstractClass();
		$cache->expects($this->once())->method('load')->with($id)->will($this->returnValue(false));
		$cache->expects($this->once())->method('save')->with($id, $data);
		/** @var CM_Model_StorageAdapter_AbstractAdapter $cache */

		$model = $this->getMockBuilder('CM_Model_Abstract')->setMethods(array('getCache', 'getIdRaw', '_loadData'))
				->disableOriginalConstructor()->getMockForAbstractClass();
		$model->expects($this->any())->method('getCache')->will($this->returnValue($cache));
		$model->expects($this->any())->method('getIdRaw')->will($this->returnValue($id));
		$model->expects($this->any())->method('_loadData')->will($this->returnValue($data));
		/** @var CM_Model_Abstract $model */

		$this->assertSame($data, $model->_get());
	}

	public function testCacheSet() {
		$data = array('foo' => 12);
		$id = array('id' => 55);

		$cache = $this->getMockBuilder('CM_Model_StorageAdapter_AbstractAdapter')->setMethods(array('load', 'save'))->getMockForAbstractClass();
		$cache->expects($this->once())->method('load')->with($id)->will($this->returnValue($data));
		$cache->expects($this->once())->method('save')->with($id, array('foo' => 12, 'bar' => 14));
		/** @var CM_Model_StorageAdapter_AbstractAdapter $cache */

		$model = $this->getMockBuilder('CM_Model_Abstract')->setMethods(array('getCache', 'getIdRaw'))
				->disableOriginalConstructor()->getMockForAbstractClass();
		$model->expects($this->any())->method('getCache')->will($this->returnValue($cache));
		$model->expects($this->any())->method('getIdRaw')->will($this->returnValue($id));
		/** @var CM_Model_Abstract $model */

		$model->_set(array('bar' => 14));
	}

	public function testGet() {
		$modelMock = CM_ModelMock::create(array('foo' => 'bar1'));
		$modelMock = new CM_ModelMock($modelMock->getId());
		try {
			$modelMock->_get('foo');
			$this->assertEquals('bar1', $modelMock->_get('foo'));
		} catch (CM_Exception $ex) {
			$this->fail('Field `foo` does not exist.');
		}
		try {<commit_msg>Add test for cache delete call<commit_after><?php

class CM_Model_AbstractTest extends CMTest_TestCase {

	public static function setupBeforeClass() {
		CM_Db_Db::exec("CREATE TABLE IF NOT EXISTS `modelMock` (
				`id` INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
				`foo` VARCHAR(32)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8;
		");
		CM_Db_Db::exec("CREATE TABLE IF NOT EXISTS `modelThasIsAnAssetMock` (
				`id` INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
				`modelMockId` INT UNSIGNED NOT NULL,
				`bar` VARCHAR(32),
				KEY (`modelMockId`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8;
		");
	}

	public static function tearDownAfterClass() {
		parent::tearDownAfterClass();
		CM_Db_Db::exec("DROP TABLE `modelMock`");
		CM_Db_Db::exec("DROP TABLE `modelThasIsAnAssetMock`");
	}

	public function setup() {
		$modelMock = CM_ModelMock::create(array('foo' => 'bar1'));
	}

	public function tearDown() {
		CM_Db_Db::truncate('modelMock');
		CM_Db_Db::truncate('modelThasIsAnAssetMock');
		CMTest_TH::clearEnv();
	}

	public function testConstruct() {
		$modelMock = CM_ModelMock::create(array('foo' => 'bar1'));
		$modelMock = new CM_ModelMock($modelMock->getId());
		$this->assertEquals('bar1', $modelMock->getFoo());
	}

	public function testCache() {
		$modelMock = CM_ModelMock::create(array('foo' => 'bar1'));
		$modelMock = new CM_ModelMock($modelMock->getId());
		$this->assertEquals('bar1', $modelMock->getFoo());
		CM_Db_Db::update('modelMock', array('foo' => 'bar2'), array('id' => $modelMock->getId()));
		$modelMock = new CM_ModelMock($modelMock->getId());
		$this->assertEquals('bar1', $modelMock->getFoo());
		$modelMock->_change();
		$modelMock = new CM_ModelMock($modelMock->getId());
		$this->assertEquals('bar2', $modelMock->getFoo());
	}

	public function testCacheHit() {
		$data = array('foo' => 12, 'bar' => 13);
		$id = array('id' => 55);

		$cache = $this->getMockBuilder('CM_Model_StorageAdapter_AbstractAdapter')->setMethods(array('load'))->getMockForAbstractClass();
		$cache->expects($this->once())->method('load')->with($id)->will($this->returnValue($data));
		/** @var CM_Model_StorageAdapter_AbstractAdapter $cache */

		$model = $this->getMockBuilder('CM_Model_Abstract')->setMethods(array('getCache',
			'getIdRaw'))->disableOriginalConstructor()->getMockForAbstractClass();
		$model->expects($this->any())->method('getCache')->will($this->returnValue($cache));
		$model->expects($this->any())->method('getIdRaw')->will($this->returnValue($id));
		/** @var CM_Model_Abstract $model */

		$this->assertSame($data, $model->_get());
	}

	public function testCacheMiss() {
		$data = array('foo' => 12, 'bar' => 13);
		$id = array('id' => 55);

		$cache = $this->getMockBuilder('CM_Model_StorageAdapter_AbstractAdapter')->setMethods(array('load', 'save'))->getMockForAbstractClass();
		$cache->expects($this->once())->method('load')->with($id)->will($this->returnValue(false));
		$cache->expects($this->once())->method('save')->with($id, $data);
		/** @var CM_Model_StorageAdapter_AbstractAdapter $cache */

		$model = $this->getMockBuilder('CM_Model_Abstract')->setMethods(array('getCache', 'getIdRaw', '_loadData'))
				->disableOriginalConstructor()->getMockForAbstractClass();
		$model->expects($this->any())->method('getCache')->will($this->returnValue($cache));
		$model->expects($this->any())->method('getIdRaw')->will($this->returnValue($id));
		$model->expects($this->any())->method('_loadData')->will($this->returnValue($data));
		/** @var CM_Model_Abstract $model */

		$this->assertSame($data, $model->_get());
	}

	public function testCacheSet() {
		$data = array('foo' => 12);
		$id = array('id' => 55);

		$cache = $this->getMockBuilder('CM_Model_StorageAdapter_AbstractAdapter')->setMethods(array('load', 'save'))->getMockForAbstractClass();
		$cache->expects($this->once())->method('load')->with($id)->will($this->returnValue($data));
		$cache->expects($this->once())->method('save')->with($id, array('foo' => 12, 'bar' => 14));
		/** @var CM_Model_StorageAdapter_AbstractAdapter $cache */

		$model = $this->getMockBuilder('CM_Model_Abstract')->setMethods(array('getCache', 'getIdRaw'))
				->disableOriginalConstructor()->getMockForAbstractClass();
		$model->expects($this->any())->method('getCache')->will($this->returnValue($cache));
		$model->expects($this->any())->method('getIdRaw')->will($this->returnValue($id));
		/** @var CM_Model_Abstract $model */

		$model->_set(array('bar' => 14));
	}

	public function testCacheDelete() {
		$id = array('id' => 55);

		$cache = $this->getMockBuilder('CM_Model_StorageAdapter_AbstractAdapter')->setMethods(array('delete'))->getMockForAbstractClass();
		$cache->expects($this->once())->method('delete')->with($id);
		/** @var CM_Model_StorageAdapter_AbstractAdapter $cache */

		$model = $this->getMockBuilder('CM_Model_Abstract')->setMethods(array('getCache', 'getIdRaw'))
				->disableOriginalConstructor()->getMockForAbstractClass();
		$model->expects($this->any())->method('getCache')->will($this->returnValue($cache));
		$model->expects($this->any())->method('getIdRaw')->will($this->returnValue($id));
		/** @var CM_Model_Abstract $model */

		$model->delete();
	}

	public function testGet() {
		$modelMock = CM_ModelMock::create(array('foo' => 'bar1'));
		$modelMock = new CM_ModelMock($modelMock->getId());
		try {
			$modelMock->_get('foo');
			$this->assertEquals('bar1', $modelMock->_get('foo'));
		} catch (CM_Exception $ex) {
			$this->fail('Field `foo` does not exist.');
		}
		try {
{'fraction_non_alphanumeric': 0.21659661812139575, 'fraction_numerical': 0.007623888182973317, 'mean_word_length': 6.490483162518301, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 272, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '659124', 'n_tokens_mistral': 3653, 'n_tokens_neox': 3342, 'n_words': 477}