/** * {@inheritdoc} */ public function fetch() { $process = $this->buildProcess(); $process->run(); if (!$process->isSuccessful()) { throw new SourceException(sprintf('Unable to dump MySql database "%s", reason: "%s".', $this->database, $process->getErrorOutput())); } $mySqlDump = Filename::temporaryFile(sprintf('mysql-dump-%s-%s-%s.sql', $this->database, is_null($this->host) ? 'localhost' : $this->host, date('Y-m-d-H-i-s'))); if (file_put_contents($mySqlDump, $process->getOutput()) === false) { throw new \RuntimeException(sprintf('Unable to save MySql dump of database into "%s".', $mySqlDump)); } else { $this->getEventDispatcher()->addListener(BackupEvents::TERMINATE, function () use($mySqlDump) { unlink($mySqlDump); }); return array(File::fromLocal($mySqlDump, dirname($mySqlDump))); } }
/** * @test */ public function temporaryFile() { $filename = Filename::temporaryFile('some_test_name'); $this->assertTrue(file_exists($filename)); $this->assertNotFalse(strpos($filename, 'some_test_name')); }