~fkooman/vpn-server-api

ref: 453cda58bae0131116fbab4e4fc686d867e87ade vpn-server-api/tests/TestRandom.php -rw-r--r-- 868 bytes
453cda58François Kooman allow configuring the log format for log entries to syslog, also allow logging originating client IP 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

/*
 * eduVPN - End-user friendly VPN.
 *
 * Copyright: 2016-2019, The Commons Conservancy eduVPN Programme
 * SPDX-License-Identifier: AGPL-3.0+
 */

namespace LC\Server\Tests;

use LC\Common\RandomInterface;
use RuntimeException;

class TestRandom implements RandomInterface
{
    /** @var array */
    private $randomData;

    /** @var int */
    private $randomCount = 0;

    /**
     * @param array<string> $randomData
     */
    public function __construct(array $randomData)
    {
        $this->randomData = $randomData;
    }

    /**
     * @param int $length
     *
     * @return string
     */
    public function get($length)
    {
        if (!\array_key_exists($this->randomCount, $this->randomData)) {
            throw new RuntimeException('no more "random" data');
        }

        return $this->randomData[$this->randomCount++];
    }
}