Completed
Push — master ( e32e27...6718d9 )
by Rafał
02:26
created

testListWithTenantsAndOrganizationOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 58
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 9.639
c 0
b 0
f 0
cc 1
eloc 40
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\MultiTenancyBundle\Tests\Command;
16
17
use SWP\Bundle\MultiTenancyBundle\Command\ListTenantsCommand;
18
use SWP\Component\MultiTenancy\Model\Organization;
19
use SWP\Component\MultiTenancy\Model\Tenant;
20
use SWP\Component\MultiTenancy\Repository\OrganizationRepositoryInterface;
21
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface;
22
use Symfony\Component\Console\Application;
23
use Symfony\Component\Console\Tester\CommandTester;
24
use Symfony\Component\DependencyInjection\ContainerInterface;
25
26
class ListTetantsCommandTest extends \PHPUnit_Framework_TestCase
27
{
28
    const ORGANIZATION_CODE = '123456';
29
30
    private $commandTester;
31
    private $command;
32
33
    public function setUp()
34
    {
35
        $application = new Application();
36
        $application->add(new ListTenantsCommand());
37
        $this->command = $application->get('swp:tenant:list');
38
    }
39
40
    /**
41
     * @covers \SWP\Bundle\MultiTenancyBundle\Command\ListTenantsCommand
42
     */
43 View Code Duplication
    public function testExecuteWhenNoTenants()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        $tenant = new Tenant();
46
        $tenant->setCode('123abc');
47
        $this->command->setContainer($this->getMockContainer(new Organization()));
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, Doctrine\Bundle\Doctrine...le\Command\CacheCommand, Doctrine\Bundle\Doctrine...Command\ContainsCommand, Doctrine\Bundle\Doctrine...e\Command\DeleteCommand, Doctrine\Bundle\Doctrine...le\Command\FlushCommand, Doctrine\Bundle\Doctrine...le\Command\StatsCommand, Doctrine\Bundle\PHPCRBun...mand\LoadFixtureCommand, Doctrine\Bundle\PHPCRBun...\MigratorMigrateCommand, Doctrine\Bundle\PHPCRBun...Command\NodeDumpCommand, Doctrine\Bundle\PHPCRBun...mmand\PhpcrShellCommand, Doctrine\Bundle\PHPCRBun...d\RepositoryInitCommand, SWP\Bundle\MultiTenancyB...eateOrganizationCommand, SWP\Bundle\MultiTenancyB...and\CreateTenantCommand, SWP\Bundle\MultiTenancyB...istOrganizationsCommand, SWP\Bundle\MultiTenancyB...mand\ListTenantsCommand, Symfony\Bundle\Framework...d\AbstractConfigCommand, Symfony\Bundle\Framework...nd\AssetsInstallCommand, Symfony\Bundle\Framework...mmand\CacheClearCommand, 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...uterApacheDumperCommand, 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. 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...
48
        $this->commandTester = new CommandTester($this->command);
49
        $this->commandTester->execute(['command' => $this->command->getName()]);
50
51
        $this->assertContains(
52
            'There are no tenants defined.',
53
            trim($this->commandTester->getDisplay())
54
        );
55
    }
56
57
    /**
58
     * @covers \SWP\Bundle\MultiTenancyBundle\Command\ListTenantsCommand
59
     */
60
    public function testListWithTenants()
61
    {
62
        $tenant = new Tenant();
63
        $tenant->setCode('123abc');
64
        $tenant->setId('1');
65
        $tenant->setName('Test Tenant');
66
        $tenant->setCreatedAt(new \DateTime('2017-02-20 15:19:55'));
67
        $organization = new Organization();
68
        $organization->setCode('123456');
69
        $organization->setName('Test Organization');
70
        $organization->addTenant($tenant);
71
        $tenant->setOrganization($organization);
72
        $this->command->setContainer($this->getMockContainer($organization));
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, Doctrine\Bundle\Doctrine...le\Command\CacheCommand, Doctrine\Bundle\Doctrine...Command\ContainsCommand, Doctrine\Bundle\Doctrine...e\Command\DeleteCommand, Doctrine\Bundle\Doctrine...le\Command\FlushCommand, Doctrine\Bundle\Doctrine...le\Command\StatsCommand, Doctrine\Bundle\PHPCRBun...mand\LoadFixtureCommand, Doctrine\Bundle\PHPCRBun...\MigratorMigrateCommand, Doctrine\Bundle\PHPCRBun...Command\NodeDumpCommand, Doctrine\Bundle\PHPCRBun...mmand\PhpcrShellCommand, Doctrine\Bundle\PHPCRBun...d\RepositoryInitCommand, SWP\Bundle\MultiTenancyB...eateOrganizationCommand, SWP\Bundle\MultiTenancyB...and\CreateTenantCommand, SWP\Bundle\MultiTenancyB...istOrganizationsCommand, SWP\Bundle\MultiTenancyB...mand\ListTenantsCommand, Symfony\Bundle\Framework...d\AbstractConfigCommand, Symfony\Bundle\Framework...nd\AssetsInstallCommand, Symfony\Bundle\Framework...mmand\CacheClearCommand, 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...uterApacheDumperCommand, 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. 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...
73
        $this->commandTester = new CommandTester($this->command);
74
        $this->commandTester->execute(['command' => $this->command->getName()]);
75
76
        $result = <<<'EOF'
77
List of all available tenants:
78
+----+--------+-------------+------------+---------------------+----------------------------------+
79
| Id | Code   | Name        | Is active? | Created at          | Organization                     |
80
+----+--------+-------------+------------+---------------------+----------------------------------+
81
| 1  | 123abc | Test Tenant | yes        | 2017-02-20 15:19:55 | Test Organization (code: 123456) |
82
+----+--------+-------------+------------+---------------------+----------------------------------+
83
EOF;
84
85
        $this->assertEquals($result, trim($this->commandTester->getDisplay()));
86
    }
87
88
    /**
89
     * @covers \SWP\Bundle\MultiTenancyBundle\Command\CreateTenantCommand
90
     */
91
    public function testListWithTenantsAndOrganizationOption()
92
    {
93
        $tenant = new Tenant();
94
        $tenant->setCode('123abc');
95
        $tenant->setId('1');
96
        $tenant->setName('Test Tenant');
97
        $tenant->setCreatedAt(new \DateTime('2017-02-20 15:19:55'));
98
        $organization = new Organization();
99
        $organization->setCode('123456');
100
        $organization->setName('Test Organization');
101
        $organization->addTenant($tenant);
102
103
        $tenant->setOrganization($organization);
104
        $this->command->setContainer($this->getMockContainer($organization));
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, Doctrine\Bundle\Doctrine...le\Command\CacheCommand, Doctrine\Bundle\Doctrine...Command\ContainsCommand, Doctrine\Bundle\Doctrine...e\Command\DeleteCommand, Doctrine\Bundle\Doctrine...le\Command\FlushCommand, Doctrine\Bundle\Doctrine...le\Command\StatsCommand, Doctrine\Bundle\PHPCRBun...mand\LoadFixtureCommand, Doctrine\Bundle\PHPCRBun...\MigratorMigrateCommand, Doctrine\Bundle\PHPCRBun...Command\NodeDumpCommand, Doctrine\Bundle\PHPCRBun...mmand\PhpcrShellCommand, Doctrine\Bundle\PHPCRBun...d\RepositoryInitCommand, SWP\Bundle\MultiTenancyB...eateOrganizationCommand, SWP\Bundle\MultiTenancyB...and\CreateTenantCommand, SWP\Bundle\MultiTenancyB...istOrganizationsCommand, SWP\Bundle\MultiTenancyB...mand\ListTenantsCommand, Symfony\Bundle\Framework...d\AbstractConfigCommand, Symfony\Bundle\Framework...nd\AssetsInstallCommand, Symfony\Bundle\Framework...mmand\CacheClearCommand, 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...uterApacheDumperCommand, 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. 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...
105
        $this->commandTester = new CommandTester($this->command);
106
        $this->commandTester->execute(['command' => $this->command->getName()]);
107
108
        $result = <<<'EOF'
109
List of all available tenants:
110
+----+--------+-------------+------------+---------------------+----------------------------------+
111
| Id | Code   | Name        | Is active? | Created at          | Organization                     |
112
+----+--------+-------------+------------+---------------------+----------------------------------+
113
| 1  | 123abc | Test Tenant | yes        | 2017-02-20 15:19:55 | Test Organization (code: 123456) |
114
+----+--------+-------------+------------+---------------------+----------------------------------+
115
EOF;
116
117
        $this->assertEquals($result, trim($this->commandTester->getDisplay()));
118
119
        $tenant2 = new Tenant();
120
        $tenant2->setCode('345def');
121
        $tenant2->setId('2');
122
        $tenant2->setName('Test Tenant 2');
123
        $tenant2->setCreatedAt(new \DateTime('2017-02-20 15:19:55'));
124
        $organization2 = new Organization();
125
        $organization2->setCode('789012');
126
        $organization2->setName('Test Organization2');
127
        $organization2->addTenant($tenant2);
128
        $tenant2->setOrganization($organization2);
129
130
        $this->command->setContainer($this->getMockContainer($organization2));
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, Doctrine\Bundle\Doctrine...le\Command\CacheCommand, Doctrine\Bundle\Doctrine...Command\ContainsCommand, Doctrine\Bundle\Doctrine...e\Command\DeleteCommand, Doctrine\Bundle\Doctrine...le\Command\FlushCommand, Doctrine\Bundle\Doctrine...le\Command\StatsCommand, Doctrine\Bundle\PHPCRBun...mand\LoadFixtureCommand, Doctrine\Bundle\PHPCRBun...\MigratorMigrateCommand, Doctrine\Bundle\PHPCRBun...Command\NodeDumpCommand, Doctrine\Bundle\PHPCRBun...mmand\PhpcrShellCommand, Doctrine\Bundle\PHPCRBun...d\RepositoryInitCommand, SWP\Bundle\MultiTenancyB...eateOrganizationCommand, SWP\Bundle\MultiTenancyB...and\CreateTenantCommand, SWP\Bundle\MultiTenancyB...istOrganizationsCommand, SWP\Bundle\MultiTenancyB...mand\ListTenantsCommand, Symfony\Bundle\Framework...d\AbstractConfigCommand, Symfony\Bundle\Framework...nd\AssetsInstallCommand, Symfony\Bundle\Framework...mmand\CacheClearCommand, 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...uterApacheDumperCommand, 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. 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...
131
        $this->commandTester = new CommandTester($this->command);
132
        $this->commandTester->execute(['command' => $this->command->getName(), '-o' => '123456']);
133
        $result = <<<'EOF'
134
There are no tenants defined.
135
EOF;
136
        $this->assertEquals($result, trim($this->commandTester->getDisplay()));
137
138
        $this->commandTester->execute(['command' => $this->command->getName()]);
139
        $result = <<<'EOF'
140
List of all available tenants:
141
+----+--------+---------------+------------+---------------------+-----------------------------------+
142
| Id | Code   | Name          | Is active? | Created at          | Organization                      |
143
+----+--------+---------------+------------+---------------------+-----------------------------------+
144
| 2  | 345def | Test Tenant 2 | yes        | 2017-02-20 15:19:55 | Test Organization2 (code: 789012) |
145
+----+--------+---------------+------------+---------------------+-----------------------------------+
146
EOF;
147
        $this->assertEquals($result, trim($this->commandTester->getDisplay()));
148
    }
149
150
    private function getMockContainer($mockOrganization = null)
151
    {
152
        $mockRepoOrganization = $this->getMockBuilder(OrganizationRepositoryInterface::class)
153
            ->getMock();
154
155
        $mockRepoOrganization->expects($this->any())
156
            ->method('findOneByCode')
157
            ->with(self::ORGANIZATION_CODE)
158
            ->willReturn($mockOrganization);
159
160
        $mockRepo = $this->getMockBuilder(TenantRepositoryInterface::class)
161
            ->getMock();
162
163
        $mockRepo->expects($this->any())
164
            ->method('findAll')
165
            ->willReturn($mockOrganization->getTenants());
166
167
        $mockContainer = $this->getMockBuilder(ContainerInterface::class)
168
            ->getMock();
169
170
        $mockContainer->expects($this->any())
171
            ->method('get')
172
            ->will($this->returnValueMap([
173
                ['swp.repository.tenant', 1, $mockRepo],
174
                ['swp.repository.organization', 1, $mockRepoOrganization],
175
            ]));
176
177
        return $mockContainer;
178
    }
179
180
    /**
181
     * @param $input
182
     *
183
     * @return resource
184
     */
185
    protected function getInputStream($input)
186
    {
187
        $stream = fopen('php://memory', 'r+', false);
188
        fwrite($stream, $input);
189
        rewind($stream);
190
191
        return $stream;
192
    }
193
}
194