• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NexusPHP / tachycardia / 6604137970

22 Oct 2023 01:30PM UTC coverage: 98.325% (-1.7%) from 100.0%
6604137970

Pull #12

github

web-flow
Merge 86538c263 into 4aae83e31
Pull Request #12: feature: Update to PHPUnit 10

411 of 418 new or added lines in 30 files covered. (98.33%)

411 of 418 relevant lines covered (98.33%)

8.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/src/SlowTest/SlowTestCollection.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Nexus Tachycardia.
7
 *
8
 * (c) 2021 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Nexus\PHPUnit\Tachycardia\SlowTest;
15

16
/**
17
 * @internal
18
 *
19
 * @implements \IteratorAggregate<int, SlowTest>
20
 */
21
final class SlowTestCollection implements \Countable, \IteratorAggregate
22
{
23
    /**
24
     * @var array<string, SlowTest>
25
     */
26
    private array $slowTests = [];
27

28
    /**
29
     * @phpstan-impure
30
     */
31
    public function push(SlowTest $slowTest): void
32
    {
33
        $id = $slowTest->test()->id();
16✔
34

35
        if (isset($this->slowTests[$id])) {
16✔
36
            $prev = $this->slowTests[$id];
2✔
37

38
            if ($slowTest->testTime()->isLessThan($prev->testTime())) {
2✔
39
                return;
2✔
40
            }
41
        }
42

43
        $this->slowTests[$id] = $slowTest;
16✔
44
    }
45

46
    /**
47
     * @phpstan-assert-if-true array{} $this->slowTests
48
     */
49
    public function isEmpty(): bool
50
    {
51
        return [] === $this->slowTests;
14✔
52
    }
53

54
    /**
55
     * @phpstan-impure
56
     *
57
     * @throws \RuntimeException
58
     */
59
    public function pop(): SlowTest
60
    {
61
        if ($this->isEmpty()) {
4✔
62
            throw new \RuntimeException('Collection is empty.');
2✔
63
        }
64

65
        return array_pop($this->slowTests);
4✔
66
    }
67

68
    /**
69
     * @return array<int, SlowTest>
70
     */
71
    public function asArray(): array
72
    {
73
        $slowTests = array_values($this->slowTests);
10✔
74

75
        usort($slowTests, static function (SlowTest $one, SlowTest $two): int {
10✔
76
            $durationOne = $one->testTime();
2✔
77
            $durationTwo = $two->testTime();
2✔
78

79
            if ($durationOne->isLessThan($durationTwo)) {
2✔
80
                return 1;
2✔
81
            }
82

83
            if ($durationOne->isGreaterThan($durationTwo)) {
2✔
84
                return -1;
2✔
85
            }
86

NEW
87
            return 0;
×
88
        });
10✔
89

90
        return $slowTests;
10✔
91
    }
92

93
    public function count(): int
94
    {
95
        return \count($this->slowTests);
10✔
96
    }
97

98
    public function getIterator(): SlowTestCollectionIterator
99
    {
100
        return new SlowTestCollectionIterator($this);
2✔
101
    }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc