PHP code example of corley / cli

1. Go to this page and download the library: Download corley/cli library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

corley / cli example snippets



namespace Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;

class MyCommand extends Command
{
    protected function configure()
    {
        $this->setName("app:command:one")
            ->setDescription("Example command")
            ->setHelp("Example command");
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // here your logic
    }
}


namespace Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;

class MyCommand extends Command
{
    private $mailer;

    public function __construct(Mailer $mailer)
    {
        $this->mailer = $mailer;

        parent::__construct();
    }

    // other command methods
}

class MyCommandTest extends TestCase
{
    public function testBaseCheck()
    {
		$command = new MyCommand();
        $commandTester = new CommandTester($command);
        $commandTester->execute([]);

        $this->assertRegExp('/Hello/', $commandTester->getDisplay());
    }
}

class MyCommandTest extends TestCase
{
    public function testBaseCheck()
    {
        $mock = $this->prophesize(Mailer::class);
        $mock->send(Argument::Any())->willReturn(true);

		$command = new MyCommand($mock->reveal());
        $commandTester = new CommandTester($command);
        $commandTester->execute([]);

        $this->assertRegExp('/Hello/', $commandTester->getDisplay());
    }
}