OpauthIdentityTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 3
c 2
b 0
f 2
lcom 0
cbo 4
dl 0
loc 108
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
B testFindOrCreateMemberLinkOnMatch() 0 38 1
A testFindOrCreateMemberOverwriteExistingFields() 0 51 1
1
<?php
2
class OpauthIdentityTest 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...
3
4
	protected $usesDatabase = true;
5
6
	public function setUp() {
7
		parent::setUp();
8
9
		Config::inst()->update('OpauthIdentity', 'member_mapper', array(
10
			'Facebook' => array(
11
				'FirstName' => 'info.first_name',
12
				'Surname' => 'info.last_name',
13
				'Email' => 'info.email',
14
			)
15
		));
16
	}
17
18
	public function testFindOrCreateMemberLinkOnMatch() {
19
		$member = new Member(array('Email' => '[email protected]'));
20
		$member->write();
21
22
		$identity = OpauthIdentity::factory(array(
23
			'auth' => array(
24
				'provider' => 'Facebook',
25
				'uid' => 999,
26
				'info' => array('email' => '[email protected]')
27
			)
28
		));
29
		$identity->findOrCreateMember(array('linkOnMatch' => false));
30
		$this->assertEquals(0, $identity->MemberID, 'Does not link unless requested');
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<OpauthIdentity>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
Bug introduced by
The method assertEquals() does not seem to exist on object<OpauthIdentityTest>.

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...
31
32
		$identity = OpauthIdentity::factory(array(
33
			'auth' => array(
34
				'provider' => 'Facebook',
35
				'uid' => 999,
36
				'info' => array('email' => '[email protected]')
37
			)
38
		));
39
		$identity->findOrCreateMember(array('linkOnMatch' => true));
40
		$this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OpauthIdentityTest>.

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...
41
			$member->ID, 
42
			$identity->MemberID, 
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<OpauthIdentity>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
43
			'Links if requested and email matches'
44
		);
45
46
		$identity = OpauthIdentity::factory(array(
47
			'auth' => array(
48
				'provider' => 'Facebook',
49
				'uid' => 999,
50
				'info' => array('email' => '[email protected]')
51
			)
52
		));
53
		$identity->findOrCreateMember(array('linkOnMatch' => true));
54
		$this->assertEquals(0, $identity->MemberID, 'Does not link if requested but no member found');
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<OpauthIdentity>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
Bug introduced by
The method assertEquals() does not seem to exist on object<OpauthIdentityTest>.

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...
55
	}
56
57
	public function testFindOrCreateMemberOverwriteExistingFields() {
58
		$member = new Member(array(
59
			'Email' => '[email protected]',
60
			'FirstName' => 'Existing',
61
			'Surname' => 'Existing',
62
		));
63
		$member->write();
64
65
		$identity = OpauthIdentity::factory(array(
66
			'auth' => array(
67
				'provider' => 'Facebook',
68
				'uid' => 999,
69
				'info' => array(
70
					'email' => '[email protected]',
71
					'first_name' => 'New',
72
					'last_name' => 'New'
73
				)
74
			)
75
		));
76
		$member = $identity->findOrCreateMember(array('overwriteExistingFields' => false));
77
		$this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OpauthIdentityTest>.

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...
78
			'Existing', 
79
			$member->FirstName, 
80
			'Does not overwrite unless requested'
81
		);
82
83
		$identity = OpauthIdentity::factory(array(
84
			'auth' => array(
85
				'provider' => 'Facebook',
86
				'uid' => 999,
87
				'info' => array(
88
					'email' => '[email protected]',
89
					'first_name' => 'New',
90
					'last_name' => 'New'
91
				)
92
			)
93
		));
94
		$member = $identity->findOrCreateMember(array('overwriteExistingFields' => array(
95
			'FirstName'
96
		)));
97
		$this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OpauthIdentityTest>.

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...
98
			'New', 
99
			$member->FirstName, 
100
			'Overwrites existing fields if requested'
101
		);
102
		$this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OpauthIdentityTest>.

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...
103
			'Existing', 
104
			$member->Surname, 
105
			'Does not overwrite fields if not present in whitelist'
106
		);
107
	}
108
109
}