Passed
Push — master ( 8d6223...3134d9 )
by Robbie
07:59
created

testGetRestoreAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\VersionedAdmin\Tests\Forms\GridField;
4
5
use SilverStripe\Assets\File;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Forms\GridField\GridField;
8
use SilverStripe\Forms\GridField\GridField_FormAction;
9
use SilverStripe\Forms\GridField\GridFieldConfig;
10
use SilverStripe\ORM\ArrayList;
11
use SilverStripe\VersionedAdmin\Forms\GridField\GridFieldFileRestoreAction;
12
use SilverStripe\VersionedAdmin\Tests\ArchiveAdminTest\VersionedObject;
13
14
class GridFieldFileRestoreActionTest extends SapphireTest
15
{
16
    public function testGetRestoreAction()
17
    {
18
        $this->logInWithPermission('ADMIN');
19
        $gridField = GridField::create('Test', 'Test', ArrayList::create(), new GridFieldConfig());
20
21
        $action = new GridFieldFileRestoreAction();
22
        $this->assertNull($action->getRestoreAction($gridField, new VersionedObject(), 'Test'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $action->getRestoreActio...sionedObject(), 'Test') targeting SilverStripe\VersionedAd...ion::getRestoreAction() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
23
        $this->assertNull($action->getRestoreAction($gridField, new File(), 'Test'));
24
25
        $file = $this->getMockBuilder(File::class)
26
            ->setMethods(['exists'])
27
            ->getMock();
28
        $file->method('exists')
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

28
        $file->/** @scrutinizer ignore-call */ 
29
               method('exists')

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...
29
            ->willReturn(true);
30
31
        $this->assertInstanceOf(GridField_FormAction::class, $action->getRestoreAction($gridField, $file, 'Test'));
32
    }
33
}
34