mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
4f7a8f9752
From the [PHPUnit 8 release notes][1], the `TestCase` methods below now declare a `void` return type: - `setUpBeforeClass()` - `setUp()` - `assertPreConditions()` - `assertPostConditions()` - `tearDown()` - `tearDownAfterClass()` - `onNotSuccessfulTest()` [1]: https://phpunit.de/announcements/phpunit-8.html
64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
*/
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
class TaskSortingTest extends TestCase
|
|
{
|
|
public $collection;
|
|
|
|
protected function setUp() :void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->collection = collect([
|
|
['id' => 1, 'name' =>'pizza', 'order' => 9999],
|
|
['id' => 2, 'name' =>'pineapple', 'order' => 9999],
|
|
['id' => 3, 'name' =>'ethereum', 'order' => 9999],
|
|
['id' => 4, 'name' =>'bitcoin', 'order' => 9999],
|
|
['id' => 5, 'name' =>'zulu', 'order' => 9999],
|
|
['id' => 6, 'name' =>'alpha', 'order' => 9999],
|
|
['id' => 7, 'name' =>'ninja', 'order' => 9999],
|
|
]);
|
|
}
|
|
|
|
public function testSorting()
|
|
{
|
|
$index = 3;
|
|
$item = $this->collection->where('id', 7)->first();
|
|
|
|
$new_collection = $this->collection->reject(function ($task) use ($item) {
|
|
return $item['id'] == $task['id'];
|
|
});
|
|
|
|
$sorted_tasks = $new_collection->filter(function ($task, $key) use ($index) {
|
|
return $key < $index;
|
|
})->push($item)->merge($new_collection->filter(function ($task, $key) use ($index) {
|
|
return $key >= $index;
|
|
}))->map(function ($item, $key) {
|
|
$item['order'] = $key;
|
|
|
|
return $item;
|
|
});
|
|
|
|
$index_item = $sorted_tasks->splice($index, 1)->all();
|
|
|
|
$this->assertEquals($sorted_tasks->first()['name'], 'pizza');
|
|
$this->assertEquals($sorted_tasks->last()['name'], 'alpha');
|
|
$this->assertEquals($index_item[0]['name'], 'ninja');
|
|
}
|
|
}
|