public function testAddKeyFromDotEnv()
{
// The key that should be available in the .env file
$key = 'DOT_ENV_KEY';
// Make key available in the .env file
file_put_contents(getcwd() . DIRECTORY_SEPARATOR . '.env', self::KEY_ENV_VARIABLE . '=' . $key);
// Mock a RemoteFilesystem
$rfs = $this->getMockBuilder('Composer\\Util\\RemoteFilesystem')->disableOriginalConstructor()->setMethods(['getOptions', 'isTlsDisabled'])->getMock();
$rfs->expects($this->once())->method('getOptions')->willReturn([]);
$rfs->expects($this->once())->method('isTlsDisabled')->willReturn(true);
// Mock Config
$config = $this->getMockBuilder('Composer\\Config')->getMock();
// Mock Composer
$composer = $this->getMockBuilder('Composer\\Composer')->setMethods(['getConfig'])->getMock();
$composer->expects($this->once())->method('getConfig')->willReturn($config);
// Mock IOInterface
$io = $this->getMockBuilder('Composer\\IO\\IOInterface')->getMock();
// Mock an Event
$event = $this->getMockBuilder('Composer\\Plugin\\PreFileDownloadEvent')->disableOriginalConstructor()->setMethods(['getProcessedUrl', 'getRemoteFilesystem', 'setRemoteFilesystem'])->getMock();
$event->expects($this->once())->method('getProcessedUrl')->willReturn(self::REPO_URL);
$event->expects($this->once())->method('getRemoteFilesystem')->willReturn($rfs);
$event->expects($this->once())->method('setRemoteFilesystem')->with($this->callback(function ($rfs) use($key) {
$this->assertAttributeContains("&k={$key}", 'acfFileUrl', $rfs);
return true;
}));
// Call addKey
$plugin = new Plugin();
$plugin->activate($composer, $io);
$plugin->addKey($event);
}