ILIAS  release_8 Revision v8.24
OrderTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6use PHPUnit\Framework\TestCase;
7
11class orderTest extends TestCase
12{
13 public function testFactory(): Order
14 {
15 $f = new ILIAS\Data\Factory();
16 $order = $f->order('subject', Order::ASC);
17 $this->assertInstanceOf(Order::class, $order);
18 return $order;
19 }
20
24 public function testValues(Order $order): void
25 {
26 $this->assertEquals(
27 ['subject' => Order::ASC],
28 $order->get()
29 );
30 }
31
35 public function testAppend(Order $order): Order
36 {
37 $order = $order->append('sub2', Order::DESC);
38 $this->assertEquals(
39 [
40 'subject' => Order::ASC,
41 'sub2' => Order::DESC
42 ],
43 $order->get()
44 );
45 return $order;
46 }
47
51 public function testJoinOne(Order $order): void
52 {
53 $this->assertEquals(
54 'SORT BY subject ASC',
55 $order->join(
56 'SORT BY',
57 function ($pre, $k, $v) {
58 return "$pre $k $v";
59 }
60 )
61 );
62 }
63
67 public function testJoinMore(Order $order): void
68 {
69 $this->assertEquals(
70 'Sorting subject ASC, sub2 DESC,',
71 $order->join(
72 'Sorting',
73 function ($pre, $k, $v) {
74 return "$pre $k $v,";
75 }
76 )
77 );
78 }
79
83 public function testInvalidDirection(Order $order): void
84 {
85 $this->expectException(TypeError::class);
86 $order = $order->append('sub3', -1);
87 }
88
92 public function testInvalidSubject(Order $order): void
93 {
94 $this->expectException(InvalidArgumentException::class);
95 $order = $order->append('subject', Order::ASC);
96 }
97}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Builds data types.
Definition: Factory.php:21
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:13
append(string $subject, string $direction)
Definition: Order.php:42
join($init, callable $fn)
Definition: Order.php:59
testJoinOne(Order $order)
@depends testFactory
Definition: OrderTest.php:51
testAppend(Order $order)
@depends testFactory
Definition: OrderTest.php:35
testInvalidSubject(Order $order)
@depends testFactory
Definition: OrderTest.php:92
testJoinMore(Order $order)
@depends testAppend
Definition: OrderTest.php:67
testInvalidDirection(Order $order)
@depends testFactory
Definition: OrderTest.php:83
testValues(Order $order)
@depends testFactory
Definition: OrderTest.php:24
testFactory()
Definition: OrderTest.php:13