uccdev's avatar

Test case can't open file in public directory?

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?

0 likes
4 replies
uccdev's avatar

@MVD - That did the trick! Thanks for clarifying. Everything's working now!

1 like

Please or to participate in this conversation.