Commit facf291b authored by Patrick Barroca's avatar Patrick Barroca 🐧

Merge branch 'perfs_phpunit' into 'master'

Perfs phpunit

See merge request !22
parents 84f4fb2e ff2fc936
Pipeline #5418 canceled with stage
......@@ -28,7 +28,13 @@ abstract class Storm_Model_Abstract {
/**
* @var array
*/
protected static $_loaders = array();
protected static $_loaders = [];
protected static $_method_prefixes = ['get' => 3,
'set' => 3,
'add' => 3,
'remove' => 6,
'has' => 3,
'numberOf' => 8];
/**
* @var string
......@@ -665,6 +671,16 @@ abstract class Storm_Model_Abstract {
}
protected function _methodMatch($method) {
foreach(static::$_method_prefixes as $prefix => $length) {
if (substr($method, 0, $length) == $prefix)
return [1 => $prefix,
2 => substr($method, $length)];
}
return null;
}
/**
* See __call
*
......@@ -678,7 +694,7 @@ abstract class Storm_Model_Abstract {
* @throws Exception
*/
public function perform($method, $args = []) {
if (!preg_match('/(get|set|add|remove|has|numberOf)(\w+)/', $method, $matches)) {
if (!$matches = $this->_methodMatch($method)) {
throw new Storm_Model_Exception('Tried to call unknown method '.get_class($this).'::'.$method);
}
......
......@@ -105,7 +105,7 @@ class Storm_Model_PersistenceStrategy_Db extends Storm_Model_PersistenceStrategy
return 0;
$select->from($this->getTable(),
[sprintf('count(%s) as numberof', $this->_loader->getIdField())]);
[sprintf('count(*) as numberof')]);
$rows = $this->getTable()->fetchAll($select)->toArray();
return $rows[0]['numberof'];
}
......
......@@ -52,7 +52,7 @@ class Storm_Test_LoaderTest extends Storm_Test_ModelTestCase {
public function countByWithWhereShouldBuildRightSQL() {
$select = Storm_Test_ObjectWrapper::mock()
->whenCalled('from')
->with($this->_table, array('count(id) as numberof'))
->with($this->_table, ['count(*) as numberof'])
->answers(null)
->whenCalled('where')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment