Skip to content

Commit

Permalink
added test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza committed Aug 28, 2024
1 parent 59503aa commit 828634c
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions tests/bundle/Command/UpdateUserCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Bundle\User\Command;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;

final class UpdateUserCommandTest extends KernelTestCase
{
private readonly CommandTester $commandTester;

protected function setUp(): void
{
self::bootKernel();

$application = new Application(self::$kernel);
$application->setAutoExit(false);

$command = $application->find('ibexa:user:update-user');
$this->commandTester = new CommandTester($command);
}

public function testExecuteWithoutOptionsReturnsFailure(): void
{
$this->commandTester->execute([
'user' => 'admin',
]);

self::assertStringContainsString(
'No new user data specified, exiting.',
$this->commandTester->getDisplay()
);

self::assertSame(
Command::FAILURE,
$this->commandTester->getStatusCode()
);
}

public function testExecuteWithEnableAndDisableOptionsReturnsFailure(): void
{
$this->commandTester->execute(
[
'user' => 'admin',
'--enable' => true,
'--disable' => true,
],
);

self::assertStringContainsString(
'--enable and --disable options cannot be used simultaneously.',
$this->commandTester->getDisplay()
);

self::assertSame(
Command::FAILURE,
$this->commandTester->getStatusCode()
);
}

public function testExecuteReturnsSuccess(): void
{
$this->commandTester->execute(
[
'user' => 'admin',
'--password' => true,
'--email' => 'foo@bar.com',
'--enable' => true,
],
);

self::assertStringContainsString(
'User was successfully updated.',
$this->commandTester->getDisplay()
);

$this->commandTester->assertCommandIsSuccessful();
}
}

0 comments on commit 828634c

Please sign in to comment.