Completed
Push — develop ( e2b887...c09155 )
by
unknown
12:13
created

CreateAssertionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 6
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testExtendsBaseClass() 0 6 1
A testProvidesDefaultEventManagerIdentifiers() 0 10 1
A testPreAssertConditions() 0 19 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2015 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace JobsTest\Acl;
12
13
use Auth\Entity\User;
14
use Jobs\Acl\CreateAssertion;
15
use Zend\Permissions\Acl\Acl;
16
use Zend\Permissions\Acl\Resource\ResourceInterface;
17
use Zend\Permissions\Acl\Role\GenericRole;
18
use Zend\Permissions\Acl\Role\RoleInterface;
19
20
/**
21
 * Test of Jobs\Acl\CreateAssertion
22
 *
23
 * @covers \Jobs\Acl\CreateAssertion
24
 * @author Mathias Gelhausen <[email protected]>
25
 * @group Jobs
26
 * @group Jobs.Acl
27
 */
28
class CreateAssertionTest extends \PHPUnit_Framework_TestCase
29
{
30
31
    /**
32
     * @coversNothing
33
     */
34
    public function testExtendsBaseClass()
35
    {
36
        $target = new CreateAssertion();
37
38
        $this->assertInstanceOf('\Acl\Assertion\AbstractEventManagerAwareAssertion', $target);
39
    }
40
41
    /**
42
     * @coversNothing
43
     */
44
    public function testProvidesDefaultEventManagerIdentifiers()
45
    {
46
        $target = new CreateAssertion();
47
        $expected = array(
48
            'Jobs/Acl/Assertions',
49
            'Jobs/Acl/Assertion/Create',
50
        );
51
52
        $this->assertAttributeEquals($expected, 'identifiers', $target);
53
    }
54
55
    public function testPreAssertConditions()
56
    {
57
        $target = new CreateAssertionMock();
58
59
        $acl = new Acl();
60
        $role = new GenericRole('test');
61
62
        // non user is always false?
63
        $this->assertFalse($target->assert($acl, $role, null, 'test'));
64
        $this->assertFalse($target->assert($acl, $role, null, 'new'));
65
66
        // user and wrong privilege is false?
67
        $role = new User();
68
        $this->assertFalse($target->assert($acl, $role, null, 'test'));
69
70
        // user and right privilege is null (meaning triggering event will be done)?
71
        $this->assertNull($target->assert($acl, $role, null, 'new'));
72
73
    }
74
}
75
76
class CreateAssertionMock extends CreateAssertion
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
77
{
78
    public function assert(Acl $acl,
79
                           RoleInterface $role = null,
80
                           ResourceInterface $resource = null,
81
                           $privilege = null
82
    ) {
83
        return parent::preAssert($acl, $role, $resource, $privilege);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (preAssert() instead of assert()). Are you sure this is correct? If so, you might want to change this to $this->preAssert().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
84
    }
85
}