<?php

class ExtCommandTest extends PHPUnit_Framework_TestCase
{
    public function testOutput()
    {
        ob_start();
        $console = new PhpBrew\Console;
        $console->run( array(null, 'ext') );

        $output = explode("\n", ob_get_clean());

        $extensions = count(get_loaded_extensions());

        $this->assertSame('', array_pop($output)); // must end with a blank line
        
        foreach ($output as $line => $buffer) {
            if($line === 0) { // title
                $this->assertContains('Loaded extensions:', $buffer);
            } else if($line <= $extensions) { // loaded extensions
                $this->assertContains('[*]', $buffer);
            } else if($line == $extensions + 1) { // title
                $this->assertContains('Available extensions:', $buffer);
            } else { // available extensions
                $this->assertContains('[ ]', $buffer);
            }
        }
    }

    public function testOutputWithDifferentPHPVersion()
    {
        ob_start();
        $console = new PhpBrew\Console;
        $console->run( array(null, 'ext', '--php', '0.0') );
        $output = ob_get_clean();

        $this->assertContains('PHP version is different from current active version.', $output);
    }
}

<?php

class ExtCommandTest extends PHPUnit_Framework_TestCase
{
    protected $application;

    protected function setUp()
    {
        $this->application = new PhpBrew\Console;
        $this->application->getLogger()->getFormatter()->preferRawOutput(); // use non colored output
    }

    public function testOutput()
    {
        ob_start();
        $this->application->run( array(null, 'ext') );
        $output = ob_get_clean();

        $this->assertEquals(1, preg_match_all('#^Loaded extensions:#m', $output, $matches)); // match once
        $this->assertRegExp('#\[\*\]\s+\w+$#m', $output);
        $this->assertEquals(count(get_loaded_extensions()), preg_match_all('#\[\*\]#', $output, $matches));
        $this->assertEquals(1, preg_match_all('#^Available extensions:#m', $output, $matches)); // match once
        $this->assertRegExp('#\[ \]\s+\w+$#m', $output);
    }

    /**
     * @outputBuffering enabled
     */
    public function testOutputWithDifferentPHPVersion()
    {
        $this->application->run( array(null, 'ext', '--php', '0.0') );

        $this->expectOutputRegex('#^PHP version is different from current active version.#');
    }
}

Revert last test. Better to test raw cli output instead of add dirty workarounds.
Revert last test. Better to test raw cli output instead of add dirty workarounds.

Revert "better test for `ext` command output since binary strings cant be tested with regex #242 #253"

This reverts commit 1a99f9de6413866800eed909c2286053aaa97ec6.
