diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2021-04-08 17:15:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-08 17:15:15 +0300 |
commit | 2764ac9a8ba867e980406db8ba24d3859aa6261d (patch) | |
tree | 8473f2e02d0253854ac929dc50498bc2fdfd8af6 /tests | |
parent | 0b934c73b3cfb0143789c37d5e0833e08746951d (diff) | |
parent | 0cfa97e236a63f56c5997880e54ba04a428b41a9 (diff) |
Merge pull request #4912 from nextcloud/enhance/array-flat-map
Add an array_flat_map function
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Unit/FunctionsTest.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/Unit/FunctionsTest.php b/tests/Unit/FunctionsTest.php new file mode 100644 index 000000000..c128055c3 --- /dev/null +++ b/tests/Unit/FunctionsTest.php @@ -0,0 +1,65 @@ +<?php + +declare(strict_types=1); + +/* + * @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +namespace OCA\mail\tests\Unit; + +use ChristophWurst\Nextcloud\Testing\TestCase; +use function OCA\Mail\array_flat_map; + +class FunctionsTest extends TestCase { + public function testFlatMapEmpty(): void { + $map = function () { + }; + + $result = array_flat_map($map, []); + + self::assertEmpty($result); + } + + public function testFlatMap(): void { + $double = function ($x) { + return [$x, $x]; + }; + $data = [ + 1, + 2, + 3, + ]; + + $result = array_flat_map($double, $data); + + self::assertEquals( + [ + 1, + 1, + 2, + 2, + 3, + 3, + ], + $result + ); + } +} |