Completed
Push — master ( 19e3bd...22f213 )
by Guilherme
17:20
created

NfgSubscriberTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 103
rs 10
c 1
b 1
f 0
wmc 4
lcom 1
cbo 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetSubscribedEvents() 0 9 1
A testOnConnectCallbackResponseNoPersonOrNfgProfile() 0 23 1
B testOnConnectCallbackResponseDoNothing() 0 28 1
B testOnConnectCallbackResponseUpdate() 0 37 1
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace PROCERGS\LoginCidadao\NfgBundle\Tests\EventListener;
12
13
use Doctrine\ORM\EntityManagerInterface;
14
use libphonenumber\PhoneNumber;
15
use LoginCidadao\CoreBundle\Entity\Person;
16
use LoginCidadao\CoreBundle\Model\PersonInterface;
17
use PROCERGS\LoginCidadao\CoreBundle\Entity\PersonMeuRS;
18
use PROCERGS\LoginCidadao\NfgBundle\Entity\NfgProfile;
19
use PROCERGS\LoginCidadao\NfgBundle\Event\GetConnectCallbackResponseEvent;
20
use PROCERGS\LoginCidadao\NfgBundle\EventListener\NfgSubscriber;
21
use PROCERGS\LoginCidadao\NfgBundle\NfgEvents;
22
use Psr\Log\LoggerInterface;
23
24
class NfgSubscriberTest extends \PHPUnit_Framework_TestCase
25
{
26
    public function testGetSubscribedEvents()
27
    {
28
        $events = NfgSubscriber::getSubscribedEvents();
29
30
        $this->assertCount(1, $events);
31
        $this->assertEquals([
32
            NfgEvents::CONNECT_CALLBACK_RESPONSE => 'onConnectCallbackResponse',
33
        ], $events);
34
    }
35
36
    public function testOnConnectCallbackResponseNoPersonOrNfgProfile()
37
    {
38
        /** @var EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject $em */
39
        $em = $this->getMock('Doctrine\ORM\EntityManagerInterface');
40
        $em->expects($this->never())->method('persist');
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityManagerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
41
        $em->expects($this->never())->method('flush');
42
43
        /** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject $logger */
44
        $logger = $this->getMock('Psr\Log\LoggerInterface');
45
        $logger->expects($this->never())->method('notice');
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Psr\Log\LoggerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
46
47
        $personMeuRS = new PersonMeuRS();
48
49
        /** @var GetConnectCallbackResponseEvent|\PHPUnit_Framework_MockObject_MockObject $event */
50
        $event = $this->getMockBuilder('PROCERGS\LoginCidadao\NfgBundle\Event\GetConnectCallbackResponseEvent')
51
            ->disableOriginalConstructor()->getMock();
52
        $event->expects($this->exactly(2))->method('getPersonMeuRS')->willReturn($personMeuRS);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in PROCERGS\LoginCidadao\Nf...ctCallbackResponseEvent.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
53
54
        $subscriber = new NfgSubscriber($em);
55
        $subscriber->setLogger($logger);
56
57
        $subscriber->onConnectCallbackResponse($event);
58
    }
59
60
    public function testOnConnectCallbackResponseDoNothing()
61
    {
62
        /** @var EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject $em */
63
        $em = $this->getMock('Doctrine\ORM\EntityManagerInterface');
64
        $em->expects($this->never())->method('persist');
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityManagerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
65
        $em->expects($this->never())->method('flush');
66
67
        /** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject $logger */
68
        $logger = $this->getMock('Psr\Log\LoggerInterface');
69
        $logger->expects($this->never())->method('notice');
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Psr\Log\LoggerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
70
71
        $person = new Person();
72
        $person->setBirthdate(new \DateTime());
73
        $person->setMobile(new PhoneNumber());
74
75
        $personMeuRS = new PersonMeuRS();
76
        $personMeuRS->setPerson($person);
77
78
        /** @var GetConnectCallbackResponseEvent|\PHPUnit_Framework_MockObject_MockObject $event */
79
        $event = $this->getMockBuilder('PROCERGS\LoginCidadao\NfgBundle\Event\GetConnectCallbackResponseEvent')
80
            ->disableOriginalConstructor()->getMock();
81
        $event->expects($this->exactly(2))->method('getPersonMeuRS')->willReturn($personMeuRS);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in PROCERGS\LoginCidadao\Nf...ctCallbackResponseEvent.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
82
83
        $subscriber = new NfgSubscriber($em);
84
        $subscriber->setLogger($logger);
85
86
        $subscriber->onConnectCallbackResponse($event);
87
    }
88
89
    public function testOnConnectCallbackResponseUpdate()
90
    {
91
        $personInterface = 'LoginCidadao\CoreBundle\Model\PersonInterface';
92
        /** @var EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject $em */
93
        $em = $this->getMock('Doctrine\ORM\EntityManagerInterface');
94
        $em->expects($this->once())->method('persist')
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityManagerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
95
            ->with($this->isInstanceOf($personInterface));
96
        $em->expects($this->once())->method('flush');
97
98
        /** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject $logger */
99
        $logger = $this->getMock('Psr\Log\LoggerInterface');
100
        $logger->expects($this->exactly(2))->method('notice');
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Psr\Log\LoggerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
101
102
        $phoneNumber = new PhoneNumber();
103
104
        /** @var PersonInterface|\PHPUnit_Framework_MockObject_MockObject $person */
105
        $person = $this->getMock($personInterface);
106
        $person->expects($this->once())->method('setBirthdate');
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\CoreBundle\Model\PersonInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
107
        $person->expects($this->once())->method('setMobile')->with($phoneNumber);
108
109
        $nfgProfile = new NfgProfile();
110
        $nfgProfile->setMobile($phoneNumber);
111
        $nfgProfile->setBirthdate(new \DateTime());
112
113
        $personMeuRS = new PersonMeuRS();
114
        $personMeuRS->setPerson($person);
115
        $personMeuRS->setNfgProfile($nfgProfile);
116
117
        $event = $this->getMockBuilder('PROCERGS\LoginCidadao\NfgBundle\Event\GetConnectCallbackResponseEvent')
118
            ->disableOriginalConstructor()->getMock();
119
        $event->expects($this->exactly(2))->method('getPersonMeuRS')->willReturn($personMeuRS);
120
121
        $subscriber = new NfgSubscriber($em);
122
        $subscriber->setLogger($logger);
123
124
        $subscriber->onConnectCallbackResponse($event);
125
    }
126
}
127