Skip to content

Commit

Permalink
Merge branch '3.x'
Browse files Browse the repository at this point in the history
Conflicts:
	Tests/Block/AbstractBlockServiceTest.php
  • Loading branch information
soullivaneuh committed Jul 12, 2016
2 parents b3f1d40 + cf1b8b4 commit 815e66c
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 75 deletions.
7 changes: 6 additions & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ $ php -v

## Actual results

<!-- If it's an error message or piece of code, use code block tags. -->
<!--
If it's an error message or piece of code, use code block tags,
and make sure you provide the whole stack trace(s),
not just the first error message you can see.
More details here: https://github.com/sonata-project/SonataBlockBundle/blob/3.x/CONTRIBUTING.md#issues
-->
2 changes: 2 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ enabled:
finder:
exclude:
- 'Tests/Fixtures'
# ecommerce special case:
- 'Resources/skeleton'
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.1.0](https://github.com/sonata-project/SonataBlockBundle/compare/3.0.1...3.1.0) - 2016-07-12
### Changed
- Tests for `*BlockService*` now uses `AbstractBlockServiceTestCase`

### Deprecated
- Deprecate empty class `BaseTestBlockService`
- Deprecate `Tests\Block\AbstractBlockServiceTest` in favor of `Test\AbstractBlockServiceTestCase`

### Fixed
- Profiler block design for Symfony Profiler v2

### Removed
- Internal test classes are now excluded from the auto-loader

## [3.0.1](https://github.com/sonata-project/SonataBlockBundle/compare/3.0.0...3.0.1) - 2016-06-14
### Changed
- The log level on exceptions in `BlockRenderer` is decreased from critical to error
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Github by following these points are taken care of:
end of the page. Just look for "Stack Trace (Plain Text)", and copy/paste what
you see. **Do not** make a screenshot of the stack trace, as screenshots are
not indexed by search engines and will make it difficult for other people to
find your bug report.
find your bug report. If you have an issue when using the Symfony CLI,
use the `-vvv` option to get a stack trace.
* Screenshots should be considered additional data, and therefore, you should
always provide a textual description of the bug. It is strongly recommended
to provide them when reporting UI-related bugs.
Expand Down
1 change: 0 additions & 1 deletion Exception/Strategy/StrategyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public function handleException(\Exception $exception, BlockInterface $block, Re
}
// render empty block template?

return $response;
}

Expand Down
79 changes: 77 additions & 2 deletions Resources/views/Profiler/block.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
{% endblock %}

{% block panel %}
{# NEXT_MAJOR : remove this when Symfony Requirement will be bumped to 2.8+ #}
{% set profiler_markup_version = profiler_markup_version|default(1) %}

<h2>Events Blocks</h2>
<table>
<tr>
Expand Down Expand Up @@ -92,11 +95,23 @@

<h2>Real Blocks</h2>
{% set blocks = collector.realBlocks %}
{{ block('table') }}
{% if profiler_markup_version == 1 %}
{{ block('table') }}
{% else %}
<div class="tab-content">
{{ block('table_v2') }}
</div>
{% endif %}

<h2>Containers Blocks</h2>
{% set blocks = collector.containers %}
{{ block('table') }}
{% if profiler_markup_version == 1 %}
{{ block('table') }}
{% else %}
<div class="tab-content">
{{ block('table_v2') }}
</div>
{% endif %}

{{ block('javascript') }}
{% endblock %}
Expand Down Expand Up @@ -157,3 +172,63 @@
{% endfor %}
</table>
{% endblock %}

{% block table_v2 %}
{% for id, block in blocks %}
<table>
<thead>
<tr>
<th colspan="2">Block {{ id }}</th>
</tr>
</thead>
<tbody>
<tr>
<th>Name</th>
<td>{{ block.name }}</td>
</tr>
<tr>
<th>Type</th>
<td>{{ block.type }}</td>
</tr>
<tr>
<th>Mem. diff / Mem. peak / Duration</th>
<td>{{ ((block.memory_end-block.memory_start)/1000)|number_format(0) }} Kb / {{ (block.memory_peak/1000)|number_format(0) }} Kb / {{ block.duration|number_format(2) }} ms</td>
</tr>

{% if block.cache.handler %}
<tr>
<th>Cache backend</th>
<td>
{{ block.cache.handler }} - Loading from cache: {% if block.cache.from_cache %}YES{% else %}NO{% endif %}
</td>
</tr>
<tr>
<th>Cache TTL / Lifetime</th>
<td>
{{ block.cache.ttl }}s. / {{ block.cache.lifetime }}s
</td>
</tr>
<tr>
<th>
Cache Informations
</th>
<td>
Cache Keys: <pre>{{ block.cache.keys|json_encode() }}</pre> <br />
Contextual Keys: <pre>{{ block.cache.contextual_keys|json_encode() }}</pre> <br />
</td>
</tr>
{% endif %}

{% if block.assets.js|length > 0 or block.assets.css|length > 0 %}
<tr>
<th>Assets</th>
<td>
Javascripts: <pre>{{ block.assets.js|json_encode() }}</pre><br />
Stylesheets: <pre>{{ block.assets.css|json_encode() }}</pre>
</td>
</tr>
{% endif %}
</tbody>
</table>
{% endfor %}
{% endblock %}
81 changes: 81 additions & 0 deletions Test/AbstractBlockServiceTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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\Test;

use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\BlockContextManager;
use Sonata\BlockBundle\Block\BlockContextManagerInterface;
use Sonata\BlockBundle\Block\BlockServiceInterface;
use Sonata\BlockBundle\Block\BlockServiceManagerInterface;
use Sonata\BlockBundle\Tests\Block\Service\FakeTemplating;

/**
* Abstract test class for block service tests.
*
* @author Sullivan Senechal <soullivaneuh@gmail.com>
*/
abstract class AbstractBlockServiceTestCase extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject|BlockServiceManagerInterface
*/
protected $blockServiceManager;

/**
* @var BlockContextManagerInterface
*/
protected $blockContextManager;

/**
* @var FakeTemplating
*/
protected $templating;

protected function setUp()
{
$this->templating = new FakeTemplating();

$blockLoader = $this->getMock('Sonata\BlockBundle\Block\BlockLoaderInterface');
$this->blockServiceManager = $this->getMock('Sonata\BlockBundle\Block\BlockServiceManagerInterface');
$this->blockContextManager = new BlockContextManager($blockLoader, $this->blockServiceManager);
}

protected function getBlockContext(BlockServiceInterface $blockService)
{
$this->blockServiceManager->expects($this->once())->method('get')->will($this->returnValue($blockService));

$block = $this->getMock('Sonata\BlockBundle\Model\BlockInterface');
$block->expects($this->once())->method('getSettings')->will($this->returnValue(array()));

$blockContext = $this->blockContextManager->get($block);
$this->assertInstanceOf('Sonata\BlockBundle\Block\BlockContextInterface', $blockContext);

return $blockContext;
}

protected function assertSettings(array $expected, BlockContextInterface $blockContext)
{
$completeExpectedOptions = array_merge(array(
'use_cache' => true,
'extra_cache_keys' => array(),
'attr' => array(),
'template' => false,
'ttl' => 0,
), $expected);

ksort($completeExpectedOptions);
$blockSettings = $blockContext->getSettings();
ksort($blockSettings);

$this->assertSame($completeExpectedOptions, $blockSettings);
}
}
72 changes: 9 additions & 63 deletions Tests/Block/AbstractBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,71 +11,17 @@

namespace Sonata\BlockBundle\Tests\Block;

use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\BlockContextManager;
use Sonata\BlockBundle\Block\BlockContextManagerInterface;
use Sonata\BlockBundle\Block\BlockServiceInterface;
use Sonata\BlockBundle\Block\BlockServiceManagerInterface;
use Sonata\BlockBundle\Tests\Block\Service\FakeTemplating;
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;

@trigger_error(
'The '.__NAMESPACE__.'\AbstractBlockServiceTest class is deprecated since version 3.x and will be removed in 4.0.'
.' Use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase instead.',
E_USER_DEPRECATED
);

/**
* Abstract test class for block service tests.
*
* @author Sullivan Senechal <soullivaneuh@gmail.com>
* @deprecated Deprecated since version 3.x. Use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase instead.
*/
abstract class AbstractBlockServiceTest extends \PHPUnit_Framework_TestCase
abstract class AbstractBlockServiceTest extends AbstractBlockServiceTestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject|BlockServiceManagerInterface
*/
protected $blockServiceManager;

/**
* @var BlockContextManagerInterface
*/
protected $blockContextManager;

/**
* @var FakeTemplating
*/
protected $templating;

protected function setUp()
{
$this->templating = new FakeTemplating();

$blockLoader = $this->getMock('Sonata\BlockBundle\Block\BlockLoaderInterface');
$this->blockServiceManager = $this->getMock('Sonata\BlockBundle\Block\BlockServiceManagerInterface');
$this->blockContextManager = new BlockContextManager($blockLoader, $this->blockServiceManager);
}

protected function getBlockContext(BlockServiceInterface $blockService)
{
$this->blockServiceManager->expects($this->once())->method('get')->will($this->returnValue($blockService));

$block = $this->getMock('Sonata\BlockBundle\Model\BlockInterface');
$block->expects($this->once())->method('getSettings')->will($this->returnValue(array()));

$blockContext = $this->blockContextManager->get($block);
$this->assertInstanceOf('Sonata\BlockBundle\Block\BlockContextInterface', $blockContext);

return $blockContext;
}

protected function assertSettings(array $expected, BlockContextInterface $blockContext)
{
$completeExpectedOptions = array_merge(array(
'use_cache' => true,
'extra_cache_keys' => array(),
'attr' => array(),
'template' => false,
'ttl' => 0,
), $expected);

ksort($completeExpectedOptions);
$blockSettings = $blockContext->getSettings();
ksort($blockSettings);

$this->assertSame($completeExpectedOptions, $blockSettings);
}
}
8 changes: 8 additions & 0 deletions Tests/Block/Service/BaseTestBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

namespace Sonata\BlockBundle\Tests\Block\Service;

@trigger_error(
'The '.__NAMESPACE__.'\BaseTestBlockService class is deprecated since version 3.x and will be removed in 4.0.',
E_USER_DEPRECATED
);

/**
* @deprecated Deprecated since version 3.x and will be removed in 4.0.
*/
class BaseTestBlockService extends \PHPUnit_Framework_TestCase
{
}
6 changes: 3 additions & 3 deletions Tests/Block/Service/RssBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
use Sonata\BlockBundle\Block\BlockContext;
use Sonata\BlockBundle\Block\Service\RssBlockService;
use Sonata\BlockBundle\Model\Block;
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
use Sonata\BlockBundle\Util\OptionsResolver;

class RssBlockServiceTest extends BaseTestBlockService
class RssBlockServiceTest extends AbstractBlockServiceTestCase
{
/*
* only test if the API is not broken
*/
public function testService()
{
$templating = new FakeTemplating();
$service = new RssBlockService('sonata.page.block.rss', $templating);
$service = new RssBlockService('sonata.page.block.rss', $this->templating);

$block = new Block();
$block->setType('core.text');
Expand Down
8 changes: 4 additions & 4 deletions Tests/Block/Service/TextBlockServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
use Sonata\BlockBundle\Block\BlockContext;
use Sonata\BlockBundle\Block\Service\TextBlockService;
use Sonata\BlockBundle\Model\Block;
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
use Sonata\BlockBundle\Util\OptionsResolver;

class TextBlockServiceTest extends BaseTestBlockService
class TextBlockServiceTest extends AbstractBlockServiceTestCase
{
public function testService()
{
$templating = new FakeTemplating();
$service = new TextBlockService('sonata.page.block.text', $templating);
$service = new TextBlockService('sonata.page.block.text', $this->templating);

$block = new Block();
$block->setType('core.text');
Expand All @@ -42,6 +42,6 @@ public function testService()

$response = $service->execute($blockContext);

$this->assertEquals('my text', $templating->parameters['settings']['content']);
$this->assertEquals('my text', $this->templating->parameters['settings']['content']);
}
}
12 changes: 12 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
UPGRADE 3.x
===========

## Deprecated AbstractBlockServiceTest class

The `Tests\Block\AbstractBlockServiceTest` class is deprecated. Use `Test\AbstractBlockServiceTestCase` instead.

### Tests

All files under the ``Tests`` directory are now correctly handled as internal test classes.
You can't extend them anymore, because they are only loaded when running internal tests.
More information can be found in the [composer docs](https://getcomposer.org/doc/04-schema.md#autoload-dev).

0 comments on commit 815e66c

Please sign in to comment.