GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( aa4ff3...5266c0 )
by Alex
22:35
created

Tests/Trigger/Event/AbstractListenerTest.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This file is part of the Global Trading Technologies Ltd workflow-extension-bundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * (c) fduch <[email protected]>
9
 * @date 14.07.16
10
 */
11
12
namespace Gtt\Bundle\WorkflowExtensionsBundle\Tests\Trigger\Event;
13
14
use Gtt\Bundle\WorkflowExtensionsBundle\Schedule\ScheduledTransition;
15
use Gtt\Bundle\WorkflowExtensionsBundle\Schedule\TransitionScheduler;
16
use Gtt\Bundle\WorkflowExtensionsBundle\Tests\TestCase;
17
use Gtt\Bundle\WorkflowExtensionsBundle\Trigger\Event\AbstractListener;
18
use Gtt\Bundle\WorkflowExtensionsBundle\WorkflowContext;
19
use Gtt\Bundle\WorkflowExtensionsBundle\WorkflowSubject\SubjectManipulator;
20
use Gtt\Bundle\WorkflowExtensionsBundle\TransitionApplier;
21
use PHPUnit_Framework_MockObject_MockObject;
22
use PHPUnit_Framework_TestCase;
23
use Psr\Log\LoggerInterface;
24
use ReflectionMethod;
25
use Symfony\Component\EventDispatcher\Event;
26
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
27
use Symfony\Component\Workflow\Registry;
28
use Symfony\Component\Workflow\Workflow;
29
30
class AbstractListenerTest extends PHPUnit_Framework_TestCase
31
{
32
    /**
33
     * @expectedException \Gtt\Bundle\WorkflowExtensionsBundle\Exception\UnsupportedTriggerEventException
34
     */
35
    public function testHandlingUnsupportedEventsTriggersException()
36
    {
37
        /** @var AbstractListener $listener */
38
        $listener = self::getMockForAbstractClass(AbstractListener::class, [], "", false);
39
        $listener->dispatchEvent(new Event(), "ghost_event");
40
    }
41
42
    public function testUnretrievableSubjectIsReportedByLogger()
43
    {
44
        $logger = $this->getMock(LoggerInterface::class);
45
        $logger->expects(self::once())->method('error');
46
47
        list($event, $expression, $language) = $this->getEventExpressionAndLanguage(true);
48
49
        /** @var AbstractListener $listener */
50
        $listener = self::getMockForAbstractClass(
51
            AbstractListener::class,
52
            [
53
                $language,
54
                $this->getMockBuilder(SubjectManipulator::class)->disableOriginalConstructor()->getMock(),
55
                $this->getMockBuilder(Registry::class)->disableOriginalConstructor()->getMock(),
56
                $logger
57
            ]
58
        );
59
60
        $configureEventMethodRef = new ReflectionMethod($listener, 'configureSubjectRetrievingForEvent');
61
        $configureEventMethodRef->setAccessible(true);
62
        $configureEventMethodRef->invokeArgs($listener, ['eventName', 'workflowName', $expression]);
63
64
        $listener->dispatchEvent($event, "eventName");
65
    }
66
67
    public function testSupportedEventIsHandled()
68
    {
69
        list($event, $expression, $language) = $this->getEventExpressionAndLanguage();
70
        $eventName = "eventName";
71
72
        $workflowRegistry = $this->getMock(Registry::class);
73
        $workflowRegistry->expects(self::once())->method('get')->willReturn(
74
            $this->getMockBuilder(Workflow::class)->disableOriginalConstructor()->getMock()
75
        );
76
77
        /** @var AbstractListener|PHPUnit_Framework_MockObject_MockObject $listener */
78
        $listener = self::getMockForAbstractClass(
79
            AbstractListener::class,
80
            [
81
                $language,
82
                $this->getMockBuilder(SubjectManipulator::class)->disableOriginalConstructor()->getMock(),
83
                $workflowRegistry,
84
                $this->getMock(LoggerInterface::class)
85
            ]
86
        );
87
88
        $listener
0 ignored issues
show
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Gtt\Bundle\WorkflowExten...\Event\AbstractListener.

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...
89
            ->expects(self::once())
90
            ->method('handleEvent')
91
            ->with(
92
                self::equalTo($eventName),
93
                self::equalTo($event),
94
                // event config
95
                self::isType('array'),
96
                self::isInstanceOf(WorkflowContext::class)
97
            )
98
        ;
99
100
        $configureEventMethodRef = new ReflectionMethod($listener, 'configureSubjectRetrievingForEvent');
101
        $configureEventMethodRef->setAccessible(true);
102
        $configureEventMethodRef->invokeArgs($listener, ['eventName', 'workflowName', $expression]);
103
104
        $listener->dispatchEvent($event, $eventName);
0 ignored issues
show
The method dispatchEvent does only exist in Gtt\Bundle\WorkflowExten...\Event\AbstractListener, but not in PHPUnit_Framework_MockObject_MockObject.

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...
105
    }
106
107
    /**
108
     * @return array
109
     */
110
    private function getEventExpressionAndLanguage($expressionEvaluationShouldThrowException = false)
111
    {
112
        $subject = new \StdClass();
113
        $event = new Event();
114
115
        $expression = "expression";
116
        $language = $this->getMockBuilder(ExpressionLanguage::class)->disableOriginalConstructor()->getMock();
117
        if ($expressionEvaluationShouldThrowException) {
118
            $language->expects(self::once())->method("evaluate")->with($expression, ['event' => $event])->willThrowException(new \Exception());
119
        } else {
120
            $language->expects(self::once())->method("evaluate")->with($expression, ['event' => $event])->willReturn($subject);
121
        }
122
        return array($event, $expression, $language);
123
    }
124
}
125