ILIAS  trunk Revision v11.0_alpha-2658-ge2404539063
OrderTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
27 class orderTest extends TestCase
28 {
29  public function testFactory(): Order
30  {
31  $f = new ILIAS\Data\Factory();
32  $order = $f->order('subject', Order::ASC);
33  $this->assertInstanceOf(Order::class, $order);
34  return $order;
35  }
36 
37  #[\PHPUnit\Framework\Attributes\Depends('testFactory')]
38  public function testValues(Order $order): void
39  {
40  $this->assertEquals(
41  ['subject' => Order::ASC],
42  $order->get()
43  );
44  }
45 
46  #[\PHPUnit\Framework\Attributes\Depends('testFactory')]
47  public function testAppend(Order $order): Order
48  {
49  $order = $order->append('sub2', Order::DESC);
50  $this->assertEquals(
51  [
52  'subject' => Order::ASC,
53  'sub2' => Order::DESC
54  ],
55  $order->get()
56  );
57  return $order;
58  }
59 
60  #[\PHPUnit\Framework\Attributes\Depends('testFactory')]
61  public function testJoinOne(Order $order): void
62  {
63  $this->assertEquals(
64  'SORT BY subject ASC',
65  $order->join(
66  'SORT BY',
67  function ($pre, $k, $v) {
68  return "$pre $k $v";
69  }
70  )
71  );
72  }
73 
74  #[\PHPUnit\Framework\Attributes\Depends('testAppend')]
75  public function testJoinMore(Order $order): void
76  {
77  $this->assertEquals(
78  'Sorting subject ASC, sub2 DESC,',
79  $order->join(
80  'Sorting',
81  function ($pre, $k, $v) {
82  return "$pre $k $v,";
83  }
84  )
85  );
86  }
87 
88  #[\PHPUnit\Framework\Attributes\Depends('testFactory')]
89  public function testInvalidDirection(Order $order): void
90  {
91  $this->expectException(TypeError::class);
92  $order = $order->append('sub3', -1);
93  }
94 
95  #[\PHPUnit\Framework\Attributes\Depends('testFactory')]
96  public function testInvalidSubject(Order $order): void
97  {
98  $this->expectException(InvalidArgumentException::class);
99  $order = $order->append('subject', Order::ASC);
100  }
101 }
testFactory()
Definition: OrderTest.php:29
join($init, callable $fn)
Definition: Order.php:75
testJoinMore(Order $order)
Definition: OrderTest.php:75
testValues(Order $order)
Definition: OrderTest.php:38
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:28
testJoinOne(Order $order)
Definition: OrderTest.php:61
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
append(string $subject, string $direction)
Definition: Order.php:58
testInvalidSubject(Order $order)
Definition: OrderTest.php:96
testInvalidDirection(Order $order)
Definition: OrderTest.php:89
testAppend(Order $order)
Definition: OrderTest.php:47