This repository has been archived on 2020-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
ext-collections/tests/005-associate.phpt

24 lines
714 B
Plaintext
Raw Permalink Normal View History

2018-03-26 05:25:00 +00:00
--TEST--
Test Collection::associate() and Collection::associateTo().
--FILE--
<?php
$array = ['foo' => 'bar', 34 => 5];
$collection = Collection::init($array)
->associate(function ($value, $key) {
return new Pair($value, $key);
});
2018-08-28 14:11:09 +00:00
if ($collection->toArray() != array_flip($array)) {
echo 'Collection::associate() failed.', PHP_EOL;
2018-08-28 14:11:09 +00:00
}
2018-03-26 05:25:00 +00:00
$array1 = ['baz' => 1];
$collection1 = Collection::init($array1);
$array2 = $collection->associateTo($collection1,
function ($value, $key) {
return new Pair($key, $value);
})->toArray();
2018-08-28 14:11:09 +00:00
if ($array2 != $array1 + array_flip($array) || $collection1->toArray() != $array2) {
2018-03-26 05:25:00 +00:00
echo 'Collection::associateTo() failed.', PHP_EOL;
2018-08-28 14:11:09 +00:00
}
2018-03-26 05:25:00 +00:00
?>
--EXPECT--