LarsvanHerwijnen's avatar

Test with storage failing in github actions

Hi all,

I have this test that is failing in the github actions but works locally. Does any of know what the issue might be? Do I have to configure something is Github Actions

Thanks!

The test:

it('displays the privacy statement', function () {
    if (getenv('CI')) {
        $this->markTestSkipped('This test is not run on GitHub Actions.');
    }
    // Fake the entire storage system
    Storage::fake();

    // Create a test markdown file
    $testMarkdownContent = "# Test Heading\nThis is a test paragraph.";
    Storage::put('test.md', $testMarkdownContent);

    // Mock the get method on the Storage facade
    Storage::shouldReceive('get')
        ->with('test.md')
        ->andReturn($testMarkdownContent);

    // Mock the delete method on the Storage facade
    Storage::shouldReceive('delete')
        ->with('test.md');

    // Mock the get method on the File facade
    File::shouldReceive('get')
        ->with(resource_path('views/privacyverklaring.md'))
        ->andReturn(Storage::get('test.md'));

    // Make a GET request to the route that maps to the show method
    $response = $this->get('/privacy-statement');

    // Assert that the response contains the test content
    $response->assertSee('Test Heading');
    $response->assertSee('This is a test paragraph.');

    // Clean up the test markdown file
    Storage::delete('test.md');
});

The error in the pipeline:

   FAILED  Tests\Unit\PrivacyStatementTest > it disp…  BadMethodCallException   
  Received Mockery_3_Illuminate_Filesystem_Filesystem::exists(), but no expectations were specified

  at vendor/laravel/framework/src/Illuminate/View/FileViewFinder.php:131
    127▕     protected function findInPaths($name, $paths)
    128▕     {
    129▕         foreach ((array) $paths as $path) {
    130▕             foreach ($this->getPossibleViewFiles($name) as $file) {
  ➜ 131▕                 if ($this->files->exists($viewPath = $path.'/'.$file)) {
    132▕                     return $viewPath;
    133▕                 }
    134▕             }
    135▕         }

      +11 vendor frames 
  12  tests/Unit/PrivacyStatementTest.php:42
0 likes
1 reply
martinbean's avatar

@larsvanherwijnen Have a look at line 42 in your tests/Unit/PrivacyStatementTest.php file. That’s where the error stems from. Something there is causing exists to be called.

Also, this is an integration test, not a unit test. You're using facades and making HTTP requests which involve the framework to be booted.

Please or to participate in this conversation.