ILIAS  release_8 Revision v8.24
ShuffleTransformationTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
28use PHPUnit\Framework\TestCase;
30
31class ShuffleTransformationTest extends TestCase
32{
33 public function testTransformResultSuccess(): void
34 {
35 $seed = 0;
36 $value = ['Donec', 'at', 'pede', 'Phasellus', 'purus', 'Nulla', 'facilisis', 'risus', 'a', 'rhoncus', 'fermentum', 'tellus', 'tellus', 'lacinia', 'purus', 'et', 'dictum', 'nunc', 'justo', 'sit', 'amet', 'elit'];
37 $expected = $this->shuffleWithSeed($value, $seed);
38 $seedMock = $this->getMockBuilder(Seed::class)->getMock();
39 $seedMock->expects(self::once())->method('seedRandomGenerator')->willReturnCallback(static function () use ($seed): void {
40 mt_srand($seed);
41 });
42
43 $result = (new ShuffleTransformation($seedMock))->transform($value);
44 $this->assertEquals($expected, $result);
45 }
46
47 public function testTransformResultFailure(): void
48 {
49 $this->expectException(ConstraintViolationException::class);
50 $seedMock = $this->getMockBuilder(Seed::class)->getMock();
51 $seedMock->expects(self::never())->method('seedRandomGenerator');
52
53 $result = (new ShuffleTransformation($seedMock))->transform('im no array');
54 }
55
56 private function shuffleWithSeed(array $array, int $seed): array
57 {
58 mt_srand($seed);
59 shuffle($array);
60
61 return $array;
62 }
63}
Signals that a result contains no value.
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Error.php:18
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:17
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...