Skip to content

Commit

Permalink
feat(Testing): Context getExpectation createState property is optiona…
Browse files Browse the repository at this point in the history
…l due the fact its not needed
  • Loading branch information
pionl committed Dec 23, 2022
1 parent ba05e44 commit 7a942e0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@

final class ContextServiceContractGetExpectation
{
public readonly Closure $createState;

/**
* @param Closure(AbstractContext, Closure, self):void|null $hook
*/
public function __construct(
public readonly ContextValueContract $return,
public readonly AbstractContext $context,
public readonly Closure $createState,
?Closure $createState = null,
public readonly ?Closure $hook = null,
) {
$this->createState = $createState ?? static function () {
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ public function generateData(): array
checkResult: true,
expectedResult: $value
),
new AssertExpectationEntity(
methodName: 'get',
createAssert: fn () => new ContextServiceContractAssert(get: [
new ContextServiceContractGetExpectation(
return: $value,
context: $context,
hook: function (
AbstractContext $context,
Closure $createState,
ContextServiceContractGetExpectation $expectation
) use ($value): void {
$this->assertSame($value, $createState('test'));
}
),
]),
call: fn (ContextServiceContractAssert $assert) => $assert->get(
context: $context,
createState: function (string $string) use ($value): TestValue {
$this->assertEquals(expected: 'test', actual: $string);
return $value;
}
),
checkResult: true,
expectedResult: $value
),
new AssertExpectationEntity(
methodName: 'is',
createAssert: fn () => new ContextServiceContractAssert(is: [
Expand Down

0 comments on commit 7a942e0

Please sign in to comment.