1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/tests/Unit/CollectionMergingTest.php

66 lines
1.6 KiB
PHP
Raw Normal View History

<?php
2020-09-14 13:11:46 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-09-14 13:11:46 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Unit;
use App\Utils\Traits\UserSessionAttributes;
use Illuminate\Support\Facades\Session;
use Tests\TestCase;
/**
* @test
*/
class CollectionMergingTest extends TestCase
{
use UserSessionAttributes;
2019-04-24 12:01:40 +02:00
public function setUp() :void
{
parent::setUp();
2019-03-27 10:38:28 +01:00
Session::start();
}
2019-09-09 04:19:19 +02:00
public function testUniqueValues()
{
$methods[] = [1 => 1];
$methods[] = [1 => 2];
$methods[] = [1 => 3];
$methods[] = [1 => 4];
$methods[] = [1 => 5];
$methods[] = [1 => 6];
$other_methods[] = [2 => 1];
$other_methods[] = [2 => 7];
$other_methods[] = [2 => 8];
$other_methods[] = [2 => 9];
$other_methods[] = [2 => 10];
$array = array_merge($methods, $other_methods);
$this->assertEquals(11, count($array));
$collection = collect($array);
$intersect = $collection->intersectByKeys($collection->flatten(1)->unique());
2019-09-09 04:19:19 +02:00
$this->assertEquals(10, $intersect->count());
2019-09-09 04:19:19 +02:00
$third_methods[] = [3 => 1];
$third_methods[] = [2 => 11];
$array = array_merge($array, $third_methods);
$collection = collect($array);
$intersect = $collection->intersectByKeys($collection->flatten(1)->unique());
$this->assertEquals(11, $intersect->count());
2019-09-09 04:19:19 +02:00
}
}