Skip to content

Commit

Permalink
a few updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes committed Sep 6, 2024
1 parent dc19b58 commit 99d515f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/SonsOfPHP/Component/Assert/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ protected static function valueToString(mixed $value): string
'DateTime' => sprintf('%s: %s', $value::class, $value->format('c')),
default => $value instanceof Stringable ? (string) $value : $debugType,
},
default => $type,
default => $debugType,
};
}

Expand Down
27 changes: 23 additions & 4 deletions src/SonsOfPHP/Component/Assert/Tests/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function __toString(): string
return 'Sons of PHP';
}
}];
yield ['resource (stream)', fopen('php://memory', 'w')];
}

public static function validStringProvider(): Generator
Expand Down Expand Up @@ -110,6 +111,11 @@ public static function validEmptyProvider(): Generator
yield [''];
}

public static function validResourceProvider(): Generator
{
yield [fopen('php://memory', 'w')];
}

public static function validNullProvider(): Generator
{
yield [null];
Expand Down Expand Up @@ -162,6 +168,13 @@ public function testItsExceptionClassIsMutable(): void
$this->assertSame(Exception::class, Assert::getExceptionClass());
}

#[DataProvider('valueToStringProvider')]
public function testItCanConvertValueToString(mixed $expected, mixed $value): void
{
$method = new ReflectionMethod(Assert::class, 'valueToString');
$this->assertSame($expected, $method->invoke(null, $value));
}

#[DataProvider('validIntProvider')]
#[DataProvider('validFloatProvider')]
public function testItCanIdentifyNotString(mixed $value): void
Expand Down Expand Up @@ -425,10 +438,16 @@ public function testItWillThrowExceptionForSameWithSame(mixed $value, mixed $val
Assert::same($value, $value2);
}

#[DataProvider('valueToStringProvider')]
public function testItCanConvertValueToString(mixed $expected, mixed $value): void
#[DataProvider('validResourceProvider')]
public function testItCanIdentifyResource(mixed $value): void
{
$method = new ReflectionMethod(Assert::class, 'valueToString');
$this->assertSame($expected, $method->invoke(null, $value));
$this->assertTrue(Assert::resource($value));
}

#[DataProvider('validStringProvider')]
public function testItWillThrowExceptionForResourceWithResource(mixed $value): void
{
$this->expectException(InvalidArgumentException::class);
Assert::resource($value);
}
}

0 comments on commit 99d515f

Please sign in to comment.