From 4f76c707bed6fa061f2b116df5ead765ec2e3804 Mon Sep 17 00:00:00 2001 From: Hideki Kinjyo Date: Wed, 7 Feb 2018 09:44:36 +0900 Subject: [PATCH] Test: Hash::extract with string-attr conditions --- tests/TestCase/Utility/HashTest.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/TestCase/Utility/HashTest.php b/tests/TestCase/Utility/HashTest.php index 68a3a9d72f4..8cb2ae1e884 100644 --- a/tests/TestCase/Utility/HashTest.php +++ b/tests/TestCase/Utility/HashTest.php @@ -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); } /**