ILIAS  release_8 Revision v8.24
ilRandomTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5use PHPUnit\Framework\TestCase;
8
9class ilRandomTest extends TestCase
10{
11 public function testConstruct(): void
12 {
13 $this->assertInstanceOf(\ilRandom::class, new ilRandom());
14 }
15
19 public function testIntSuccessfully(int ...$arguments): void
20 {
21 $this->expectNotToPerformAssertions();
22
23 $random = new \ilRandom();
24 try {
25 $random->int(...$arguments);
26 } catch (Error $e) {
27 $this->fail('Expected no exception.');
28 }
29 }
30
31 public function testIntWithInvalidArguments(): void
32 {
33 $this->expectException(Error::class);
34 $random = new \ilRandom();
35
36 $random->int(10, 9);
37 }
38
39 public function testLogIfPossible(): void
40 {
41 $this->expectException(Error::class);
42
43 $logger = $this->getMockBuilder(\ilLogger::class)->disableOriginalConstructor()->getMock();
44 $logger->expects(self::once())->method('logStack')->with(\ilLogLevel::ERROR);
45 $logger->expects(self::once())->method('error');
46
47 $factory = $this->getMockBuilder(ilLoggerFactory::class)->disableOriginalConstructor()->getMock();
48 $factory->expects(self::once())->method('getComponentLogger')->with('rnd')->willReturn($logger);
49
50 $GLOBALS['DIC'] = new Container();
51 $GLOBALS['DIC']['ilLoggerFactory'] = static function () use ($factory): ilLoggerFactory {
52 return $factory;
53 };
54 $random = new \ilRandom();
55 $random->int(10, 9);
56
57 unset($GLOBALS['DIC']);
58 }
59
60 public function intArguments(): array
61 {
62 return [
63 'No arguments can be provided' => [],
64 'One argument can be provided' => [34],
65 '2 arguments can be provided' => [-20, 30],
66 'The limit is inclusive' => [8, 8]
67 ];
68 }
69}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
Provides fluid interface to LoggingServices.
testIntWithInvalidArguments()
testIntSuccessfully(int ... $arguments)
@dataProvider intArguments
Wrapper for generation of random numbers, strings, bytes.
$factory
Definition: metadata.php:75