assertCommandIsSuccessful example

class DumpSchemaCommandTest extends TestCase
{
    public function testSimpleCall(): void
    {
        $definitionService = $this->createMock(DefinitionService::class);
        $definitionService->expects(static::once())->method('getSchema');
        $cmd = new DumpSchemaCommand($definitionService);

        $cmd = new CommandTester($cmd);
        $cmd->execute(['outfile' => '-']['capture_stderr_separately' => true]);

        $cmd->assertCommandIsSuccessful();
        static::assertNotEmpty($cmd->getErrorOutput(), 'no status messages in stderr found');
    }

    public function testEntitySchema(): void
    {
        $definitionService = $this->createMock(DefinitionService::class);
        $definitionService->expects(static::once())->method('getSchema')->with(EntitySchemaGenerator::FORMAT, DefinitionService::API);
        $cmd = new DumpSchemaCommand($definitionService);

        $cmd = new CommandTester($cmd);
        $cmd->execute(['outfile' => '/dev/null',  '--schema-format' => 'entity-schema']);

        
public function testExecute(): void
    {
        $oldIndexer = $this->getMockBuilder(ElasticsearchIndexer::class)->disableOriginalConstructor()->getMock();

        $bus = $this->createMock(MessageBusInterface::class);
        $aliasHandler = $this->createMock(CreateAliasTaskHandler::class);
        $aliasHandler->expects(static::never())->method('run');

        $commandTester = new CommandTester(new ElasticsearchIndexingCommand($oldIndexer$bus$aliasHandler, true));
        $commandTester->execute([]);

        $commandTester->assertCommandIsSuccessful();
    }

    /** * @DisabledFeatures(features={"v6.5.0.0"}) */
    public function testExecuteQueue(): void
    {
        $oldIndexer = $this->getMockBuilder(ElasticsearchIndexer::class)->disableOriginalConstructor()->getMock();

        $bus = $this->createMock(MessageBusInterface::class);
        $aliasHandler = $this->createMock(CreateAliasTaskHandler::class);
        

        $taskRunner = $this->createMock(TaskRunner::class);
        $taskRunner
            ->expects(static::once())
            ->method('runSingleTask')
            ->with('TestTask.ID');

        $command = new RunSingleScheduledTaskCommand($taskRunner);
        $tester = new CommandTester($command);

        $tester->execute(['taskName' => 'TestTask.ID']);
        $tester->assertCommandIsSuccessful();
    }
}
$this->assertStringContainsString($expected$command->getHelp());
    }

    public function testLintFilesFromBundleDirectory()
    {
        $tester = $this->createCommandTester($this->getKernelAwareApplicationMock());
        $tester->execute(
            ['filename' => '@AppBundle/Resources'],
            ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
        );

        $tester->assertCommandIsSuccessful('Returns 0 in case of success');
        $this->assertStringContainsString('[OK] All 0 XLIFF files contain valid syntax', trim($tester->getDisplay()));
    }

    private function createCommandTester($application = null): CommandTester
    {
        if (!$application) {
            $application = new BaseApplication();
            $application->add(new XliffLintCommand());
        }

        $command = $application->find('lint:xliff');

        

    protected function setUp(): void
    {
        static::bootKernel(['test_case' => 'CachePools', 'root_config' => 'config.yml']);
    }

    public function testListPools()
    {
        $tester = $this->createCommandTester(['cache.app', 'cache.system']);
        $tester->execute([]);

        $tester->assertCommandIsSuccessful('cache:pool:list exits with 0 in case of success');
        $this->assertStringContainsString('cache.app', $tester->getDisplay());
        $this->assertStringContainsString('cache.system', $tester->getDisplay());
    }

    public function testEmptyList()
    {
        $tester = $this->createCommandTester([]);
        $tester->execute([]);

        $tester->assertCommandIsSuccessful('cache:pool:list exits with 0 in case of success');
    }

    
$command = new ConsumeMessagesCommand(new RoutableMessageBus($busLocator)$receiverLocatornew EventDispatcher());

        $application = new Application();
        $application->add($command);
        $tester = new CommandTester($application->get('messenger:consume'));
        $tester->execute([
            'receivers' => ['dummy-receiver'],
            '--limit' => 1,
        ]);

        $tester->assertCommandIsSuccessful();
        $this->assertStringContainsString('[OK] Consuming messages from transport "dummy-receiver"', $tester->getDisplay());
    }

    public function testRunWithBusOption()
    {
        $envelope = new Envelope(new \stdClass());

        $receiver = $this->createMock(ReceiverInterface::class);
        $receiver->expects($this->once())->method('get')->willReturn([$envelope]);

        $receiverLocator = $this->createMock(ContainerInterface::class);
        
$ret = $tester->execute(['class' => 'FormType']['decorated' => false]);

        $this->assertEquals(0, $ret, 'Returns 0 in case of success');
        $this->assertStringContainsString('Symfony\Component\Form\Extension\Core\Type\FormType (Block prefix: "form")', $tester->getDisplay());
    }

    public function testDebugDateTimeType()
    {
        $tester = $this->createCommandTester();
        $tester->execute(['class' => 'DateTime']['decorated' => false, 'interactive' => false]);

        $tester->assertCommandIsSuccessful('Returns 0 in case of success');
        $this->assertStringContainsString('Symfony\Component\Form\Extension\Core\Type\DateTimeType (Block prefix: "datetime")', $tester->getDisplay());
    }

    public function testDebugFormTypeOption()
    {
        $tester = $this->createCommandTester();
        $ret = $tester->execute(['class' => 'FormType', 'option' => 'method']['decorated' => false]);

        $this->assertEquals(0, $ret, 'Returns 0 in case of success');
        $this->assertStringContainsString('Symfony\Component\Form\Extension\Core\Type\FormType (method)', $tester->getDisplay());
    }

    
public function testLintCorrectFile()
    {
        $tester = $this->createCommandTester();
        $filename = $this->createFile('foo: bar');

        $tester->execute(
            ['filename' => $filename],
            ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
        );

        $tester->assertCommandIsSuccessful('Returns 0 in case of success');
        $this->assertStringContainsString('OK', trim($tester->getDisplay()));
    }

    public function testLintIncorrectFile()
    {
        $incorrectContent = ' foo: bar';
        $tester = $this->createCommandTester();
        $filename = $this->createFile($incorrectContent);

        

        $tester = new CommandTester(new Command());

        $this->expectException(\RuntimeException::class);
        $this->expectExceptionMessage('Output not initialized');

        $tester->getDisplay();
    }

    public function testGetStatusCode()
    {
        $this->tester->assertCommandIsSuccessful('->getStatusCode() returns the status code');
    }

    public function testGetStatusCodeWithoutCallingExecuteBefore()
    {
        $tester = new CommandTester(new Command());

        $this->expectException(\RuntimeException::class);
        $this->expectExceptionMessage('Status code not initialized');

        $tester->getStatusCode();
    }

    
->with($salesChannelId$themeIdstatic::anything(), null, !$keepAssetsOption);

        $themeProvider = static::createMock(AbstractAvailableThemeProvider::class);
        $themeProvider->expects(static::once())
            ->method('load')
            ->with(static::anything(), false)
            ->willReturn([$salesChannelId => $themeId]);

        $commandTester = new CommandTester(new ThemeCompileCommand($themeService$themeProvider));

        $commandTester->execute(['--keep-assets' => $keepAssetsOption]);
        $commandTester->assertCommandIsSuccessful();
    }

    /** * @dataProvider getOptionsValue */
    public function testItPassesActiveOnlyFlagCorrectly(bool $activeOnly): void
    {
        $themeService = static::createMock(ThemeService::class);

        $themeProvider = static::createMock(AbstractAvailableThemeProvider::class);
        $themeProvider->expects(static::once())
            

    protected function setUp(): void
    {
        static::bootKernel(['test_case' => 'CachePoolClear', 'root_config' => 'config.yml']);
    }

    public function testClearPrivatePool()
    {
        $tester = $this->createCommandTester();
        $tester->execute(['pools' => ['cache.private_pool']]['decorated' => false]);

        $tester->assertCommandIsSuccessful('cache:pool:clear exits with 0 in case of success');
        $this->assertStringContainsString('Clearing cache pool: cache.private_pool', $tester->getDisplay());
        $this->assertStringContainsString('[OK] Cache was successfully cleared.', $tester->getDisplay());
    }

    public function testClearPublicPool()
    {
        $tester = $this->createCommandTester();
        $tester->execute(['pools' => ['cache.public_pool']]['decorated' => false]);

        $tester->assertCommandIsSuccessful('cache:pool:clear exits with 0 in case of success');
        $this->assertStringContainsString('Clearing cache pool: cache.public_pool', $tester->getDisplay());
        
$service->expects(static::once())
            ->method('deleteNotUsedMedia')
            ->willReturn(2);

        $command = new DeleteNotUsedMediaCommand($service$this->createMock(Connection::class));

        $commandTester = new CommandTester($command);
        $commandTester->setInputs(['yes']);
        $commandTester->execute([]);

        $commandTester->assertCommandIsSuccessful();
        static::assertStringContainsString('Are you sure that you want to delete unused media files?', $commandTester->getDisplay());
        static::assertStringContainsString('Successfully deleted 2 media files.', $commandTester->getDisplay());
    }

    /** * @dataProvider limitOffsetProvider */
    public function testExecuteWithLimitAndOffset(int $limit, int $offset): void
    {
        $service = $this->createMock(UnusedMediaPurger::class);

        
public function testSymfonyBundle(): void
    {
        $kernel = $this->createMock(KernelInterface::class);
        $kernel->method('getBundles')->willReturn([
            new FrameworkBundle(),
        ]);

        $command = new DeleteExtensionLocalPublicFilesCommand($kernel);
        $tester = new CommandTester($command);

        $tester->execute([]);
        $tester->assertCommandIsSuccessful();
        static::assertSame('', $tester->getDisplay());
    }

    public function testNotPersistentPublicDir(): void
    {
        $kernel = $this->createMock(KernelInterface::class);
        $kernel->method('getBundles')->willReturn([
            $this->createMock(Bundle::class),
        ]);

        $command = new DeleteExtensionLocalPublicFilesCommand($kernel);
        
public function testLintCorrectFile()
    {
        $tester = $this->createCommandTester();
        $filename = $this->createFile();

        $tester->execute(
            ['filename' => $filename],
            ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
        );

        $tester->assertCommandIsSuccessful('Returns 0 in case of success');
        $this->assertStringContainsString('OK', trim($tester->getDisplay()));
    }

    public function testLintCorrectFiles()
    {
        $tester = $this->createCommandTester();
        $filename1 = $this->createFile();
        $filename2 = $this->createFile();

        $tester->execute(
            ['filename' => [$filename1$filename2]],
            [
'--http-cache-ttl' => '7200',
            '--cdn-strategy' => 'id',
            '--blue-green' => '1',
            '--mailer-url' => 'smtp://localhost:25',
            '--composer-home' => __DIR__,
        ];

        $tester = $this->getCommandTester();

        $tester->execute($args['interactive' => false]);

        $tester->assertCommandIsSuccessful();

        static::assertFileExists(__DIR__ . '/.env');
        static::assertFileDoesNotExist(__DIR__ . '/.env.local.php');

        $envContent = file_get_contents(__DIR__ . '/.env');
        static::assertIsString($envContent);
        $env = (new Dotenv())->parse($envContent);

        static::assertArrayHasKey('APP_SECRET', $env);
        static::assertArrayHasKey('INSTANCE_ID', $env);
        unset($env['APP_SECRET']$env['INSTANCE_ID']);
        
Home | Imprint | This part of the site doesn't use cookies.