Skip to content

Commit

Permalink
Merge pull request #26 from CrossKnowledge/fix/CKLS-11615
Browse files Browse the repository at this point in the history
Undo Revert Symfony4 merge after correct tagging.
  • Loading branch information
rafaelpires815 authored May 4, 2022
2 parents 53e46bd + 293a29b commit 4c92ed1
Show file tree
Hide file tree
Showing 21 changed files with 1,609 additions and 833 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor/
logs/
.idea/
.phpunit.result.cache
5 changes: 2 additions & 3 deletions Controller/DataTableController.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php


namespace CrossKnowledge\DataTableBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class DataTableController extends Controller
class DataTableController extends AbstractController
{
/**
* @param Request $request
Expand Down
11 changes: 9 additions & 2 deletions DataTable/Renderer/TwigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
namespace CrossKnowledge\DataTableBundle\DataTable\Renderer;

use CrossKnowledge\DataTableBundle\DataTable\Table\AbstractTable;
use Twig\Environment;

class TwigRenderer implements RendererInterface
{
/** @var Environment */
protected $twig;

public function __construct(\Twig_Environment $env)
/**
* TwigRenderer constructor
*
* @param Environment $env
*/
public function __construct(Environment $env)
{
$this->twig = $env;
}
Expand All @@ -18,7 +25,7 @@ public function render(AbstractTable $table)
$tableOptions = $table->getOptions();
$data = [
'columns' => $table->getClientSideColumns(),
'datatable' => $table,
'datatable' => $table
];
if ($tableOptions['has_filter_form'])
{
Expand Down
66 changes: 33 additions & 33 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@


services:

crossKnowledge.datatable.twig_extension:
class: CrossKnowledge\DataTableBundle\Twig\DataTableExtension
arguments: ['@crossknowledge_datatable.twig_renderer']
tags:
- { name: twig.extension }

crossknowledge_datatable.registry:
class: CrossKnowledge\DataTableBundle\DataTable\DataTableRegistry

crossknowledge_datatable.default_formatter:
class: CrossKnowledge\DataTableBundle\DataTable\Formatter\DefaultFormatter

crossknowledge_datatable.classic_table:
abstract: true
arguments:
- '@form.factory'
- '@security.authorization_checker'
- '@router'
- '@crossknowledge_datatable.default_formatter'

crossknowledge_datatable.default_renderer:
alias: crossknowledge_datatable.twig_renderer

crossknowledge_datatable.json_renderer:
class: CrossKnowledge\DataTableBundle\DataTable\Renderer\JsonRenderer

crossknowledge_datatable.twig_renderer:
class: CrossKnowledge\DataTableBundle\DataTable\Renderer\TwigRenderer
arguments: ['@twig']

crossKnowledge.datatable.twig_extension:
class: CrossKnowledge\DataTableBundle\Twig\DataTableExtension
arguments:
- '@crossknowledge_datatable.twig_renderer'
tags:
- { name: twig.extension }

crossknowledge_datatable.registry:
public: true
class: CrossKnowledge\DataTableBundle\DataTable\DataTableRegistry

crossknowledge_datatable.default_formatter:
class: CrossKnowledge\DataTableBundle\DataTable\Formatter\DefaultFormatter

crossknowledge_datatable.classic_table:
abstract: true
arguments:
- '@form.factory'
- '@security.authorization_checker'
- '@router'
- '@crossknowledge_datatable.default_formatter'

crossknowledge_datatable.default_renderer:
alias: crossknowledge_datatable.twig_renderer

crossknowledge_datatable.json_renderer:
public: true
class: CrossKnowledge\DataTableBundle\DataTable\Renderer\JsonRenderer

crossknowledge_datatable.twig_renderer:
class: CrossKnowledge\DataTableBundle\DataTable\Renderer\TwigRenderer
arguments:
- '@twig'
13 changes: 7 additions & 6 deletions Tests/Controller/DataTableControllerTest.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
<?php

namespace CrossKnowledge\DataTableDundle\Tests\Controller;

require_once __DIR__.'/../UsesContainerTrait.php';

use CrossKnowledge\DataTableBundle\Controller\DataTableController;
use CrossKnowledge\DataTableBundle\DataTable\DataTableRegistry;
use CrossKnowledge\DataTableBundle\DataTable\Renderer\JsonRenderer;
use CrossKnowledge\DataTableDundle\Tests\UsesContainerTrait;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\HttpFoundation\Request;
use PHPUnit\Framework\TestCase;

class DataTableControllerTest extends \PHPUnit_Framework_TestCase
class DataTableControllerTest extends TestCase
{
use UsesContainerTrait;

public function testJsonAction()
{
$tableMock = $this->getDataTableMock();
$registryMock = $this->getMockBuilder('CrossKnowledge\DataTableBundle\DataTable\DataTableRegistry')
$registryMock = $this->getMockBuilder(DataTableRegistry::class)
->disableOriginalConstructor()
->getMock();

$registryMock->expects($this->once())
->method('retrieveByTableId')
->will($this->returnValue($tableMock));

$rendererMock = $this->getMockBuilder('CrossKnowledge\DataTableBundle\DataTable\Renderer\JsonRenderer')
$rendererMock = $this->getMockBuilder(JsonRenderer::class)
->getMock();

$rendererMock->expects($this->once())
Expand Down
16 changes: 10 additions & 6 deletions Tests/CrossKnowledgeDataTableBundleTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?php


namespace CrossKnowledge\DataTableDundle\Tests;


use CrossKnowledge\DataTableBundle\CrossKnowledgeDataTableBundle;
use CrossKnowledge\DataTableBundle\DependencyInjection\Compiler\DatatablePass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use PHPUnit\Framework\TestCase;

class CrossKnowledgeDataTableBundleTest extends \PHPUnit_Framework_TestCase
class CrossKnowledgeDataTableBundleTest extends TestCase
{
/**
* Test if the DataTable compiler pass is successfully registered.
*/
public function testPassIsRegistered()
{
$container = new ContainerBuilder();
$bundle = new CrossKnowledgeDataTableBundle();
$bundle->build($container);
(new CrossKnowledgeDataTableBundle())->build($container);
$compilerPasses = $container->getCompilerPassConfig()->getBeforeOptimizationPasses();

$passes = array_values(
array_filter(
Expand All @@ -25,6 +27,8 @@ function ($pass) {
)
);

$this->assertInstanceOf(DatatablePass::class, $passes[0]);
$this->assertNotEmpty(array_filter($compilerPasses, function($compilerPass) {
return $compilerPass instanceof DatatablePass;
}));
}
}
13 changes: 9 additions & 4 deletions Tests/DataTable/Column/ColumnTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<?php
namespace CrossKnowledge\DataTableDundle\Tests\DataTable\Column;

namespace CrossKnowledge\DataTableDundle\Tests\DataTable\Column;

use CrossKnowledge\DataTableBundle\DataTable\Table\Element\Column\Column;
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;

class ColumnTest extends \PHPUnit_Framework_TestCase
class ColumnTest extends TestCase
{
/**
* Test if instantiate a column with an undefined option throws an exception.
*/
public function testUndefinedOptionThrowsException()
{
$this->setExpectedException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$column = new Column("test", ['not_defined' => true]);
$this->expectException(UndefinedOptionsException::class);
(new Column("test", ['not_defined' => true]));
}

public function testFormatCellUsesCallback()
Expand Down
5 changes: 2 additions & 3 deletions Tests/DataTable/Column/DateTimeColumnTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php


namespace CrossKnowledge\DataTableDundle\Tests\DataTable\Column;


use CrossKnowledge\DataTableBundle\DataTable\Table\Element\Column\DateTimeColumn;
use PHPUnit\Framework\TestCase;

class DateTimeColumnTest extends \PHPUnit_Framework_TestCase
class DateTimeColumnTest extends TestCase
{
/**
* @dataProvider dateFormatProvider
Expand Down
4 changes: 3 additions & 1 deletion Tests/DataTable/Column/LinkTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace CrossKnowledge\DataTableDundle\Tests\DataTable\Column;

use CrossKnowledge\DataTableBundle\DataTable\Table\Element\Column\Link;
use PHPUnit\Framework\TestCase;

class LinkTest extends \PHPUnit_Framework_TestCase
class LinkTest extends TestCase
{
/**
* @dataProvider linkTestProvider
Expand Down
4 changes: 3 additions & 1 deletion Tests/DataTable/ColumnBuilderTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

namespace CrossKnowledge\DataTableDundle\Tests\DataTable;

use CrossKnowledge\DataTableBundle\DataTable\ColumnBuilder;
use CrossKnowledge\DataTableBundle\DataTable\Table\Element\Column\Column;
use PHPUnit\Framework\TestCase;

class ColumnBuilderTest extends \PHPUnit_Framework_TestCase
class ColumnBuilderTest extends TestCase
{
public function testBuilder()
{
Expand Down
4 changes: 2 additions & 2 deletions Tests/DataTable/Formatter/DefaultFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace CrossKnowledge\DataTableDundle\Tests\DataTable\Formatter;


use CrossKnowledge\DataTableBundle\DataTable\Formatter\DefaultFormatter;
use CrossKnowledge\DataTableBundle\DataTable\Table\Element\Column\Column;
use PHPUnit\Framework\TestCase;

class DefaultFormatterTest extends \PHPUnit_Framework_TestCase
class DefaultFormatterTest extends TestCase
{
public function testFormatRowAutoEscapeOption()
{
Expand Down
4 changes: 3 additions & 1 deletion Tests/DataTable/Layout/LayoutsTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

namespace CrossKnowledge\DataTableDundle\Tests\DataTable\Layout;

use CrossKnowledge\DataTableBundle\DataTable\Table\Layout\Bootstrap;
use CrossKnowledge\DataTableBundle\DataTable\Table\Layout\CustomLayout;
use CrossKnowledge\DataTableBundle\DataTable\Table\Layout\DataTableLayoutInterface;
use PHPUnit\Framework\TestCase;

class ColumnBuilderTest extends \PHPUnit_Framework_TestCase
class ColumnBuilderTest extends TestCase
{
/**
* @dataProvider layoutsProvider
Expand Down
10 changes: 5 additions & 5 deletions Tests/DataTable/RegistryTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php


namespace CrossKnowledge\DataTableDundle\Tests\DataTable;


use BadMethodCallException;
use CrossKnowledge\DataTableBundle\DataTable\DataTableRegistry;
use CrossKnowledge\DataTableBundle\DataTable\Table\AbstractTable;
use PHPUnit\Framework\TestCase;

class RegistryTest extends \PHPUnit_Framework_TestCase
class RegistryTest extends TestCase
{
public function testRetrieveTableById()
{
Expand All @@ -18,7 +18,7 @@ public function testRetrieveTableById()
$registry = new DataTableRegistry(['test' => $table]);
$this->assertEquals($table, $registry->retrieveByTableId('test'));

$this->setExpectedException('\BadMethodCallException');
$this->expectException(BadMethodCallException::class);
$registry->retrieveByTableId('undef');
}
}
}
3 changes: 2 additions & 1 deletion Tests/DataTable/Renderer/JsonRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace CrossKnowledge\DataTableDundle\Tests\DataTable\Renderer;

use CrossKnowledge\DataTableBundle\DataTable\Renderer\JsonRenderer;
use PHPUnit\Framework\TestCase;

class JsonRendererTest extends \PHPUnit_Framework_TestCase
class JsonRendererTest extends TestCase
{

protected function getTableMock($unfilteredCount, $filteredCount)
Expand Down
Loading

0 comments on commit 4c92ed1

Please sign in to comment.