Completed
Pull Request — master (#45)
by Robbie
24:33 queued 17:24
created

FileTextExtractableTest::testExtractFileAsText()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
rs 9.2
cc 2
eloc 12
nc 2
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A FileTextExtractableTest::tearDown() 0 7 2
1
<?php
2
3
namespace SilverStripe\TextExtraction\Tests;
4
5
use SilverStripe\Assets\File;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\TextExtraction\Extension\FileTextExtractable;
9
10
class FileTextExtractableTest extends SapphireTest
11
{
12
    protected $usesDatabase = true;
13
14
    protected static $required_extensions = [
15
        File::class => [
16
            FileTextExtractable::class,
17
        ],
18
    ];
19
20
    protected function setUp()
21
    {
22
        parent::setUp();
23
24
        // Ensure that html is a valid extension
25
        Config::modify()->merge(File::class, 'allowed_extensions', ['html']);
26
27
        // Create a copy of the file, as it may be clobbered by the test
28
        // ($file->extractFileAsText() calls $file->write)
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
29
        copy(
30
            dirname(__FILE__) . '/fixtures/test1.html',
31
            dirname(__FILE__) . '/fixtures/test1-copy.html'
32
        );
33
    }
34
35
    protected function tearDown()
36
    {
37
        if (file_exists(dirname(__FILE__) . '/fixtures/test1-copy.html')) {
38
            unlink(dirname(__FILE__) . '/fixtures/test1-copy.html');
39
        }
40
41
        parent::tearDown();
42
    }
43
44
    public function testExtractFileAsText()
45
    {
46
        // Use HTML, since the extractor is always available
47
        /** @var File|FileTextExtractable $file */
48
        $file = new File(['Name' => 'test1-copy.html']);
49
        $file->setFromLocalFile(dirname(__FILE__) . '/fixtures/test1-copy.html');
0 ignored issues
show
Bug introduced by
The method setFromLocalFile() does not exist on SilverStripe\TextExtract...ion\FileTextExtractable. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
        $file->/** @scrutinizer ignore-call */ 
50
               setFromLocalFile(dirname(__FILE__) . '/fixtures/test1-copy.html');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
        $file->write();
0 ignored issues
show
Bug introduced by
The method write() does not exist on SilverStripe\TextExtract...ion\FileTextExtractable. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        $file->/** @scrutinizer ignore-call */ 
51
               write();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
52
        $content = $file->extractFileAsText();
53
        $this->assertNotNull($content);
54
        $this->assertContains('Test Headline', $content);
55
        $this->assertContains('Test Text', $content);
56
        $this->assertEquals($content, $file->FileContentCache);
0 ignored issues
show
Bug introduced by
The property FileContentCache does not seem to exist on SilverStripe\TextExtract...ion\FileTextExtractable.
Loading history...
57
    }
58
}
59