Completed
Push — master ( a5a038...08ae9a )
by Ricardo
04:34
created

PermissionCheckCommandTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 39
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A tearDown() 0 4 1
A provideSimpleCase() 0 9 1
A testSimpleCase() 0 10 3
1
<?php
2
3
/**
4
 * This file is part of Fabrica.
5
 *
6
 * (c) Alexandre Salomé <[email protected]>
7
 * (c) Julien DIDIER <[email protected]>
8
 *
9
 * This source file is subject to the GPL license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Fabrica\Bundle\CoreBundle\Tests\Command;
14
15
use Fabrica\Bundle\CoreBundle\Test\CommandTestCase;
16
17
class PermissionCheckCommandTest extends CommandTestCase
18
{
19
    protected $client;
20
21
    protected function setUp(): void
22
    {
23
        $this->client = self::createClient();
24
        $this->client->startIsolation();
25
    }
26
27
    public function tearDown(): void
28
    {
29
        $this->client->stopIsolation();
30
    }
31
32
    public function provideSimpleCase()
33
    {
34
        return array(
35
            array('foobar', 'alice', 'PROJECT_READ',       true  ),
36
            array('barbaz', 'bob',   'PROJECT_READ',       false ),
37
            array(null,     'admin', 'ROLE_ADMIN',         true ),
38
            array(null,     'alice', 'ROLE_ADMIN',         false ),
39
        );
40
    }
41
42
    /**
43
     * @dataProvider provideSimpleCase
44
     */
45
    public function testSimpleCase($projectSlug, $username, $permission, $expected)
46
    {
47
        $projectSuffix = $projectSlug === null ? '' : '--project='.$projectSlug;
48
49
        $command = sprintf('fabrica:permission-check %s %s %s', $projectSuffix, $username, $permission);
50
        list($statusCode, $output) = $this->runCommand($this->client, $command);
51
52
        $this->assertEquals($statusCode, $expected ? 0 : 1);
53
        $this->assertEquals('', $output); // Output must be empty, otherwise displayed to user pushing
54
    }
55
}
56