Skip to content

Commit

Permalink
refactor: add typed on private property based on assigns (#1200)
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Jan 10, 2025
1 parent 77af92d commit 3aa8d30
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"require-dev": {
"phpunit/phpunit": "^10.1",
"mockery/mockery": "^1.5",
"spiral/files": "^3.14.9",
"spiral/files": "^3.15",
"nyholm/psr7": "^1.5",
"vimeo/psalm": "^5.9"
},
Expand Down
56 changes: 28 additions & 28 deletions tests/StreamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,97 +24,97 @@ public function tearDown(): void
$files->deleteDirectory(self::FIXTURE_DIRECTORY, true);
}

public function testGetUri()
public function testGetUri(): void
{
$stream = Stream::create();
$stream->write('sample text');

$filename = StreamWrapper::getFilename($stream);

$this->assertFileExists($filename);
$this->assertSame(strlen('sample text'), filesize($filename));
$this->assertSame(md5('sample text'), md5_file($filename));
self::assertFileExists($filename);
self::assertSame(strlen('sample text'), filesize($filename));
self::assertSame(md5('sample text'), md5_file($filename));

$newFilename = self::FIXTURE_DIRECTORY . '/test.txt';
copy($filename, $newFilename);

$this->assertFileExists($newFilename);
$this->assertSame(strlen('sample text'), filesize($newFilename));
$this->assertSame(md5('sample text'), md5_file($newFilename));
self::assertFileExists($newFilename);
self::assertSame(strlen('sample text'), filesize($newFilename));
self::assertSame(md5('sample text'), md5_file($newFilename));

//Rewinding
$this->assertFileExists($newFilename);
$this->assertSame(strlen('sample text'), filesize($newFilename));
$this->assertSame(md5('sample text'), md5_file($newFilename));
self::assertFileExists($newFilename);
self::assertSame(strlen('sample text'), filesize($newFilename));
self::assertSame(md5('sample text'), md5_file($newFilename));

$this->assertTrue(StreamWrapper::has($filename));
$this->assertFalse(StreamWrapper::has($newFilename));
self::assertTrue(StreamWrapper::has($filename));
self::assertFalse(StreamWrapper::has($newFilename));
}

public function testGetResource()
public function testGetResource(): void
{
$stream = Stream::create();
$stream->write('sample text');

$this->assertFalse(StreamWrapper::has($stream));
self::assertFalse(StreamWrapper::has($stream));
$resource = StreamWrapper::getResource($stream);
$this->assertTrue(StreamWrapper::has($stream));
self::assertTrue(StreamWrapper::has($stream));

$this->assertIsResource($resource);
$this->assertSame('sample text', stream_get_contents($resource, -1, 0));
self::assertIsResource($resource);
self::assertSame('sample text', stream_get_contents($resource, -1, 0));

//Rewinding
$this->assertSame('sample text', stream_get_contents($resource, -1, 0));
self::assertSame('sample text', stream_get_contents($resource, -1, 0));

fseek($resource, 7);
$this->assertSame('text', stream_get_contents($resource, -1));
$this->assertSame('sample', stream_get_contents($resource, 6, 0));
self::assertSame('text', stream_get_contents($resource, -1));
self::assertSame('sample', stream_get_contents($resource, 6, 0));
}

/**
* @requires PHP < 8.0
*/
public function testException()
public function testException(): void
{
try {
fopen('spiral://non-exists', 'rb');
} catch (\Throwable $e) {
$this->assertStringContainsString('failed to open stream', $e->getMessage());
self::assertStringContainsString('failed to open stream', $e->getMessage());
}

try {
filemtime('spiral://non-exists');
} catch (\Throwable $e) {
$this->assertStringContainsString('stat failed', $e->getMessage());
self::assertStringContainsString('stat failed', $e->getMessage());
}
}

/**
* @requires PHP >= 8.0
*/
public function testExceptionPHP8()
public function testExceptionPHP8(): void
{
try {
fopen('spiral://non-exists', 'rb');
} catch (\Throwable $e) {
$this->assertStringContainsString('Failed to open stream', $e->getMessage());
self::assertStringContainsString('Failed to open stream', $e->getMessage());
}

try {
filemtime('spiral://non-exists');
} catch (\Throwable $e) {
$this->assertStringContainsString('stat failed', $e->getMessage());
self::assertStringContainsString('stat failed', $e->getMessage());
}
}

public function testWriteIntoStream()
public function testWriteIntoStream(): void
{
$stream = Stream::create(fopen('php://temp', 'wrb+'));
$file = StreamWrapper::getFilename($stream);

file_put_contents($file, 'test');

$this->assertSame('test', file_get_contents($file));
self::assertSame('test', file_get_contents($file));

StreamWrapper::release($file);
}
Expand Down

0 comments on commit 3aa8d30

Please sign in to comment.