-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserCreateCommandTest.php
More file actions
55 lines (45 loc) · 1.73 KB
/
Copy pathUserCreateCommandTest.php
File metadata and controls
55 lines (45 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace App\Tests\Integration\Command;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
/**
* Relies on the baseline `UserFixtures` (alice + bob) loaded by
* `tests/bootstrap_integration.php`. The "create fresh user" path uses
* a non-fixture email to avoid colliding with the baseline.
*/
final class UserCreateCommandTest extends KernelTestCase
{
private CommandTester $tester;
protected function setUp(): void
{
self::bootKernel();
$application = new Application(self::$kernel);
$command = $application->find('app:user:create');
$this->tester = new CommandTester($command);
}
// Tests that the command creates a new user and reports success on a fresh email.
public function testCreatesUser(): void
{
$exit = $this->tester->execute([
'email' => 'charlie@example.test',
'name' => 'Charlie',
'password' => 'secret',
]);
self::assertSame(0, $exit);
self::assertStringContainsString('Created user "charlie@example.test"', $this->tester->getDisplay());
}
// Ensures the command exits non-zero when the email collides with an existing user.
public function testReportsFailureWhenEmailAlreadyExists(): void
{
// alice@example.test is in the baseline fixtures.
$exit = $this->tester->execute([
'email' => 'alice@example.test',
'name' => 'Alice',
'password' => 'second',
]);
self::assertSame(1, $exit);
self::assertStringContainsString('already exists', $this->tester->getDisplay());
}
}