Skip to content

Commit

Permalink
Use self:: instead of $this->
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Nov 25, 2023
1 parent 7ad8c91 commit dd0dc4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
26 changes: 13 additions & 13 deletions tests/DecodeJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public function it_rejects_invalid_json(): void
#[Test]
public function it_decodes_to_an_object_by_default(): void
{
$this->assertIsObject(JSON::decode('{"foo": "bar"}'));
self::assertIsObject(JSON::decode('{"foo": "bar"}'));
}

#[Test]
public function it_forces_an_array(): void
{
$this->assertIsArray(JSON::decode('{"foo": "bar"}', true));
self::assertIsArray(JSON::decode('{"foo": "bar"}', true));
}

#[Test]
Expand All @@ -41,9 +41,9 @@ public function it_decodes_large_integers_to_string(): void
$object = JSON::decode('{"large": 9223372036854775808}');
assert(is_object($object));

$this->assertObjectHasProperty('large', $object);
$this->assertIsString($object->large);
$this->assertSame('9223372036854775808', $object->large);
self::assertObjectHasProperty('large', $object);
self::assertIsString($object->large);
self::assertSame('9223372036854775808', $object->large);
}

#[Test]
Expand All @@ -52,15 +52,15 @@ public function it_decodes_a_file(): void
$path = __DIR__.'/valid.json';
assert(file_exists($path));

$this->assertIsObject(Json::decodeFile($path));
self::assertIsObject(Json::decodeFile($path));
}

#[Test]
public function it_rejects_an_unreadable_file(): void
{
$path = __DIR__.'/non-existing.json';

$this->expectException(UnexpectedValueException::class);
self::expectException(UnexpectedValueException::class);
assert(!file_exists($path));

Json::decodeFile($path);
Expand All @@ -72,14 +72,14 @@ public function it_rejects_a_file_with_invalid_json(): void
$path = __DIR__.'/invalid.json';
assert(file_exists($path));

$this->expectException(UnexpectedValueException::class);
self::expectException(UnexpectedValueException::class);
Json::decodeFile($path);
}

#[Test]
public function it_rejects_a_directory(): void
{
$this->expectException(UnexpectedValueException::class);
self::expectException(UnexpectedValueException::class);
Json::decodeFile(__DIR__);
}

Expand All @@ -90,10 +90,10 @@ public function it_resolves_links(): void
$symlinkPath = __DIR__.'/'.__FUNCTION__.'.json';

try {
$this->assertNotFalse(symlink($path, $symlinkPath));
$this->assertTrue(is_link($symlinkPath));
self::assertNotFalse(symlink($path, $symlinkPath));
self::assertTrue(is_link($symlinkPath));

$this->assertIsObject(Json::decodeFile($symlinkPath));
self::assertIsObject(Json::decodeFile($symlinkPath));
} finally {
unlink($symlinkPath);
}
Expand All @@ -104,6 +104,6 @@ public function it_resolves_relative_links(): void
{
$path = __DIR__.'/symlinked/symlinked.json';

$this->assertIsObject(Json::decodeFile($path));
self::assertIsObject(Json::decodeFile($path));
}
}
8 changes: 4 additions & 4 deletions tests/EncodeJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ class EncodeJsonTest extends TestCase
#[Test]
public function it_does_not_escape_slashes(): void
{
$this->assertSame('{"slash":"/"}', Json::encode(['slash' => '/']));
self::assertSame('{"slash":"/"}', Json::encode(['slash' => '/']));
}

#[Test]
public function it_does_not_escape_unicode(): void
{
$this->assertSame('{"emoji":"πŸš€"}', Json::encode(['emoji' => 'πŸš€']));
self::assertSame('{"emoji":"πŸš€"}', Json::encode(['emoji' => 'πŸš€']));
}

#[Test]
public function it_rejects_invalid_resources(): void
{
$this->expectException(UnexpectedValueException::class);
self::expectException(UnexpectedValueException::class);

// The point is that resources cannot be encoded, not what's in the file :)
Json::encode(fopen(__DIR__.'/valid.json', 'rb'));
Expand All @@ -44,6 +44,6 @@ public function it_pretty_prints(): void
}
PRETTY;

$this->assertSame($expected, Json::pretty(['pretty' => 'print']));
self::assertSame($expected, Json::pretty(['pretty' => 'print']));
}
}

0 comments on commit dd0dc4b

Please sign in to comment.