2019-02-17 11:34:46 +01:00
|
|
|
<?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;
|
|
|
|
|
2019-04-24 12:01:40 +02:00
|
|
|
public function setUp() :void
|
2019-02-17 11:34:46 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-03-27 10:38:28 +01:00
|
|
|
|
2019-02-17 11:34:46 +01:00
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->setCurrentCompanyId(1);
|
|
|
|
|
2019-03-27 10:38:28 +01:00
|
|
|
$this->terms = PaymentTerm::all();
|
2019-02-17 11:34:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|