目前我有目錄結構,如: `訪問資源文件中的Symfony
src
-App
--MyBundle
---Service
----DefaultService
tests
-AppMyBundle
--files
---data.csv
--Service
---DefaultServiceTest
I'm writting test for a file reader and I added
data.csv file for demo file for a test. In my test I need to get a path of that
data.csv file. But I couldn't find any way of getting it. I have tried accessing it via
file_locator service like:
$locator = $this->container->get('file_locator');
$path = $locator->locate('@AppMyBundle/Tests/files/data.csv');
and
$locator = $this->container->get('file_locator');
$path = $locator->locate('@AppMyBundle/files/data.
With no luck. namespaces if necessary of my
DefaultService is
應用程序\ MyBundle \服務and for DefaultServiceTest is
應用程序\ MyBundle \測試\ Service`
不幸的是,這是行不通的。給出'InvalidArgumentException:無法找到文件'@AppMyBundle/Tests/files/data.csv''錯誤 – Einius
更新答案@Einius –
是的,我想過這個選項,但也想到我可以得到一個更獨立的路徑,但我想這個將是我必須去的方式 – Einius