mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
Add tests for #3288 and remove nested ternaries.
Nested ternaries are complicated to maintain and hard to read. Break down the nested ternary into two conditionals.
This commit is contained in:
parent
db450a96e9
commit
c6173a0054
2 changed files with 40 additions and 1 deletions
|
@ -831,6 +831,39 @@ class HashTest extends CakeTestCase {
|
|||
$this->assertEquals(5, $result[3]['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test extracting based on attributes with boolean values.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExtractAttributeBoolean() {
|
||||
$users = array(
|
||||
array(
|
||||
'id' => 2,
|
||||
'username' => 'johndoe',
|
||||
'active' => true
|
||||
),
|
||||
array(
|
||||
'id' => 5,
|
||||
'username' => 'kevin',
|
||||
'active' => true
|
||||
),
|
||||
array(
|
||||
'id' => 9,
|
||||
'username' => 'samantha',
|
||||
'active' => false
|
||||
),
|
||||
);
|
||||
$result = Hash::extract($users, '{n}[active=false]');
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals($users[2], $result[0]);
|
||||
|
||||
$result = Hash::extract($users, '{n}[active=true]');
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertEquals($users[0], $result[0]);
|
||||
$this->assertEquals($users[1], $result[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that attribute matchers don't cause errors on scalar data.
|
||||
*
|
||||
|
|
|
@ -192,7 +192,13 @@ class Hash {
|
|||
return false;
|
||||
}
|
||||
|
||||
$prop = isset($data[$attr]) ? ( is_bool($data[$attr]) ? (($data[$attr]) ? 'true' : 'false') : $data[$attr] ) : null;
|
||||
$prop = null;
|
||||
if (isset($data[$attr])) {
|
||||
$prop = $data[$attr];
|
||||
}
|
||||
if ($prop === true || $prop === false) {
|
||||
$prop = $prop ? 'true' : 'false';
|
||||
}
|
||||
|
||||
// Pattern matches and other operators.
|
||||
if ($op === '=' && $val && $val[0] === '/') {
|
||||
|
|
Loading…
Add table
Reference in a new issue