<commit_before><?php

namespace Mduk\Gowi\Http;

use Psr\Log\NullLogger as PsrNullLogger;

use Mduk\Gowi\Http\Application;
use Mduk\Gowi\Http\Application\Stage;
use Mduk\Gowi\Http\Application\Stage\Stub as StubStage;

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

class ApplicationTest extends \PHPUnit_Framework_TestCase {

    public function testRun() {
        $stage1 = $this->mockStage();
        $stage1->expects( $this->once() )->method( 'execute' );

        $stage2 = $this->mockStage();
        $stage2->expects( $this->once() )->method( 'execute' );

        $app = new Application('/tmp');
        $app->addStage( $stage1 );
        $app->addStage( $stage2 );
        $app->run();
    }

    public function testRun_ReturnStage() {
        $stage1 = $this->mockStage();
        $stage1->expects( $this->once() )
            ->method( 'execute' );

        $stage2 = $this->mockStage();
        $stage2->expects( $this->once() )
            ->method( 'execute' )
            ->will( $this->returnValue( $stage1 ) );

        $app = new Application('/tmp');
        $app->addStage( $stage2 );
        $app->run();
    }

    public function testRun_ReturnResponse() {
        $stage1 = $this->mockStage();
        $stage1->expects( $this->once() )
            ->method( 'execute' )
            ->will( $this->returnValue( new Response ) );

        $stage2 = $this->mockStage();
        $stage2->expects( $this->never() )
            ->method( 'execute' );

        $app = new Application('/tmp');
        $app->addStage( $stage1 );
        $app->addStage( $stage2 );
        $app->run();
    }

    public function testConfig() {
        $app = new Application('/tmp');
        $app->setConfig( 'foo', 'bar' );
        $this->assertEquals( 'bar', $app->getConfig( 'foo' ) );
    }

    public function testGetConfig_InvalidKey_NoDefault() {
        $this->setExpectedException( '\\Mduk\\Gowi\\Http\\Application\\Exception' );
        $app = new Application('/tmp');
        $app->getConfig( 'foo' );
    }

    public function testGetConfig_InvalidKey_WithDefault() {
        $app = new Application('/tmp');
        $this->assertEquals( 'bar', $app->getConfig( 'foo', 'bar' ) );
    }

    public function testServices() {
        $service = (object) [ 'foo' => 'bar' ];
        $app = new Application('/tmp');
        $app->setService( 'foo', $service );

        $this->assertEquals( $service, $app->getService( 'foo' ),
            "Didn't get the expected service back" );
    }

	public function testLog() {
		$app = new Application('/tmp');

		$this->assertInstanceOf( '\\Psr\\Log\\NullLogger', $app->getLogger(),
			"getLogger should return a Psr NullLogger");

		$log = new ArrayLogger;
		$app->setLogger( $log );<commit_msg>fix application test<commit_after><?php

namespace Mduk\Gowi\Http;

use Psr\Log\NullLogger as PsrNullLogger;

use Mduk\Gowi\Http\Application;
use Mduk\Gowi\Http\Application\Stage;
use Mduk\Gowi\Http\Application\Stage\Stub as StubStage;

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

class ApplicationTest extends \PHPUnit_Framework_TestCase {

    public function testRun() {
        $stage1 = $this->mockStage();
        $stage1->expects( $this->once() )->method( 'execute' );

        $stage2 = $this->mockStage();
        $stage2->expects( $this->once() )->method( 'execute' );

        $app = new Application('/tmp');
        $app->addStage( $stage1 );
        $app->addStage( $stage2 );
        $app->run();
    }

    public function testRun_ReturnStage() {
        $stage1 = $this->mockStage();
        $stage1->expects( $this->once() )
            ->method( 'execute' );

        $stage2 = $this->mockStage();
        $stage2->expects( $this->once() )
            ->method( 'execute' )
            ->will( $this->returnValue( $stage1 ) );

        $app = new Application('/tmp');
        $app->addStage( $stage2 );
        $app->run();
    }

    public function testRun_ReturnResponse() {
        $stage1 = $this->mockStage();
        $stage1->expects( $this->once() )
            ->method( 'execute' )
            ->will( $this->returnValue( new Response ) );

        $stage2 = $this->mockStage();
        $stage2->expects( $this->never() )
            ->method( 'execute' );

        $app = new Application('/tmp');
        $app->addStage( $stage1 );
        $app->addStage( $stage2 );
        $app->run();
    }

    public function testConfig() {
        $app = new Application('/tmp');
        $app->setConfig( 'foo', 'bar' );
        $this->assertEquals( 'bar', $app->getConfig( 'foo' ) );
    }

    public function testGetConfig_InvalidKey_NoDefault() {
        $this->setExpectedException( '\\Mduk\\Gowi\\Http\\Application\\Exception' );
        $app = new Application('/tmp');
        $app->getConfig( 'foo' );
    }

    public function testGetConfig_InvalidKey_WithDefault() {
        $app = new Application('/tmp');
        $this->assertEquals( 'bar', $app->getConfig( 'foo', 'bar' ) );
    }

    public function testServices() {
        $service = (object) [ 'foo' => 'bar' ];
        $app = new Application('/tmp');
        $app->setService( 'foo', $service );

        $this->assertEquals( $service, $app->getService( 'foo' ),
            "Didn't get the expected service back" );
    }

	public function testLog() {
		$app = new Application('/tmp');

		$this->assertInstanceOf( '\\Psr\\Log\\LoggerInterface', $app->getLogger(),
			"getLogger should return a PsrLogger");

		$log = new ArrayLogger;
		$app->setLogger( $log );
{'fraction_non_alphanumeric': 0.18017038245423236, 'fraction_numerical': 0.0065252854812398045, 'mean_word_length': 2.510178117048346, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5691921', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1707, 'n_words': 349}