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

88 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Unit;
use App\Models\PaymentTerm;
use App\Utils\Traits\UserSessionAttributes;
use Illuminate\Support\Facades\Session;
use Tests\TestCase;
/**
* @test
* @covers App\Http\ViewComposers\TranslationComposer
*/
class CollectionMergingTest extends TestCase
{
use UserSessionAttributes;
public function setUp()
{
parent::setUp();
2019-03-27 10:38:28 +01:00
Session::start();
$this->setCurrentCompanyId(1);
2019-03-27 10:38:28 +01:00
$this->terms = PaymentTerm::all();
}
public function testBlankCollectionReturned()
{
$this->assertEquals($this->terms->count(), 0);
}
public function testMergingCollection()
{
$payment_terms = collect(unserialize(CACHED_PAYMENT_TERMS));
$new_terms = $this->terms->map(function($term) {
return $term['num_days'];
});
$payment_terms->merge($new_terms);
$this->assertEquals($payment_terms->count(), 8);
}
public function testSortingCollection()
{
$payment_terms = collect(unserialize(CACHED_PAYMENT_TERMS));
$new_terms = $this->terms->map(function($term) {
return $term['num_days'];
});
$payment_terms->merge($new_terms)
->sortBy('num_days')
->values()
->all();
$term = $payment_terms->first();
$this->assertEquals($term['num_days'], 0);
}
public function testSortingCollectionLast()
{
$payment_terms = collect(unserialize(CACHED_PAYMENT_TERMS));
$new_terms = $this->terms->map(function($term) {
return $term['num_days'];
});
$payment_terms->merge($new_terms)
->sortBy('num_days')
->values()
->all();
$term = $payment_terms->last();
$this->assertEquals($term['num_days'], 90);
}
}