Commit 77704143 authored by Laurent's avatar Laurent

Merge branch 'perfs_and_warnings' into 'master'

fix warnings and small performances improvement

See merge request !21
parents 4aa9820c 53bc64d2
Pipeline #1843 passed with stage
in 3 seconds
......@@ -202,12 +202,9 @@ abstract class Storm_Model_Abstract {
* @return Storm_Model_Loader
*/
public static function getLoaderFor($class) {
if (!(isset(self::$_loaders[$class]) || array_key_exists($class, self::$_loaders))) {
self::setLoaderFor($class, self::_buildLoaderFor($class));
}
return self::$_loaders[$class];
return isset(self::$_loaders[$class])
? self::$_loaders[$class]
: self::setLoaderFor($class, self::_buildLoaderFor($class));
}
......@@ -216,7 +213,7 @@ abstract class Storm_Model_Abstract {
* @param Storm_Model_Loader $loader
*/
public static function setLoaderFor($class, $loader) {
self::$_loaders[$class] = $loader;
return self::$_loaders[$class] = $loader;
}
......
......@@ -184,7 +184,7 @@ class Storm_Model_Loader {
return null;
}
if (array_key_exists($id, $this->_loaded_instances)) {
if (isset($this->_loaded_instances[$id])) {
return $this->_loaded_instances[$id];
}
......
......@@ -26,9 +26,7 @@ THE SOFTWARE.
class Storm_Test_SaveHooksTest extends Storm_Test_ModelTestCase {
public function setUp() {
$this->trace_hook_mock = $this->createMock('TraceHookMock', array('beforeSave',
'afterSave',
'loaderSave'));
$this->trace_hook_mock = $this->mock();
$this->valid_user = new Storm_Test_Mock_User();
$this->valid_user
......@@ -44,12 +42,11 @@ class Storm_Test_SaveHooksTest extends Storm_Test_ModelTestCase {
public function testInvalidModelDoNotCallHooks() {
$this->trace_hook_mock
->expects($this->never())
->method('beforeSave');
$this->trace_hook_mock
->expects($this->never())
->method('afterSave');
->whenCalled('beforeSave')
->never()
->whenCalled('afterSave')
->never()
->beStrict();
$this->invalid_user->save();
}
......@@ -57,37 +54,52 @@ class Storm_Test_SaveHooksTest extends Storm_Test_ModelTestCase {
public function testValidModelCallHooksWithSuccessfullSave() {
$this->trace_hook_mock
->expects($this->at(0))
->method('beforeSave');
->whenCalled('beforeSave')
->willDo(function()
{
$this->trace_hook_mock
->whenCalled('loaderSave')
->willDo(function()
{
$this->trace_hook_mock
->expects($this->at(1))
->method('loaderSave')
->will($this->returnValue(2));
$this->trace_hook_mock
->whenCalled('afterSave')
->answers(true);
return 2;
});
})
->beStrict();
$this->trace_hook_mock
->expects($this->at(2))
->method('afterSave');
$this->valid_user->save();
$this->assertTrue($this->trace_hook_mock->methodHasBeenCalled('afterSave'));
}
public function testValidModelCallHooksWithUnsuccessfullSave() {
$this->trace_hook_mock
->expects($this->at(0))
->method('beforeSave');
->whenCalled('beforeSave')
->willDo(function()
{
$this->trace_hook_mock
->whenCalled('loaderSave')
->willDo(function()
{
$this->trace_hook_mock
->expects($this->at(1))
->method('loaderSave')
->will($this->returnValue(0));
$this->trace_hook_mock
->whenCalled('afterSave')
->answers(true);
return false;
});
})
->beStrict();
$this->trace_hook_mock
->expects($this->once())
->method('afterSave');
$this->valid_user->save();
$this->assertTrue($this->trace_hook_mock->methodHasBeenCalled('afterSave'));
}
}
......
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