GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ArrayRandWeightedTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A it_can_handle_an_empty_array() 0 4 1
A it_retrieves_a_value_from_the_array() 0 4 1
A it_is_safe_to_assume_the_result_is_weighted() 0 12 2
1
<?php
2
3
namespace Spatie\Test;
4
5
use function spatie\array_rand_weighted;
6
use PHPUnit\Framework\TestCase;
7
8
class ArrayRandWeightedTest extends TestCase
9
{
10
    protected $testArray = [
11
        'foo' => 1,
12
        'bar' => 1,
13
        'baz' => 4,
14
    ];
15
16
    /**
17
     * @test
18
     */
19
    public function it_can_handle_an_empty_array()
20
    {
21
        $this->assertNull(array_rand_weighted([]));
22
    }
23
24
    /**
25
     * @test
26
     */
27
    public function it_retrieves_a_value_from_the_array()
28
    {
29
        $this->assertContains(array_rand_weighted($this->testArray), array_keys($this->testArray));
30
    }
31
32
    /**
33
     * @test
34
     */
35
    public function it_is_safe_to_assume_the_result_is_weighted()
36
    {
37
        $results = [];
38
39
        for ($i = 0; $i < 100; ++$i) {
40
            $results[] = array_rand_weighted($this->testArray);
41
        }
42
43
        $resultCounts = array_count_values($results);
44
45
        $this->assertGreaterThan($resultCounts['foo'] + $resultCounts['bar'], $resultCounts['baz']);
46
    }
47
}
48