<commit_before><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @see       https://github.com/zendframework/zend-expressive for the canonical source repository
 * @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License
 */

namespace ZendTest\Expressive\Emitter;

use PHPUnit_Framework_TestCase as TestCase;
use Prophecy\Argument;
use Zend\Expressive\Emitter\EmitterStack;

/**
 * @covers Zend\Expressive\Emitter\EmitterStack
 */
class EmitterStackTest extends TestCase
{
    public function setUp()
    {
        $this->emitter = new EmitterStack();
    }

    public function testIsAnSplStack()
    {
        $this->assertInstanceOf('SplStack', $this->emitter);
    }

    public function testIsAnEmitterImplementation()
    {
        $this->assertInstanceOf('Zend\Diactoros\Response\EmitterInterface', $this->emitter);
    }

    public function nonEmitterValues()
    {
        return [
            'null'       => [null],
            'true'       => [true],
            'false'      => [false],
            'zero'       => [0],
            'int'        => [1],
            'zero-float' => [0.0],
            'float'      => [1.1],
            'string'     => ['emitter'],
            'array'      => [[$this->prophesize('Zend\Diactoros\Response\EmitterInterface')->reveal()]],
            'object'     => [(object)[]],
        ];
    }

    /**
     * @dataProvider nonEmitterValues
     */
    public function testCannotPushNonEmitterToStack($value)
    {
        $this->setExpectedException('InvalidArgumentException');
        $this->emitter->push($value);
    }

    /**
     * @dataProvider nonEmitterValues
     */
    public function testCannotUnshiftNonEmitterToStack($value)
    {
        $this->setExpectedException('InvalidArgumentException');
        $this->emitter->unshift($value);
    }

    /**
     * @dataProvider nonEmitterValues
     */
    public function testCannotSetNonEmitterToSpecificIndex($value)
    {
        $this->setExpectedException('InvalidArgumentException');
        $this->emitter->offsetSet(0, $value);
    }

    public function testEmitLoopsThroughEmittersUntilOneReturnsNonFalseValue()
    {
        $first = $this->prophesize('Zend\Diactoros\Response\EmitterInterface');
        $first->emit()->shouldNotBeCalled();

        $second = $this->prophesize('Zend\Diactoros\Response\EmitterInterface');
        $second->emit(Argument::type('Psr\Http\Message\ResponseInterface'))
            ->willReturn(null);

        $third = $this->prophesize('Zend\Diactoros\Response\EmitterInterface');
        $third->emit(Argument::type('Psr\Http\Message\ResponseInterface'))
            ->willReturn(false);

        $this->emitter->push($first->reveal());
        $this->emitter->push($second->reveal());
        $this->emitter->push($third->reveal());

        $response = $this->prophesize('Psr\Http\Message\ResponseInterface');<commit_msg>Full coverage for EmitterStack class<commit_after><?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @see       https://github.com/zendframework/zend-expressive for the canonical source repository
 * @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License
 */

namespace ZendTest\Expressive\Emitter;

use PHPUnit_Framework_TestCase as TestCase;
use Prophecy\Argument;
use Zend\Expressive\Emitter\EmitterStack;

/**
 * @covers Zend\Expressive\Emitter\EmitterStack
 */
class EmitterStackTest extends TestCase
{
    /** @var EmitterStack */
    private $emitter;

    public function setUp()
    {
        $this->emitter = new EmitterStack();
    }

    public function testIsAnSplStack()
    {
        $this->assertInstanceOf('SplStack', $this->emitter);
    }

    public function testIsAnEmitterImplementation()
    {
        $this->assertInstanceOf('Zend\Diactoros\Response\EmitterInterface', $this->emitter);
    }

    public function nonEmitterValues()
    {
        return [
            'null'       => [null],
            'true'       => [true],
            'false'      => [false],
            'zero'       => [0],
            'int'        => [1],
            'zero-float' => [0.0],
            'float'      => [1.1],
            'string'     => ['emitter'],
            'array'      => [[$this->prophesize('Zend\Diactoros\Response\EmitterInterface')->reveal()]],
            'object'     => [(object)[]],
        ];
    }

    /**
     * @dataProvider nonEmitterValues
     */
    public function testCannotPushNonEmitterToStack($value)
    {
        $this->setExpectedException('InvalidArgumentException');
        $this->emitter->push($value);
    }

    /**
     * @dataProvider nonEmitterValues
     */
    public function testCannotUnshiftNonEmitterToStack($value)
    {
        $this->setExpectedException('InvalidArgumentException');
        $this->emitter->unshift($value);
    }

    /**
     * @dataProvider nonEmitterValues
     */
    public function testCannotSetNonEmitterToSpecificIndex($value)
    {
        $this->setExpectedException('InvalidArgumentException');
        $this->emitter->offsetSet(0, $value);
    }

    public function testOffsetSetReplacesExistingValue()
    {
        $first = $this->prophesize('Zend\Diactoros\Response\EmitterInterface');
        $replacement = $this->prophesize('Zend\Diactoros\Response\EmitterInterface');
        $this->emitter->push($first->reveal());
        $this->emitter->offsetSet(0, $replacement->reveal());
        $this->assertSame($replacement->reveal(), $this->emitter->pop());
    }

    public function testUnshiftAddsNewEmitter()
    {
        $first = $this->prophesize('Zend\Diactoros\Response\EmitterInterface');
        $second = $this->prophesize('Zend\Diactoros\Response\EmitterInterface');
        $this->emitter->push($first->reveal());
        $this->emitter->unshift($second->reveal());
        $this->assertSame($second->reveal(), $this->emitter->pop());
    }

    public function testEmitLoopsThroughEmittersUntilOneReturnsNonFalseValue()
    {
        $first = $this->prophesize('Zend\Diactoros\Response\EmitterInterface');
        $first->emit()->shouldNotBeCalled();

        $second = $this->prophesize('Zend\Diactoros\Response\EmitterInterface');
        $second->emit(Argument::type('Psr\Http\Message\ResponseInterface'))
            ->willReturn(null);

        $third = $this->prophesize('Zend\Diactoros\Response\EmitterInterface');
        $third->emit(Argument::type('Psr\Http\Message\ResponseInterface'))
            ->willReturn(false);

        $this->emitter->push($first->reveal());
        $this->emitter->push($second->reveal());
        $this->emitter->push($third->reveal());

        $response = $this->prophesize('Psr\Http\Message\ResponseInterface');
{'fraction_non_alphanumeric': 0.15394622723330442, 'fraction_numerical': 0.00332466030644695, 'mean_word_length': 2.8374930671103717, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 117, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '4103025', 'n_tokens_mistral': 2066, 'n_tokens_neox': 1991, 'n_words': 274}