Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/static-code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: ${{ steps.cache-dir.outputs.COMPOSER_CACHE_DIR }}
key: ${{ github.workflow }}-PHP_${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: ${{ steps.globals.outputs.COMPOSER_CACHE_DIR }}
key: ${{ github.workflow }}-PHP_${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }}
Expand Down
10 changes: 9 additions & 1 deletion src/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
final readonly class Expectation implements Expectable
{
private Exporter $exporter;
public Exporter $exporter;

/**
* @param TValue $value
Expand All @@ -39,6 +39,14 @@ public function not(): NegatedExpectation
return new NegatedExpectation($this);
}

/**
* @return NullableExpectation<TValue>
*/
public function nullOr(): NullableExpectation
{
return new NullableExpectation($this);
}

/**
* @return self<TValue>
*/
Expand Down
31 changes: 17 additions & 14 deletions src/NegatedExpectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
*/
final readonly class NegatedExpectation implements Expectable
{
private Exporter $exporter;
/**
* @var TValue
*/
public mixed $value;

/**
* @param Expectation<TValue> $expectation
*/
public function __construct(
public Expectation $expectation,
) {
$this->exporter = new Exporter();
$this->value = $expectation->value;
}

/**
Expand All @@ -48,7 +51,7 @@ public function isArray(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isArray".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}

Expand All @@ -65,7 +68,7 @@ public function isBool(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isBool".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}

Expand All @@ -82,7 +85,7 @@ public function isFalse(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isFalse".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}

Expand All @@ -99,7 +102,7 @@ public function isFloat(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isFloat".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}

Expand All @@ -116,7 +119,7 @@ public function isInt(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isInt".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}

Expand All @@ -133,7 +136,7 @@ public function isIterable(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isIterable".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}

Expand All @@ -150,7 +153,7 @@ public function isNull(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isNull".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}

Expand All @@ -167,7 +170,7 @@ public function isNumeric(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isNumeric".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}

Expand All @@ -184,7 +187,7 @@ public function isObject(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isObject".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}

Expand All @@ -201,7 +204,7 @@ public function isScalar(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isScalar".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}

Expand All @@ -218,7 +221,7 @@ public function isString(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isString".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}

Expand All @@ -235,7 +238,7 @@ public function isTrue(?string $message = null): self

throw new ExpectationFailedException(
$message ?? 'Value "{value}" is not expected to pass the negated expectation for method "isTrue".',
['value' => $this->exporter->exportValue($this->expectation->value)],
['value' => $this->expectation->exporter->exportValue($this->value)],
);
}
}
Loading
Loading