Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add *Stream and DoctrineHelper tests #560

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,27 @@
<code><![CDATA[new DefaultSelectSQLBuilder($abstractPlatform->reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]></code>
</InternalMethod>
</file>
<file src="tests/Unit/Store/DoctrineHelperTest.php">
<InternalMethod>
<code><![CDATA[new class extends Type {
/** @inheritdoc */
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return '';
}

public function getName(): string
{
return 'needed for older dbal versions';
}

public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed
{
return 'not a datetime';
}
}]]></code>
</InternalMethod>
</file>
<file src="tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php">
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$update1]]></code>
Expand Down
1 change: 1 addition & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"logs": {
"text": "infection.log",
"html": "infection.html",
"stryker": {
"report": "3.0.x"
}
Expand Down
32 changes: 14 additions & 18 deletions src/Store/ArrayStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,15 @@ public function close(): void
/** @return Traversable<Message> */
public function getIterator(): Traversable
{
if ($this->iterator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

return $this->iterator;
}

/** @return positive-int|0|null */
public function position(): int|null
{
if ($this->iterator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

if ($this->position === null) {
$this->iterator->key();
Expand All @@ -67,9 +63,7 @@ public function position(): int|null
*/
public function index(): int|null
{
if ($this->iterator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

if ($this->index === null) {
$this->iterator->key();
Expand All @@ -80,27 +74,21 @@ public function index(): int|null

public function next(): void
{
if ($this->iterator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

$this->iterator->next();
}

public function end(): bool
{
if ($this->iterator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

return !$this->iterator->valid();
}

public function current(): Message|null
{
if ($this->iterator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

return $this->iterator->current() ?: null;
}
Expand Down Expand Up @@ -134,4 +122,12 @@ private function createGenerator(array $messages): Generator
yield $message;
}
}

/** @psalm-assert !null $this->iterator */
private function assertNotClosed(): void
{
if ($this->iterator === null) {
throw new StreamClosed();
}
}
}
35 changes: 17 additions & 18 deletions src/Store/DoctrineDbalStoreStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,29 @@

public function next(): void
{
if ($this->result === null || $this->generator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

$this->generator->next();
}

public function end(): bool
{
if ($this->result === null || $this->generator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

return !$this->generator->valid();
}

public function current(): Message|null
{
if ($this->result === null || $this->generator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

return $this->generator->current() ?: null;
}

/** @return positive-int|0|null */
public function position(): int|null
{
if ($this->result === null || $this->generator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

if ($this->position === null) {
$this->generator->key();
Expand All @@ -93,9 +85,7 @@
/** @return positive-int|null */
public function index(): int|null
{
if ($this->result === null || $this->generator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

if ($this->index === null) {
$this->generator->key();
Expand All @@ -107,9 +97,7 @@
/** @return Traversable<Message> */
public function getIterator(): Traversable
{
if ($this->result === null || $this->generator === null) {
throw new StreamClosed();
}
$this->assertNotClosed();

return $this->generator;
}
Expand Down Expand Up @@ -146,4 +134,15 @@
->withHeaders($customHeaders);
}
}

/**
* @psalm-assert !null $this->result
* @psalm-assert !null $this->generator
*/
private function assertNotClosed(): void
{
if ($this->result === null || $this->generator === null) {

Check warning on line 144 in src/Store/DoctrineDbalStoreStream.php

View workflow job for this annotation

GitHub Actions / Mutation tests on diff (locked, 8.3, ubuntu-latest)

Escaped Mutant for Mutator "LogicalOr": --- Original +++ New @@ @@ */ private function assertNotClosed() : void { - if ($this->result === null || $this->generator === null) { + if ($this->result === null && $this->generator === null) { throw new StreamClosed(); } } }
throw new StreamClosed();
}
}
}
Loading
Loading