Repository: symfony/symfony
File: src/Symfony/Bundle/SecurityBundle/Tests/Command/SecurityRoleHierarchyDumpCommandTest.php (PHP)

Code before:
{
    public function testExecuteWithNoRoleHierarchy()
    {
        $command = new SecurityRoleHierarchyDumpCommand();
        $commandTester = new CommandTester($command);

        $exitCode = $commandTester->execute([]);

        $this->assertEquals(Command::SUCCESS, $exitCode);
        $this->assertStringContainsString('No role hierarchy is configured', $commandTester->getDisplay());
    }

    public function testExecuteWithRoleHierarchy()
    {
        $hierarchy = [
            'ROLE_ADMIN' => ['ROLE_USER'],
            'ROLE_SUPER_ADMIN' => ['ROLE_ADMIN', 'ROLE_USER'],
        ];

        $roleHierarchy = new RoleHierarchy($hierarchy);
        $command = new SecurityRoleHierarchyDumpCommand($roleHierarchy);
        $commandTester = new CommandTester($command);

        $exitCode = $commandTester->execute([]);

        $this->assertEquals(Command::SUCCESS, $exitCode);
        $output = $commandTester->getDisplay();
        $expectedOutput = <<<EXPECTED
graph TB
    ROLE_ADMIN
    ROLE_USER
    ROLE_SUPER_ADMIN
    ROLE_ADMIN --> ROLE_USER
    ROLE_SUPER_ADMIN --> ROLE_ADMIN
    ROLE_SUPER_ADMIN --> ROLE_USER

EXPECTED;

        $this->assertEquals($expectedOutput, $output);
    }

    public function testExecuteWithCustomDirection()
    {
        $hierarchy = [
            'ROLE_ADMIN' => ['ROLE_USER'],
        ];

        $roleHierarchy = new RoleHierarchy($hierarchy);
        $command = new SecurityRoleHierarchyDumpCommand($roleHierarchy);
        $commandTester = new CommandTester($command);


Review comment (suggestion):
```suggestion
        $this->assertSame(Command::SUCCESS, $exitCode);
```

Code after:
    public function testExecuteWithRoleHierarchy()
    {
        $hierarchy = [
            'ROLE_ADMIN' => ['ROLE_USER'],
            'ROLE_SUPER_ADMIN' => ['ROLE_ADMIN', 'ROLE_USER'],
        ];

        $roleHierarchy = new RoleHierarchy($hierarchy);
        $command = new SecurityRoleHierarchyDumpCommand($roleHierarchy);
        $commandTester = new CommandTester($command);

        $exitCode = $commandTester->execute([]);

        $this->assertSame(Command::SUCCESS, $exitCode);
        $output = $commandTester->getDisplay();
        $expectedOutput = <<<EXPECTED
            graph TB
                ROLE_ADMIN
                ROLE_USER
                ROLE_SUPER_ADMIN
                ROLE_ADMIN --> ROLE_USER
                ROLE_SUPER_ADMIN --> ROLE_ADMIN
                ROLE_SUPER_ADMIN --> ROLE_USER

            EXPECTED;

        $this->assertSame($expectedOutput, $output);
    }

    public function testExecuteWithCustomDirection()
    {
        $hierarchy = [
            'ROLE_ADMIN' => ['ROLE_USER'],
        ];

        $roleHierarchy = new RoleHierarchy($hierarchy);
        $command = new SecurityRoleHierarchyDumpCommand($roleHierarchy);
        $commandTester = new CommandTester($command);

        $exitCode = $commandTester->execute(['--direction' => 'BT']);

        $this->assertSame(Command::SUCCESS, $exitCode);
        $output = $commandTester->getDisplay();
        $this->assertStringContainsString('graph BT', $output);
    }

    public function testExecuteWithInvalidDirection()
    {
        $hierarchy = [
            'ROLE_ADMIN' => ['ROLE_USER'],
        ];