Completed
Pull Request — master (#168)
by Franco
02:41
created

tests/cms/DMSUploadField_ItemHandlerTest.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class DMSUploadField_ItemHandlerTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    protected static $fixture_file = 'dms/tests/dmstest.yml';
6
7
    /**
8
     * @var DMSDocument
9
     */
10
    protected $document;
11
12
    public function setUp()
13
    {
14
        parent::setUp();
15
16
        $this->document = $this->objFromFixture('DMSDocument', 'd1');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->objFromFixture('DMSDocument', 'd1') can also be of type object<DataObject>. However, the property $document is declared as type object<DMSDocument>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
17
    }
18
19
    public function testGetItem()
20
    {
21
        $handler = new DMSUploadField_ItemHandler(DMSUploadField::create('Test'), $this->document->ID);
22
        $result = $handler->getItem();
23
        $this->assertSame($result->ID, $this->document->ID, 'getItem returns the correct document from the database');
0 ignored issues
show
The method assertSame() does not seem to exist on object<DMSUploadField_ItemHandlerTest>.

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...
24
    }
25
26
    public function testEditForm()
27
    {
28
        $handler = new DMSUploadField_ItemHandler(DMSUploadField::create('Test'), $this->document->ID);
29
        $result = $handler->EditForm();
30
31
        $this->assertInstanceOf('Form', $result);
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<DMSUploadField_ItemHandlerTest>.

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...
32
        $this->assertInstanceOf('DMSDocument', $result->getRecord());
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<DMSUploadField_ItemHandlerTest>.

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...
33
        $this->assertSame($this->document->ID, $result->getRecord()->ID);
0 ignored issues
show
The method assertSame() does not seem to exist on object<DMSUploadField_ItemHandlerTest>.

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...
34
    }
35
}
36