Skip to content

Commit

Permalink
ignore constructor in property expectations (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonPurvis authored Sep 16, 2024
1 parent 0cc9ebc commit fef0b37
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Expectations/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@
expect(property_exists($this->value, 'tries'))->toBeTrue()
->and((new ReflectionClass($this->value)) // @phpstan-ignore-line
->getProperty('tries')
->getValue(new $this->value)) // @phpstan-ignore-line
->getValue((new ReflectionClass($this->value))->newInstanceWithoutConstructor())) // @phpstan-ignore-line
->toBeGreaterThan(1)
);

expect()->extend(
'toHaveRetryInterval',
fn (): Expectation => // @phpstan-ignore-next-line
expect(property_exists($this->value, 'retryInterval'))->toBeTrue()
->and((new ReflectionClass($this->value)) // @phpstan-ignore-line
->getProperty('retryInterval')
->getValue((new ReflectionClass($this->value))->newInstanceWithoutConstructor())) // @phpstan-ignore-line
->toBeGreaterThan(0)
);

expect()->extend(
Expand All @@ -38,7 +42,7 @@
expect(property_exists($this->value, 'useExponentialBackoff'))->toBeTrue()
->and((new ReflectionClass($this->value)) // @phpstan-ignore-line
->getProperty('useExponentialBackoff')
->getValue(new $this->value)) // @phpstan-ignore-line
->getValue((new ReflectionClass($this->value))->newInstanceWithoutConstructor())) // @phpstan-ignore-line
->toBeTrue()
);

Expand All @@ -48,6 +52,6 @@
expect(property_exists($this->value, 'throwOnMaxTries'))->toBeTrue()
->and((new ReflectionClass($this->value)) // @phpstan-ignore-line
->getProperty('throwOnMaxTries')
->getValue(new $this->value)) // @phpstan-ignore-line
->getValue((new ReflectionClass($this->value))->newInstanceWithoutConstructor())) // @phpstan-ignore-line
->toBeTrue()
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

class ToBeTriedAgainOnFailure extends Request
{
public function __construct(
public string $test
) {}

/**
* Define the HTTP method
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

class ToHaveRetryInterval extends Request
{
public function __construct(
public string $test
) {}

/**
* Define the HTTP method
*/
Expand Down
4 changes: 4 additions & 0 deletions tests/Fixtures/Arch/ToThrowOnMaxTries/ToThrowOnMaxTries.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

class ToThrowOnMaxTries extends Request
{
public function __construct(
public string $test
) {}

/**
* Define the HTTP method
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

class ToUseExponentialBackoff extends Request
{
public function __construct(
public string $test
) {}

/**
* Define the HTTP method
*/
Expand Down

0 comments on commit fef0b37

Please # to comment.