Skip to content

Commit

Permalink
Add draining state accessor and tests for it
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jun 22, 2024
1 parent 2b0f1a5 commit fa24d20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/php/io/streams/Buffer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ public function __construct($files, int $threshold) {
/** Returns buffer size */
public function size(): int { return $this->size; }

/** @return ?io.File */
public function file() { return $this->file; }
/** Returns the underlying file, if any */
public function file(): ?File { return $this->file; }

/** Returns whether this buffer is draining */
public function draining(): bool { return $this->draining; }

/**
* Write a string
Expand Down
2 changes: 2 additions & 0 deletions src/test/php/io/unittest/BufferTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ public function reset($length) {
public function cannot_write_after_draining_started() {
$fixture= new Buffer($this->temp, self::THRESHOLD);
$fixture->write('Test');
Assert::false($fixture->draining());

$fixture->read();
Assert::true($fixture->draining());
Assert::throws(IllegalStateException::class, fn() => $fixture->write('Test'));
}

Expand Down

0 comments on commit fa24d20

Please sign in to comment.