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 ( 9b028d...187f46 )
by Bruno
10:41
created

YumlCommandTest::testExecuteWithFilenameOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
namespace OnurbTest\Bundle\YumlBundle\Command;
3
4
use Onurb\Bundle\YumlBundle\Command\YumlCommand;
5
use Symfony\Component\Console\Application;
6
use Symfony\Component\Console\Tester\CommandTester;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
9
class YumlCommandTest extends \PHPUnit_Framework_TestCase
10
{
11
    const YUML_LINK  = 'https://yuml.me/15a98c92.png';
12
13
    /**
14
     * @var Application
15
     */
16
    private $application;
17
18
    /**
19
     * @var YumlCommand
20
     */
21
    private $command;
22
23
    /**
24
     * @var ContainerInterface
25
     */
26
    private $container;
27
28
    /**
29
     * @var CommandTester
30
     */
31
    private $commandTester;
32
33
    public function setUp()
34
    {
35
        parent::setUp();
36
        $this->application = new Application();
37
        $this->application->add(new YumlCommand());
38
        $this->command = $this->application->find('yuml:mappings');
39
40
        $this->commandTester = new CommandTester($this->command);
41
42
        $yumlClient = $this->getMock('Onurb\\Bundle\\YumlBundle\\Yuml\\YumlClientInterface');
43
44
        $yumlClient->expects($this->once())
45
            ->method('makeDslText')
46
            ->will($this->returnValue('[Simple.Entity|+a;b;c]'));
47
48
        $yumlClient->expects($this->once())
49
            ->method('getGraphUrl')
50
            ->will($this->returnValue(self::YUML_LINK));
51
52
        $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
53
54
        $this->container->expects($this->once())->method('get')
55
            ->with($this->matches('onurb.doctrine_yuml.client'))
56
            ->will($this->returnValue($yumlClient));
57
58
        $this->command->setContainer($this->container);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Console\Command\Command as the method setContainer() does only exist in the following sub-classes of Symfony\Component\Console\Command\Command: Doctrine\Bundle\Doctrine...DatabaseDoctrineCommand, Doctrine\Bundle\Doctrine...Command\DoctrineCommand, Doctrine\Bundle\Doctrine...DatabaseDoctrineCommand, Doctrine\Bundle\Doctrine...EntitiesDoctrineCommand, Doctrine\Bundle\Doctrine...tMappingDoctrineCommand, Onurb\Bundle\YumlBundle\Command\YumlCommand, Sensio\Bundle\GeneratorB...d\GenerateBundleCommand, Sensio\Bundle\GeneratorB...\GenerateCommandCommand, Sensio\Bundle\GeneratorB...nerateControllerCommand, Sensio\Bundle\GeneratorB...GenerateDoctrineCommand, Sensio\Bundle\GeneratorB...rateDoctrineCrudCommand, Sensio\Bundle\GeneratorB...teDoctrineEntityCommand, Sensio\Bundle\GeneratorB...rateDoctrineFormCommand, Sensio\Bundle\GeneratorB...ommand\GeneratorCommand, Symfony\Bundle\Framework...d\AbstractConfigCommand, Symfony\Bundle\Framework...nd\AssetsInstallCommand, Symfony\Bundle\Framework...mmand\CacheClearCommand, Symfony\Bundle\Framework...d\CachePoolClearCommand, Symfony\Bundle\Framework...mand\CacheWarmupCommand, Symfony\Bundle\Framework...mand\ConfigDebugCommand, Symfony\Bundle\Framework...figDumpReferenceCommand, Symfony\Bundle\Framework...d\ContainerAwareCommand, Symfony\Bundle\Framework...d\ContainerDebugCommand, Symfony\Bundle\Framework...tDispatcherDebugCommand, Symfony\Bundle\Framework...mand\RouterDebugCommand, Symfony\Bundle\Framework...mand\RouterMatchCommand, Symfony\Bundle\Framework...e\Command\ServerCommand, Symfony\Bundle\Framework...ommand\ServerRunCommand, Symfony\Bundle\Framework...mand\ServerStartCommand, Symfony\Bundle\Framework...and\ServerStatusCommand, Symfony\Bundle\Framework...mmand\ServerStopCommand, Symfony\Bundle\Framework...TranslationDebugCommand, Symfony\Bundle\Framework...ranslationUpdateCommand, Symfony\Bundle\Framework...and\WorkflowDumpCommand, Symfony\Bundle\SecurityB...\Command\InitAclCommand, Symfony\Bundle\SecurityB...e\Command\SetAclCommand, Symfony\Bundle\SecurityB...rPasswordEncoderCommand, Symfony\Bundle\TwigBundle\Command\DebugCommand, Symfony\Bundle\TwigBundle\Command\LintCommand. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
59
    }
60
61
    /**
62
     * @covers \Onurb\Bundle\YumlBundle\Command\YumlCommand
63
     */
64
    public function testExecute()
65
    {
66
        $this->commandTester->execute(array('command' => $this->command->getName()));
67
        $this->assertRegExp('/.../', $this->commandTester->getDisplay());
68
        $this->assertSame('Downloaded', explode(' ', $this->commandTester->getDisplay())[0]);
69
    }
70
}
71