Completed
Push — master ( b28dd3...d832e3 )
by Franco
13s
created

ChecIOExtensionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testGetChecIOJs() 0 6 1
A testGetChecIOJsIgnoresIfFalsy() 0 6 1
1
<?php
2
3
class ChecIOExtensionTest 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 = 'ChecIOShortcodeTest.yml';
6
7
    /**
8
     * @var Page
9
     */
10
    private $page;
11
12
    public function setUp()
13
    {
14
        parent::setUp();
15
        $this->page = $this->objFromFixture('SiteTree', 'test');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->objFromFixture('SiteTree', 'test') can also be of type object<DataObject>. However, the property $page is declared as type object<Page>. 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...
16
    }
17
18
    /**
19
     * Tests that a non-empty result is returned.
20
     */
21
    public function testGetChecIOJs()
22
    {
23
        $result = $this->page->getChecIOJs();
24
        $this->assertNotNull($result);
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<ChecIOExtensionTest>.

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...
25
        $this->assertContains('<script type="text/javascript', $result);
26
    }
27
28
    /**
29
     * Allow the JS to be disabled if desired
30
     */
31
    public function testGetChecIOJsIgnoresIfFalsy()
32
    {
33
        Config::inst()->update('ChecIOShortcode', 'third-party-js', '');
34
        $result = $this->page->getChecIOJs();
35
        $this->assertNotContains('<script type="text/javascript', $result);
36
    }
37
}
38