Hi @uccdev
fopen("courses.csv", "r");
Fopen is looking in the root now. You need to set the path to the file, https://www.php.net/manual/en/function.fopen.php
fopen(public_path('courses.csv'), "r")
Hi, In my current laravel project, I have a controller function that can find a file "courses.csv" just fine in my public directory ("myProject\public\courses.csv").
Now I want to test it can always find this in my test case code:
public function testOpenCourse() {
$course = new CourseController();
$course_list = $course->openCourse();
$this->assertNotNull(fgets($course_list));
}
Where 'openCourse()' simply reads this:
public function openCourse() {
return fopen("courses.csv", "r");
}
Rather than assert anything, when I run my phpunit for test cases, I instead get an error: "ErrorException: fopen(file.csv): failed to open stream: No such file or directory"
Why is this happening?
Hi @uccdev
fopen("courses.csv", "r");
Fopen is looking in the root now. You need to set the path to the file, https://www.php.net/manual/en/function.fopen.php
fopen(public_path('courses.csv'), "r")
Please or to participate in this conversation.