BadMethodCallException:调用未定义的方法League \ Flysystem \ Filesystem :: assertExists

BadMethodCallException:调用未定义的方法League \ Flysystem \ Filesystem :: assertExists

问题描述:

我正在测试使用phpunit的laravel应用程序我试图运行以下以确保文件存在。BadMethodCallException:调用未定义的方法League Flysystem Filesystem :: assertExists

Storage::disk('local')->assertExists("mib_players.csv"); 

但是,当我运行测试时,我得到以下错误。

BadMethodCallException: Call to undefined method League\Flysystem\Filesystem::assertExists 

任何帮助,将不胜感激。

+0

assertExists不是一个函数从磁盘 – McStuffins

+0

回来,我发现这个assertExists下页https://laracasts.com/discuss/channels/testing/how-to-check-if-uploaded-file在存储中如果名称被哈希?页面= 0是他们测试文件存在的另一种方式。 –

你有几个这样的错误。首先,您在Storage对象上调用assertExists()。您需要调用TestCase对象上的断言函数。此外,没有assertExists(),只有assertFileExists()assertDirectoryExists(),但是如果存在特定路径中的文件,则会自动断言。

你应该做的是在你的Storage对象的方法是检查某些文件中存在的话,像这样:

public function fileExists($path) { 
    // check if file exists 
    return true; // or false 
} 

,然后断言函数返回true

$this->assertTrue(Storage::disk('local')->fileExists("mib_players.csv")); 

我不知道你的班级的具体情况,但是你也可以选择返回Storage的路径,然后你可以这样做:

$this->assertFileExists(Storage::disk("local")->getPath()."mib_players.csv"); 

Reference

+0

感谢您的帮助,我能够检查这样的文件。 $这 - > assertFileExists(storage_path( '应用程序/ flatfiles/mlb_players.csv')); –

+0

我很高兴你能解决它!我刚才意识到我不知何故错过了你使用Laravel。 'assertExists()'方法肯定在'FilesystemAdapter'类中,所以尝试更新你的Laravel版本('composer update'),也许你有一个旧版本! [见这里](https://github.com/illuminate/filesystem/blob/master/FilesystemAdapter.php#L50) – ishegg

+0

我曾尝试做一个作曲家更新,但我仍然有同样的错误。 –