<commit_before><?php

namespace Brera\Product\Block;

use Brera\Product\FilterNavigationFilterCollection;
use Brera\Product\FilterNavigationFilterOption;
use Brera\Renderer\Block;
use Brera\Renderer\BlockRenderer;
use Brera\Renderer\InvalidDataObjectException;

/**
 * @covers \Brera\Product\Block\FilterNavigationBlock
 * @uses   \Brera\Renderer\Block
 */
class FilterNavigationBlockTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var FilterNavigationBlock
     */
    private $block;

    /**
     * @var BlockRenderer|\PHPUnit_Framework_MockObject_MockObject
     */
    private $stubBlockRenderer;

    /**
     * @var FilterNavigationFilterCollection|\PHPUnit_Framework_MockObject_MockObject
     */
    private $stubFilterCollection;

    /**
     * @param string $filterCode
     * @param string $filterOptionValue
     * @return FilterNavigationFilterOption|\PHPUnit_Framework_MockObject_MockObject
     */
    private function createStubFilterOption($filterCode, $filterOptionValue)
    {
        $stubFilterOptionValue = $this->getMock(FilterNavigationFilterOption::class, [], [], '', false);
        $stubFilterOptionValue->method('getCode')->willReturn($filterCode);
        $stubFilterOptionValue->method('getValue')->willReturn($filterOptionValue);

        return $stubFilterOptionValue;
    }

    protected function setUp()
    {
        $this->stubBlockRenderer = $this->getMock(BlockRenderer::class, [], [], '', false);
        $this->stubFilterCollection = $this->getMock(FilterNavigationFilterCollection::class, [], [], '', false);
        $stubDataObject = $this->stubFilterCollection;

        $this->block = new FilterNavigationBlock($this->stubBlockRenderer, 'foo.phtml', 'foo', $stubDataObject);
    }

    public function testBlockClassIsExtended()
    {
        $this->assertInstanceOf(Block::class, $this->block);
    }

    public function testExceptionIsThrownIfDataObjectIsNotFilterNavigationFilterCollection()
    {
        $this->setExpectedException(
            InvalidDataObjectException::class,
            sprintf('Data object must be instance of %s, got "stdClass".', FilterNavigationFilterCollection::class)
        );
        $invalidDataObject = new \stdClass;
        $blockName = 'foo';
        $block = new FilterNavigationBlock($this->stubBlockRenderer, 'foo.phtml', $blockName, $invalidDataObject);
        $block->getFilterCollection();
    }

    public function testFilterNavigationFilterCollectionIsReturned()
    {
        $result = $this->block->getFilterCollection();
        $this->assertInstanceOf(FilterNavigationFilterCollection::class, $result);
    }

    public function testQueryStringContainsOnlyGivenFilterIfNoFiltersAreCurrentlySelected()
    {<commit_msg>Issue #326: Refactor FilterNavigationBlockTest<commit_after><?php

namespace Brera\Product\Block;

use Brera\Product\FilterNavigationFilterCollection;
use Brera\Product\FilterNavigationFilterOption;
use Brera\Renderer\Block;
use Brera\Renderer\BlockRenderer;
use Brera\Renderer\InvalidDataObjectException;

/**
 * @covers \Brera\Product\Block\FilterNavigationBlock
 * @uses   \Brera\Renderer\Block
 */
class FilterNavigationBlockTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var FilterNavigationBlock
     */
    private $block;

    /**
     * @var BlockRenderer|\PHPUnit_Framework_MockObject_MockObject
     */
    private $stubBlockRenderer;

    /**
     * @var FilterNavigationFilterCollection|\PHPUnit_Framework_MockObject_MockObject
     */
    private $stubFilterCollection;

    /**
     * @param string $filterCode
     * @param string $filterOptionValue
     * @return FilterNavigationFilterOption|\PHPUnit_Framework_MockObject_MockObject
     */
    private function createStubFilterOption($filterCode, $filterOptionValue)
    {
        $stubFilterOptionValue = $this->getMock(FilterNavigationFilterOption::class, [], [], '', false);
        $stubFilterOptionValue->method('getCode')->willReturn($filterCode);
        $stubFilterOptionValue->method('getValue')->willReturn($filterOptionValue);

        return $stubFilterOptionValue;
    }

    protected function setUp()
    {
        $this->stubBlockRenderer = $this->getMock(BlockRenderer::class, [], [], '', false);
        $blockName = 'foo';
        $this->stubFilterCollection = $this->getMock(FilterNavigationFilterCollection::class, [], [], '', false);
        $stubDataObject = $this->stubFilterCollection;

        $this->block = new FilterNavigationBlock($this->stubBlockRenderer, 'foo.phtml', $blockName, $stubDataObject);
    }

    public function testBlockClassIsExtended()
    {
        $this->assertInstanceOf(Block::class, $this->block);
    }

    public function testExceptionIsThrownIfDataObjectIsNotFilterNavigationFilterCollection()
    {
        $this->setExpectedException(
            InvalidDataObjectException::class,
            sprintf('Data object must be instance of %s, got "stdClass".', FilterNavigationFilterCollection::class)
        );
        $invalidDataObject = new \stdClass;
        $blockName = 'foo';
        $block = new FilterNavigationBlock($this->stubBlockRenderer, 'foo.phtml', $blockName, $invalidDataObject);
        $block->getFilterCollection();
    }

    public function testFilterNavigationFilterCollectionIsReturned()
    {
        $result = $this->block->getFilterCollection();
        $this->assertInstanceOf(FilterNavigationFilterCollection::class, $result);
    }

    public function testQueryStringContainsOnlyGivenFilterIfNoFiltersAreCurrentlySelected()
    {
{'fraction_non_alphanumeric': 0.1146059291395517, 'fraction_numerical': 0.0005422993492407809, 'mean_word_length': 4.0529680365296805, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '1371129', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1457, 'n_words': 227}