FIX unlink call checks that a file exists first, and tests pass a File object

This commit is contained in:
Robbie Averill 2018-07-03 16:30:05 +12:00
parent 770af5cfc9
commit 6bf932e5f0
4 changed files with 16 additions and 6 deletions

View File

@ -140,7 +140,9 @@ abstract class FileTextExtractor
} }
// Remove any existing temp files with this name // Remove any existing temp files with this name
unlink($path); if (file_exists($path)) {
unlink($path);
}
$bytesWritten = file_put_contents($path, $file->getStream()); $bytesWritten = file_put_contents($path, $file->getStream());
if (false === $bytesWritten) { if (false === $bytesWritten) {

View File

@ -4,7 +4,6 @@ namespace SilverStripe\TextExtraction\Extractor;
use SilverStripe\Assets\File; use SilverStripe\Assets\File;
use SilverStripe\TextExtraction\Extractor\FileTextExtractor\Exception; use SilverStripe\TextExtraction\Extractor\FileTextExtractor\Exception;
use function tempnam;
/** /**
* Text extractor that calls pdftotext to do the conversion. * Text extractor that calls pdftotext to do the conversion.

View File

@ -25,9 +25,9 @@ class TikaRestClient extends Client
/** /**
* *
* @param string $baseUrl * @param string $baseUrl
* @param array $config * @param array $config
*/ */
public function __construct($baseUrl = '', $config = null) public function __construct($baseUrl = '', $config = [])
{ {
$password = Environment::getEnv('SS_TIKA_PASSWORD'); $password = Environment::getEnv('SS_TIKA_PASSWORD');

View File

@ -2,6 +2,7 @@
namespace SilverStripe\TextExtraction\Tests; namespace SilverStripe\TextExtraction\Tests;
use SilverStripe\Assets\File;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\TextExtraction\Extractor\TikaServerTextExtractor; use SilverStripe\TextExtraction\Extractor\TikaServerTextExtractor;
use SilverStripe\TextExtraction\Extractor\TikaTextExtractor; use SilverStripe\TextExtraction\Extractor\TikaTextExtractor;
@ -11,6 +12,8 @@ use SilverStripe\TextExtraction\Extractor\TikaTextExtractor;
*/ */
class TikaTextExtractorTest extends SapphireTest class TikaTextExtractorTest extends SapphireTest
{ {
protected $usesDatabase = true;
public function testExtraction() public function testExtraction()
{ {
$extractor = new TikaTextExtractor(); $extractor = new TikaTextExtractor();
@ -19,7 +22,10 @@ class TikaTextExtractorTest extends SapphireTest
} }
// Check file // Check file
$file = dirname(__FILE__) . '/fixtures/test1.pdf'; $file = new File();
$file->setFromLocalFile(dirname(__FILE__) . '/fixtures/test1.pdf');
$file->write();
$content = $extractor->getContent($file); $content = $extractor->getContent($file);
$this->assertContains('This is a test file with a link', $content); $this->assertContains('This is a test file with a link', $content);
@ -37,7 +43,10 @@ class TikaTextExtractorTest extends SapphireTest
} }
// Check file // Check file
$file = dirname(__FILE__) . '/fixtures/test1.pdf'; $file = new File();
$file->setFromLocalFile(dirname(__FILE__) . '/fixtures/test1.pdf');
$file->write();
$content = $extractor->getContent($file); $content = $extractor->getContent($file);
$this->assertContains('This is a test file with a link', $content); $this->assertContains('This is a test file with a link', $content);