Completed
Pull Request — master (#62)
by Jason
17:50 queued 02:52
created

PhotoGalleryBlockImageTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetCMSFields() 0 7 1
A testCanView() 0 8 1
A testCanEdit() 0 8 1
A testCanDelete() 0 8 1
A testCanCreate() 0 8 1
1
<?php
2
3
namespace Dynamic\DynamicBlocks\Test;
4
5
use Dynamic\DynamicBlocks\Model\PhotoGalleryBlockImage;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Security\Member;
9
10
class PhotoGalleryBlockImageTest extends SapphireTest
11
{
12
    /**
13
     * @var string
14
     */
15
    protected static $fixture_file = 'dynamic-blocks/tests/Fixtures.yml';
16
17
    /**
18
     *
19
     */
20
    public function testGetCMSFields()
21
    {
22
        $object = $this->objFromFixture(PhotoGalleryBlockImage::class, 'one');
23
        $fields = $object->getCMSFields();
24
        $this->assertInstanceOf(FieldList::class, $fields);
25
        $this->assertNull($fields->dataFieldByName('PhotoGalleryID'));
26
    }
27
28
    /**
29
     *
30
     */
31
    public function testCanView()
32
    {
33
        $object = $this->objFromFixture(PhotoGalleryBlockImage::class, 'one');
34
        $admin = $this->objFromFixture(Member::class, 'admin');
35
        $this->assertTrue($object->canView($admin));
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture(\S...Member::class, 'admin') on line 34 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canView() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
36
        $member = $this->objFromFixture(Member::class, 'default');
37
        $this->assertTrue($object->canView($member));
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture(\S...mber::class, 'default') on line 36 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canView() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
38
    }
39
40
    /**
41
     *
42
     */
43
    public function testCanEdit()
44
    {
45
        $object = $this->objFromFixture(PhotoGalleryBlockImage::class, 'one');
46
        $admin = $this->objFromFixture(Member::class, 'admin');
47
        $this->assertTrue($object->canEdit($admin));
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture(\S...Member::class, 'admin') on line 46 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canEdit() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
48
        $member = $this->objFromFixture(Member::class, 'default');
49
        $this->assertTrue($object->canEdit($member));
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture(\S...mber::class, 'default') on line 48 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canEdit() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
50
    }
51
52
    /**
53
     *
54
     */
55
    public function testCanDelete()
56
    {
57
        $object = $this->objFromFixture(PhotoGalleryBlockImage::class, 'one');
58
        $admin = $this->objFromFixture(Member::class, 'admin');
59
        $this->assertTrue($object->canDelete($admin));
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture(\S...Member::class, 'admin') on line 58 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canDelete() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
60
        $member = $this->objFromFixture(Member::class, 'default');
61
        $this->assertTrue($object->canDelete($member));
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture(\S...mber::class, 'default') on line 60 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canDelete() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
62
    }
63
64
    /**
65
     *
66
     */
67
    public function testCanCreate()
68
    {
69
        $object = $this->objFromFixture(PhotoGalleryBlockImage::class, 'one');
70
        $admin = $this->objFromFixture(Member::class, 'admin');
71
        $this->assertTrue($object->canCreate($admin));
0 ignored issues
show
Bug introduced by
It seems like $admin defined by $this->objFromFixture(\S...Member::class, 'admin') on line 70 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canCreate() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
72
        $member = $this->objFromFixture(Member::class, 'default');
73
        $this->assertTrue($object->canCreate($member));
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture(\S...mber::class, 'default') on line 72 can also be of type object<SilverStripe\ORM\DataObject>; however, SilverStripe\ORM\DataObject::canCreate() does only seem to accept object<SilverStripe\Security\Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
74
    }
75
}
76