Skip to content

Commit

Permalink
Merge 588d5ef into 603e201
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Nov 29, 2017
2 parents 603e201 + 588d5ef commit 98dacf2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
64 changes: 64 additions & 0 deletions Tests/Profiler/DataCollector/BlockDataCollectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\BlockBundle\Tests\Profiler\DataCollector;

use PHPUnit\Framework\TestCase;
use Sonata\BlockBundle\Profiler\DataCollector\BlockDataCollector;
use Sonata\BlockBundle\Templating\Helper\BlockHelper;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
* Block data collector test.
*
* @author Olivier Paradis <paradis.olivier@gmail.com>
*/
final class BlockDataCollectorTest extends TestCase
{
public function testBlockDataCollector()
{
$blockHelper = $this->prophesize(BlockHelper::class);
$request = $this->prophesize(Request::class);
$response = $this->prophesize(Response::class);

$blockDataCollector = new BlockDataCollector($blockHelper->reveal(), ['container']);

$expectedEvents = ['1' => '2', '3' => '4'];
$expectedBlocks = [
'_events' => ['1' => '2', '3' => '4'],
'test1' => ['type' => 'container'],
'test2' => ['type' => 'another_type'],
];
$expectedContainers = ['test1' => ['type' => 'container']];
$expectedRealBlocks = ['test2' => ['type' => 'another_type']];

$blockHelper->getTraces()->willReturn([
'_events' => ['1' => '2', '3' => '4'],
'test1' => ['type' => 'container'],
'test2' => ['type' => 'another_type'],
]);

$blockDataCollector->collect($request->reveal(), $response->reveal());

$this->assertSame($expectedEvents, $blockDataCollector->getEvents());
$this->assertSame($expectedBlocks, $blockDataCollector->getBlocks());
$this->assertSame($expectedContainers, $blockDataCollector->getContainers());
$this->assertSame($expectedRealBlocks, $blockDataCollector->getRealBlocks());

$blockDataCollector->reset();

$this->assertSame([], $blockDataCollector->getEvents());
$this->assertSame([], $blockDataCollector->getBlocks());
$this->assertSame([], $blockDataCollector->getContainers());
$this->assertSame([], $blockDataCollector->getRealBlocks());
}
}
11 changes: 11 additions & 0 deletions src/Profiler/DataCollector/BlockDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,15 @@ public function getName()
{
return 'block';
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->blocks = [];
$this->containers = [];
$this->realBlocks = [];
$this->events = [];
}
}

0 comments on commit 98dacf2

Please sign in to comment.