Skip to content

Commit

Permalink
used get_debug_type()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 8, 2023
1 parent 78555c7 commit 869cb00
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ public static function type(string|object $type, mixed $value, ?string $descript
'int', 'integer', 'null', 'object', 'resource', 'scalar', 'string', ], true)
) {
if (!("is_$type")($value)) {
self::fail(self::describe(gettype($value) . " should be $type", $description));
self::fail(self::describe(get_debug_type($value) . " should be $type", $description));
}
} elseif (!$value instanceof $type) {
$actual = is_object($value) ? $value::class : gettype($value);
$actual = get_debug_type($value);
$type = is_object($type) ? $type::class : $type;
self::fail(self::describe("$actual should be instance of $type", $description));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private function prepareTestData(\ReflectionMethod $method, array $dataprovider)

foreach ($res as $k => $set) {
if (!is_array($set)) {
$type = is_object($set) ? $set::class : gettype($set);
$type = get_debug_type($set);
throw new TestCaseException("Data provider $provider() item '$k' must be an array, $type given.");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Framework/Assert.type.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $cases = [
['STDCLASS', new stdClass],
['x', new stdClass, 'stdClass should be instance of x'],
['Int', new stdClass, 'stdClass should be instance of Int'],
['int', new stdClass, 'object should be int'],
['int', new stdClass, 'stdClass should be int'],
['array', []],
['bool', true],
['callable', function () {}],
Expand Down
4 changes: 2 additions & 2 deletions tests/Framework/Dumper.dumpException.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ $cases = [
'Failed: SimpleXMLElement(#%a%) should be truthy' => function () { Assert::truthy(new SimpleXMLElement('<xml></xml>')); },
'Failed: stdClass(#%a%) should be stdClass(#%a%)' => function () { Assert::same(new stdClass, new stdClass); },
'Failed: null should not be null' => function () { Assert::notSame(null, null); },
'Failed: boolean should be instance of x' => function () { Assert::type('x', true); },
'Failed: resource should be int' => function () { Assert::type('int', fopen(__FILE__, 'r')); },
'Failed: bool should be instance of x' => function () { Assert::type('x', true); },
'Failed: resource (stream) should be int' => function () { Assert::type('int', fopen(__FILE__, 'r')); },
"Failed: 'Hello\\n\nWorld' should match\n ... 'Hello'" => function () { Assert::match('%a%', "Hello\nWorld"); },
"Failed: '...xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' should be \n ... '...xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'" => function () { Assert::same(str_repeat('x', 100), str_repeat('x', 120)); },
"Failed: '...xxxxxxxxxxxxxxxxxxxxxxxxxxx****************************************' should be \n ... '...xxxxxxxxxxxxxxxxxxxxxxxxxxx'" => function () { Assert::same(str_repeat('x', 30), str_repeat('x', 30) . str_repeat('*', 40)); },
Expand Down
4 changes: 2 additions & 2 deletions tests/Framework/Expect.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Assert::same("type('string'),match('%d%')", $expectation->dump());

Assert::exception(function () use ($expectation) {
$expectation->__invoke(123);
}, Tester\AssertException::class, 'integer should be string');
}, Tester\AssertException::class, 'int should be string');

Assert::noError(function () use ($expectation) {
$expectation->__invoke('123');
Expand All @@ -47,7 +47,7 @@ Assert::same("type('string'),match('%d%')", $expectation->dump());

Assert::exception(function () use ($expectation) {
$expectation->__invoke(123);
}, Tester\AssertException::class, 'integer should be string');
}, Tester\AssertException::class, 'int should be string');

Assert::noError(function () use ($expectation) {
$expectation->__invoke('123');
Expand Down

0 comments on commit 869cb00

Please sign in to comment.