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 UserSshKeyCreateCommandTest 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
|
|
View Code Duplication |
public function testSimpleCase() |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:user-ssh-key-create "alice" foo bar'); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$this->assertEquals("The key named foo was successfully added to user alice!\n", $output); |
37
|
|
|
|
38
|
|
|
$em = $this->client->getKernel()->getContainer()->get('doctrine')->getManager(); |
39
|
|
|
|
40
|
|
|
$userSshKey = $em->getRepository('FabricaCoreBundle:UserSshKey')->findOneBy( |
41
|
|
|
array( |
42
|
|
|
'title' => 'foo' |
43
|
|
|
) |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$this->assertInstanceOf('Fabrica\Models\Code\UserSshKey', $userSshKey); |
47
|
|
|
|
48
|
|
|
$this->assertEquals('alice', $userSshKey->getUser()->getUsername()); |
49
|
|
|
$this->assertEquals('foo', $userSshKey->getTitle()); |
50
|
|
|
$this->assertEquals('bar', $userSshKey->getContent()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testNonExistingUser() |
54
|
|
|
{ |
55
|
|
|
list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:user-ssh-key-create "foo" bar baz'); |
|
|
|
|
56
|
|
|
|
57
|
|
|
$this->assertContains('User with username "foo" not found', $output); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
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.