Skip to content

Commit

Permalink
Test: Hash::extract with string-attr conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
o0h committed Feb 7, 2018
1 parent 2787d60 commit 4f76c70
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tests/TestCase/Utility/HashTest.php
Expand Up @@ -1422,23 +1422,33 @@ public function testExtractMatchesNull()
}

/**
* Test extracting value-zero contained data based on attributes with string
* Test extracting attributes with string
*
* @return void
*/
public function testExtractAttributeStringWithDataContainsZero()
public function testExtractAttributeString()
{
$data = [
['value' => '0'],
['value' => 0],
['value' => 3],
['value' => 'string-value'],
['value' => new Time('2010-01-05 01:23:45')],
];

$expected = [
['value' => 'string-value'],
];
// check _matches does not work as `0 == 'string-value'`
$expected = [$data[2]];
$result = Hash::extract($data, '{n}[value=string-value]');
$this->assertSame($expected, $result);

// check _matches work with object implements __toString()
$expected = [$data[3]];
$result = Hash::extract($data, sprintf('{n}[value=%s]', $data[3]['value']));
$this->assertSame($expected, $result);

// check _matches does not work as `3 == '3 people'`
$unexpected = $data[1];
$result = Hash::extract($data, '{n}[value=3people]');
$this->assertNotContains($unexpected, $result);
}

/**
Expand Down

0 comments on commit 4f76c70

Please sign in to comment.