Spaces:
No application file
No application file
File size: 3,094 Bytes
d2897cd |
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
<?php
declare(strict_types=1);
namespace Mautic\InstallBundle\Tests\Command;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Mautic\CoreBundle\Doctrine\Connection\ConnectionWrapper;
use Mautic\InstallBundle\Command\InstallCommand;
use Mautic\InstallBundle\Install\InstallService;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Output\BufferedOutput;
class InstallCommandTest extends TestCase
{
/**
* @var MockObject&InstallService
*/
private MockObject $installer;
/**
* @var MockObject&Registry
*/
private MockObject $doctrineRegistry;
private InstallCommand $command;
protected function setUp(): void
{
parent::setUp();
$this->installer = $this->createMock(InstallService::class);
$this->doctrineRegistry = $this->createMock(Registry::class);
$application = $this->createMock(Application::class);
$inputDefinition = $this->createMock(InputDefinition::class);
$command = $this->createMock(Command::class);
$inputDefinition->method('getOptions')->willReturn([]);
$inputDefinition->method('getArguments')->willReturn([]);
$application->method('getHelperSet')->willReturn($this->createMock(HelperSet::class));
$application->method('getDefinition')->willReturn($inputDefinition);
$application->method('find')->willReturn($command);
$this->command = new InstallCommand($this->installer, $this->doctrineRegistry);
$this->command->setApplication($application);
}
public function testCommandWhenSiteInstalled(): void
{
$this->installer->method('checkIfInstalled')->willReturnOnConsecutiveCalls(true);
$input = new ArrayInput(['site_url' => 'localhost']);
$output = new BufferedOutput();
$this->command->run($input, $output);
$this->assertSame('Mautic already installed'.PHP_EOL, $output->fetch());
}
public function testCommandWhenSiteNotInstalled(): void
{
$this->installer->method('checkIfInstalled')->willReturnOnConsecutiveCalls(false);
$this->doctrineRegistry->method('getConnection')->willReturn($this->createMock(ConnectionWrapper::class));
$input = new ArrayInput(
[
'site_url' => 'localhost',
'--admin_firstname' => 'Admin',
'--admin_lastname' => 'Mautic',
'--admin_username' => 'admin',
'--admin_email' => '[email protected]',
'--admin_password' => 'password',
]
);
$output = new BufferedOutput();
$this->command->run($input, $output);
$this->assertStringContainsString('Install complete'.PHP_EOL, $output->fetch());
}
}
|