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

azjezz / psl / 22520865518

28 Feb 2026 12:36PM UTC coverage: 97.768% (+0.2%) from 97.532%
22520865518

Pull #586

github

azjezz
more tests

Signed-off-by: azjezz <azjezz@protonmail.com>
Pull Request #586: add more tests

16 of 16 new or added lines in 4 files covered. (100.0%)

20 existing lines in 13 files now uncovered.

7492 of 7663 relevant lines covered (97.77%)

43.46 hits per line

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

90.48
/src/Psl/Channel/Internal/UnboundedChannelState.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Channel\Internal;
6

7
use Psl\Channel\ChannelInterface;
8
use Psl\Channel\Exception;
9
use Revolt\EventLoop\Suspension;
10

11
use function array_shift;
12
use function count;
13

14
/**
15
 * @template T
16
 *
17
 * @internal
18
 */
19
final class UnboundedChannelState implements ChannelInterface
20
{
21
    /**
22
     * @var list<Suspension<mixed>>
23
     */
24
    private array $waitingForMessage = [];
25

26
    /**
27
     * @var array<array-key, T>
28
     */
29
    private array $messages = [];
30

31
    private bool $closed = false;
32

33
    /**
34
     * @param Suspension<mixed> $suspension
35
     */
36
    public function waitForMessage(Suspension $suspension): void
37
    {
38
        $this->waitingForMessage[] = $suspension;
48✔
39
    }
40

41
    /**
42
     * @return null
43
     *
44
     * @psalm-mutation-free
45
     */
46
    #[\Override]
47
    public function getCapacity(): null
48
    {
49
        return null;
1✔
50
    }
51

52
    /**
53
     * @inheritDoc
54
     */
55
    #[\Override]
56
    public function close(): void
57
    {
58
        $this->closed = true;
40✔
59

60
        $suspensions = $this->waitingForMessage;
40✔
61
        $this->waitingForMessage = [];
40✔
62
        foreach ($suspensions as $suspension) {
40✔
UNCOV
63
            $suspension->throw(Exception\ClosedChannelException::forReceiving());
×
64
        }
65
    }
66

67
    /**
68
     * @psalm-mutation-free
69
     */
70
    #[\Override]
71
    public function isClosed(): bool
72
    {
73
        return $this->closed;
2✔
74
    }
75

76
    /**
77
     * @return int<0, max>
78
     *
79
     * @psalm-mutation-free
80
     */
81
    #[\Override]
82
    public function count(): int
83
    {
84
        return count($this->messages);
1✔
85
    }
86

87
    /**
88
     * @psalm-mutation-free
89
     */
90
    #[\Override]
91
    public function isFull(): bool
92
    {
93
        return false;
1✔
94
    }
95

96
    /**
97
     * @psalm-mutation-free
98
     */
99
    #[\Override]
100
    public function isEmpty(): bool
101
    {
102
        return !$this->messages;
1✔
103
    }
104

105
    /**
106
     * @param T $message
107
     *
108
     * @throws Exception\ClosedChannelException If the channel is closed.
109
     * @throws Exception\FullChannelException If the channel is full.
110
     */
111
    public function send(mixed $message): void
112
    {
113
        if ($this->closed) {
51✔
UNCOV
114
            throw Exception\ClosedChannelException::forSending();
×
115
        }
116

117
        $this->messages[] = $message;
51✔
118
        $suspension = array_shift($this->waitingForMessage);
51✔
119
        $suspension?->resume(null);
51✔
120
    }
121

122
    /**
123
     * @throws Exception\ClosedChannelException If the channel is closed, and there's no more messages to receive.
124
     * @throws Exception\EmptyChannelException If the channel is empty.
125
     *
126
     * @return T
127
     */
128
    public function receive(): mixed
129
    {
130
        if (!$this->messages) {
49✔
131
            if ($this->closed) {
48✔
132
                throw Exception\ClosedChannelException::forReceiving();
38✔
133
            }
134

135
            throw Exception\EmptyChannelException::create();
48✔
136
        }
137

138
        return array_shift($this->messages);
49✔
139
    }
140
}
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