Completed
Push — master ( 30cac3...a62ce1 )
by Daniel
15s queued 10s
created

testBlogTagUrlSegmentsAreAutomaticallyUpdated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace SilverStripe\Blog\Tests;
4
5
use SilverStripe\Blog\Model\Blog;
6
use SilverStripe\Blog\Model\BlogPost;
7
use SilverStripe\Blog\Model\BlogTag;
8
use SilverStripe\Control\Controller;
9
use SilverStripe\Dev\FunctionalTest;
10
use SilverStripe\ORM\FieldType\DBDatetime;
11
use SilverStripe\ORM\ValidationException;
12
use SilverStripe\Security\Member;
13
14
/**
15
 * @mixin PHPUnit_Framework_TestCase
16
 */
17
class BlogTagTest extends FunctionalTest
18
{
19
    /**
20
     * {@inheritDoc}
21
     * @var string
22
     */
23
    protected static $fixture_file = 'blog.yml';
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function setUp()
29
    {
30
        parent::setUp();
31
32
        DBDatetime::set_mock_now('2013-10-10 20:00:00');
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function tearDown()
39
    {
40
        DBDatetime::clear_mock_now();
41
42
        parent::tearDown();
43
    }
44
45
    /**
46
     * Tests that any blog posts returned from $tag->BlogPosts() many_many are published, both by
47
     * normal 'save & publish' functionality and by publish date.
48
     */
49 View Code Duplication
    public function testBlogPosts()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        $member = Member::currentUser();
52
53
        if ($member) {
54
            $member->logout();
55
        }
56
57
        $this->objFromFixture('SiteTree', 'FirstBlogPost');
58
59
        /**
60
         * @var BlogTag $tag
61
         */
62
        $tag = $this->objFromFixture('BlogTag', 'FirstTag');
63
64
        $this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
65
    }
66
67
    /**
68
     * @see https://github.com/silverstripe/silverstripe-blog/issues/376
69
     */
70 View Code Duplication
    public function testAllowMultibyteUrlSegment()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        $blog = $this->objFromFixture('SiteTree', 'FirstBlog');
73
        $tag = new BlogTag();
74
        $tag->BlogID = $blog->ID;
75
        $tag->Title = 'تست';
76
        $tag->write();
77
        // urlencoded
78
        $this->assertEquals('%D8%AA%D8%B3%D8%AA', $tag->URLSegment);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
79
        $link = Controller::join_links($tag->Blog()->Link(), 'tag', '%D8%AA%D8%B3%D8%AA');
80
        $this->assertEquals($link, $tag->getLink());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
81
    }
82
83
    /**
84
     * The first blog can be viewed by anybody.
85
     */
86
    public function testCanView()
87
    {
88
        $this->useDraftSite();
89
90
        $admin = $this->objFromFixture('Member', 'Admin');
91
        $editor = $this->objFromFixture('Member', 'Editor');
92
93
        $tag = $this->objFromFixture('BlogTag', 'FirstTag');
94
95
        $this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 90 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...
96
        $this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 91 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...
97
98
        $tag = $this->objFromFixture('BlogTag', 'SecondTag');
99
100
        $this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 90 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...
101
        $this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.');
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 91 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...
102
    }
103
104 View Code Duplication
    public function testCanEdit()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
    {
106
        $this->useDraftSite();
107
108
        $admin = $this->objFromFixture('Member', 'Admin');
109
        $editor = $this->objFromFixture('Member', 'Editor');
110
111
        $tag = $this->objFromFixture('BlogTag', 'FirstTag');
112
113
        $this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 108 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...
114
        $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 109 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...
115
116
        $tag = $this->objFromFixture('BlogTag', 'SecondTag');
117
118
        $this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 108 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...
119
        $this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.');
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 109 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...
120
121
        $tag = $this->objFromFixture('BlogTag', 'ThirdTag');
122
123
        $this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 108 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...
124
        $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 109 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...
125
    }
126
127 View Code Duplication
    public function testCanCreate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
    {
129
        $this->useDraftSite();
130
131
        $admin = $this->objFromFixture('Member', 'Admin');
132
        $editor = $this->objFromFixture('Member', 'Editor');
133
134
        $tag = singleton(BlogTag::class);
135
136
        $this->assertTrue($tag->canCreate($admin), 'Admin should be able to create tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
137
        $this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
138
    }
139
140 View Code Duplication
    public function testCanDelete()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
141
    {
142
        $this->useDraftSite();
143
144
        $admin = $this->objFromFixture('Member', 'Admin');
145
        $editor = $this->objFromFixture('Member', 'Editor');
146
147
        $tag = $this->objFromFixture('BlogTag', 'FirstTag');
148
149
        $this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 144 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...
150
        $this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 145 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...
151
152
        $tag = $this->objFromFixture('BlogTag', 'SecondTag');
153
154
        $this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 144 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...
155
        $this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.');
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 145 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...
156
157
        $tag = $this->objFromFixture('BlogTag', 'ThirdTag');
158
159
        $this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $admin defined by $this->objFromFixture('Member', 'Admin') on line 144 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...
160
        $this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'Editor') on line 145 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...
161
    }
162
163
    public function testDuplicateTagsForURLSegment()
164
    {
165
        $blog = new Blog();
166
        $blog->Title = 'Testing for duplicates blog';
167
        $blog->write();
168
        $tag1 = new BlogTag();
169
        $tag1->Title = 'cat-test';
170
        $tag1->BlogID = $blog->ID;
171
        $tag1->write();
172
        $this->assertEquals('cat-test', $tag1->URLSegment);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
173
174
        $tag2 = new BlogTag();
175
        $tag2->Title = 'cat test';
176
        $tag2->BlogID = $blog->ID;
177
        $tag2->write();
178
        $this->assertEquals('cat-test-1', $tag2->URLSegment);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
179
    }
180
181 View Code Duplication
    public function testDuplicateTags()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
182
    {
183
        $blog = new Blog();
184
        $blog->Title = 'Testing for duplicate tags';
185
        $blog->write();
186
187
        $tag = new BlogTag();
188
        $tag->Title = 'Test';
189
        $tag->BlogID = $blog->ID;
190
        $tag->URLSegment = 'test';
191
        $tag->write();
192
193
        $tag = new BlogTag();
194
        $tag->Title = 'Test';
195
        $tag->URLSegment = 'test';
196
        $tag->BlogID = $blog->ID;
197
        try {
198
            $tag->write();
199
            $this->fail('Duplicate BlogTag written');
0 ignored issues
show
Bug introduced by
The method fail() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
200
        } catch (ValidationException $e) {
201
            $messages = $e->getResult()->getMessages();
202
            $this->assertCount(1, $messages);
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
203
            $this->assertEquals(BlogTag::DUPLICATE_EXCEPTION, $messages[0]['messageType']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
204
        }
205
    }
206
207
    public function testBlogTagUrlSegmentsAreAutomaticallyUpdated()
208
    {
209
        $tag = new BlogTag;
210
        $tag->Title = "a test";
211
        $tag->write();
212
        $this->assertEquals($tag->URLSegment, "a-test");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
213
214
        $tag->Title = "another test";
215
        $tag->write();
216
        $this->assertEquals($tag->URLSegment, "another-test");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SilverStripe\Blog\Tests\BlogTagTest>.

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...
217
    }
218
219
}
220