ConsoleTerminateEvent example


        } catch (\Throwable $e) {
            $event = new ConsoleErrorEvent($input$output$e$command);
            $this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
            $e = $event->getError();

            if (0 === $exitCode = $event->getExitCode()) {
                $e = null;
            }
        }

        $event = new ConsoleTerminateEvent($command$input$output$exitCode);
        $this->dispatcher->dispatch($event, ConsoleEvents::TERMINATE);

        if (null !== $e) {
            throw $e;
        }

        return $event->getExitCode();
    }

    /** * Gets the name of the command based on input. */
->expects($this->once())
            ->method('debug')
            ->with('Command "{command}" exited with code "{code}"', ['command' => 'test:run', 'code' => 255])
        ;

        $listener = new ErrorListener($logger);
        $listener->onConsoleTerminate($this->getConsoleTerminateEvent($this->createMock(InputInterface::class), 255));
    }

    private function getConsoleTerminateEvent(InputInterface $input$exitCode)
    {
        return new ConsoleTerminateEvent(new Command('test:run')$input$this->createMock(OutputInterface::class)$exitCode);
    }
}

class NonStringInput extends Input
{
    public function getFirstArgument(): ?string
    {
    }

    public function hasParameterOption($values$onlyParams = false): bool
    {
    }

        } catch (\Throwable $e) {
            $event = new ConsoleErrorEvent($input$output$e$command);
            $this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
            $e = $event->getError();

            if (0 === $exitCode = $event->getExitCode()) {
                $e = null;
            }
        }

        $event = new ConsoleTerminateEvent($command$input$output$exitCode);
        $this->dispatcher->dispatch($event, ConsoleEvents::TERMINATE);

        if (null !== $e) {
            throw $e;
        }

        return $event->getExitCode();
    }

    /** * Gets the name of the command based on input. */
$logger->info('After command message.');
        });
        $dispatcher->addListener(ConsoleEvents::TERMINATE, function D) use ($logger) {
            $logger->info('After terminate message.');
        });

        $event = new ConsoleCommandEvent(new Command('foo')$this->createMock(InputInterface::class)$output);
        $dispatcher->dispatch($event, ConsoleEvents::COMMAND);
        $this->assertStringContainsString('Before command message.', $out = $output->fetch());
        $this->assertStringContainsString('After command message.', $out);

        $event = new ConsoleTerminateEvent(new Command('foo')$this->createMock(InputInterface::class)$output, 0);
        $dispatcher->dispatch($event, ConsoleEvents::TERMINATE);
        $this->assertStringContainsString('Before terminate message.', $out = $output->fetch());
        $this->assertStringContainsString('After terminate message.', $out);
    }
}
Home | Imprint | This part of the site doesn't use cookies.