Completed
Push — dev2 ( bf3a9f...7a5f92 )
by Gordon
07:26 queued 12s
created

SearchableClassTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 32
ccs 0
cts 18
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testCMSFields() 0 20 1
A testIsInSiteTreeHumanReadable() 0 6 1
1
<?php
2
3
/**
4
 * Test the functionality SearchableClass
5
 * @package elastica
6
 */
7
class SearchableClassTest extends ElasticsearchBaseTest {
8
9
	public function testCMSFields() {
10
		$sc = new SearchableClass();
11
		$sc->Name = 'TestField';
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<SearchableClass>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
12
		$sc->InSiteTree = false;
0 ignored issues
show
Documentation introduced by
The property InSiteTree does not exist on object<SearchableClass>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
13
		$sc->write();
14
15
		$fields = $sc->getCMSFields();
16
17
		$tab = $this->checkTabExists($fields,'Main');
18
19
		//Check fields
20
		$nf = $this->checkFieldExists($tab, 'Name');
21
		$this->assertTrue($nf->isDisabled());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SearchableClassTest>.

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...
22
23
		//FIXME - why does this fail?
24
		$this->assertTrue($nf->isReadOnly());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<SearchableClassTest>.

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
26
		//Check for existence of grid field
27
		$nf = $this->checkFieldExists($tab, 'SearchableField');
0 ignored issues
show
Unused Code introduced by
$nf is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28
	}
29
30
31
	public function testIsInSiteTreeHumanReadable() {
32
		$sc = new SearchableClass();
33
		$this->assertEquals('No', $sc->IsInSiteTreeHumanReadable());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SearchableClassTest>.

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
		$sc->InSiteTree = true;
0 ignored issues
show
Documentation introduced by
The property InSiteTree does not exist on object<SearchableClass>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
35
		$this->assertEquals('Yes', $sc->IsInSiteTreeHumanReadable());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<SearchableClassTest>.

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...
36
	}
37
38
}
39