mwangi's avatar
Level 1

Mock Process Facade side-effects

Hey Artisans, how do you mock when a Process run using Process Facade has side effects. E.g scp downloads files and now you want to assert that a method returns correct downloaded files. I already have \Illuminate\Support\Facades\Process::fake().

I have attempted the following but none feels "Laravel-y" to me (I know we are we spoilt):

  • Swap the implementation from the container with a stub where the download function creates the file locally instead of doing the actual download. This feels gross yet the best alternative I have so far; When used in conjunction with Process::fake() to ascertain the command being run in a separate test.
  • Use Mockery to stub that the download() should always return the expected array
Class::shouldReceive('download')
                ->once()
                ->with($params)
                ->andReturn($pathsArray)
  • Assume that scp command is at the OS level; will always work and testing it is beyond the scope of my application code
0 likes
0 replies

Please or to participate in this conversation.