Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Adds the possibility of testing file upload content #35231

Merged
merged 1 commit into from Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Illuminate/Filesystem/FilesystemAdapter.php
Expand Up @@ -52,16 +52,27 @@ public function __construct(FilesystemInterface $driver)
* Assert that the given file exists.
*
* @param string|array $path
* @param string|null $content
* @return $this
*/
public function assertExists($path)
public function assertExists($path, $content = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change unfortunately :-/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed - but I think this may be a breaking change that doesn't "really" affect people.

Reasoning: This method seems to be used only in testing, and people would have to extend this class, and this method, for this to affect their test suites.

What do you think @driesvints ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally feel like we should avoid all breaking changes. Every one is a risk we take. But let's let @taylorotwell decide.

{
$paths = Arr::wrap($path);

foreach ($paths as $path) {
PHPUnit::assertTrue(
$this->exists($path), "Unable to find a file at path [{$path}]."
);

if (! is_null($content)) {
$actual = $this->get($path);

PHPUnit::assertSame(
$content,
$actual,
"File [{$path}] was found, but content [{$actual}] does not match [{$content}]."
);
}
}

return $this;
Expand Down
15 changes: 15 additions & 0 deletions tests/Filesystem/FilesystemAdapterTest.php
Expand Up @@ -262,6 +262,11 @@ public function testPutFileAs()
$filesystemAdapter->assertExists($storagePath);

$this->assertSame('uploaded file content', $filesystemAdapter->read($storagePath));

$filesystemAdapter->assertExists(
$storagePath,
'uploaded file content'
);
}

public function testPutFileAsWithAbsoluteFilePath()
Expand Down Expand Up @@ -290,6 +295,11 @@ public function testPutFile()
$this->assertFileExists($filePath);

$filesystemAdapter->assertExists($storagePath);

$filesystemAdapter->assertExists(
$storagePath,
'uploaded file content'
);
}

public function testPutFileWithAbsoluteFilePath()
Expand All @@ -303,5 +313,10 @@ public function testPutFileWithAbsoluteFilePath()
$this->assertSame(44, strlen($storagePath)); // random 40 characters + ".txt"

$filesystemAdapter->assertExists($storagePath);

$filesystemAdapter->assertExists(
$storagePath,
'uploaded file content'
);
}
}