GridFieldFileRestoreActionTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 12
c 1
b 1
f 0
dl 0
loc 18
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testGetRestoreAction() 0 16 1
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)
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

25
        $file = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(File::class)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
26
            ->setMethods(['exists'])
27
            ->getMock();
28
        $file->method('exists')
29
            ->willReturn(true);
30
31
        $this->assertInstanceOf(GridField_FormAction::class, $action->getRestoreAction($gridField, $file, 'Test'));
32
    }
33
}
34