diff --git a/src/Storm/Model/PersistenceStrategy/Volatile.php b/src/Storm/Model/PersistenceStrategy/Volatile.php index f9262921224d9e6f3706f096bc967ec493ed490f..0cea7806d0dfda9a1a7e898588220f332d13344e 100644 --- a/src/Storm/Model/PersistenceStrategy/Volatile.php +++ b/src/Storm/Model/PersistenceStrategy/Volatile.php @@ -225,6 +225,10 @@ class Storm_Model_PersistenceStrategy_Volatile extends Storm_Model_PersistenceS if (!array_key_exists($key, $model)) return false; + if (is_array($value) && count($value) == 0) + throw new Storm_Model_Exception(sprintf('array given for %s is empty', + $key)); + if (is_array($value) && in_array($model[$key], $value)) return true; diff --git a/tests/Storm/Test/LoaderVolatileTest.php b/tests/Storm/Test/LoaderVolatileTest.php index aac0b8979cdb1fe329b890ee5a36661813a89c5f..851f5af2cdf1639ed4328f194f2d21d1f207143d 100644 --- a/tests/Storm/Test/LoaderVolatileTest.php +++ b/tests/Storm/Test/LoaderVolatileTest.php @@ -33,8 +33,8 @@ class Storm_Test_VolatileUser extends Storm_Model_Abstract { 'id_mouth' => null, 'brain_id' => null], - $_has_many = ['cats' => ['model' => 'Storm_Test_VolatileCat', - 'instance_of' => 'Storm_Test_VolatilePets', + $_has_many = ['cats' => ['model' => Storm_Test_VolatileCat::class, + 'instance_of' => Storm_Test_VolatilePets::class, 'dependents' => 'delete', 'role' => 'master']]; @@ -45,10 +45,10 @@ class Storm_Test_VolatileUser extends Storm_Model_Abstract { public function describeAssociationsOn($associations) { $associations - ->add(new Storm_Model_Association_HasOne('brain', ['model' => 'Storm_Test_VolatileBrain', + ->add(new Storm_Model_Association_HasOne('brain', ['model' => Storm_Test_VolatileBrain::class, 'referenced_in' => 'brain_id'])) - ->add(new Storm_Model_Association_HasOne('mouth', ['model' => 'Storm_Test_VolatileMouth', + ->add(new Storm_Model_Association_HasOne('mouth', ['model' => Storm_Test_VolatileMouth::class, 'referenced_in' => 'id_mouth'])); } } @@ -114,7 +114,7 @@ class Storm_Test_LoaderVolatileTest extends Storm_Test_ModelTestCase { 'option' => 'set', 'brain_id' => 2]); - $this->hubert_brain = $this->fixture('Storm_Test_VolatileBrain', + $this->hubert_brain = $this->fixture(Storm_Test_VolatileBrain::class, ['id' => 2, 'weight' => 155]); @@ -125,15 +125,15 @@ class Storm_Test_LoaderVolatileTest extends Storm_Test_ModelTestCase { 'level' => 'admin', 'foo' => 'snafu', 'cats' => [ - $this->fixture('Storm_Test_VolatileCat', + $this->fixture(Storm_Test_VolatileCat::class, ['id' => 3, 'name' => 'riri']), - $this->fixture('Storm_Test_VolatileCat', + $this->fixture(Storm_Test_VolatileCat::class, ['id' => 4, 'name' => 'fifi']), - $this->fixture('Storm_Test_VolatileCat', + $this->fixture(Storm_Test_VolatileCat::class, ['id' => 5, 'name' => 'loulou']), ] @@ -173,7 +173,7 @@ class Storm_Test_LoaderVolatileTest extends Storm_Test_ModelTestCase { /** @test */ public function changingAlbertBrainShouldUpdateItsReferenceInBrainId() { - $better_brain = $this->fixture('Storm_Test_VolatileBrain', ['id' => 3, + $better_brain = $this->fixture(Storm_Test_VolatileBrain::class, ['id' => 3, 'weight' => 150]); $this->albert->setBrain($better_brain); $this->assertEquals(3, $this->albert->getBrainId()); @@ -483,6 +483,17 @@ class Storm_Test_LoaderVolatileTest extends Storm_Test_ModelTestCase { } + + /** + * @expectedException Storm_Model_Exception + * @expectedExceptionMessage array given for login is empty + * @test + **/ + public function findAllWithLoginEmptyArrayShouldRaiseEmptyArrayException() { + Storm_Test_VolatileUser::findAll(['login'=> []]); + } + + /** @test */ public function findAllInviteOrderByLoginNameDescShouldReturnMaxAndHubert() { $this->max->save();