Commit 67e32fa4 authored by Laurent's avatar Laurent

Add left() syntax:

Storm_Test_VolatileUser::findAllBy(['left(login,2)' => 'zo'])
parent 7aa22a89
Pipeline #10077 passed with stage
in 17 seconds
......@@ -217,9 +217,23 @@ class Storm_Model_PersistenceStrategy_Volatile extends Storm_Model_PersistenceS
public function containsAttribute($model, $key, $value) {
return array_key_exists($key, $model)
&& ($model[$key] == $value
|| (is_array($value) && in_array($model[$key], $value)));
if (preg_match('/left\((.+),(.+)\)/', $key, $matches)) {
$key = trim($matches[1]);
$left_len = (int)$matches[2];
}
if (!array_key_exists($key, $model))
return false;
if (is_array($value) && in_array($model[$key], $value))
return true;
if (isset($left_len)
&& is_string($value)
&& substr($model[$key], 0, $left_len) === substr($value, 0, $left_len))
return true;
return $model[$key] == $value;
}
......
......@@ -632,13 +632,25 @@ class Storm_Test_LoaderVolatileTest extends Storm_Test_ModelTestCase {
}
/** @test */
/** @test */
public function memoryReportShouldPrintThreeUsers() {
$this->assertContains("Storm_Test_VolatileUser: 3",
Storm_MemoryReport::renderText());
}
}
/** @test */
public function findAllByLeftLogin2ZoShouldAnswersZoe() {
$this->assertEquals([ $this->zoe ],
Storm_Test_VolatileUser::findAllBy(['left(login,2)' => 'zo']));
}
/** @test */
public function findAllByLeftLogin10HubertShouldAnswersHubert() {
$this->assertEquals([ $this->hubert ],
Storm_Test_VolatileUser::findAllBy(['left( login , 10 )' => 'hubert']));
}
}
?>
\ No newline at end of file
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