Skip to content

Commit

Permalink
Prepare 0.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 committed Dec 1, 2017
1 parent ce07086 commit f592055
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to `omines\datatables-bundle` will be documented in this fil
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
Nothing yet.

## 0.1.0 - 2017-12-01
### Added
- Basic functionality

[Unreleased]: https://github.com/omines/datatables-bundle
[Unreleased]: https://github.com/omines/datatables-bundle/compare/0.1.0...master
10 changes: 6 additions & 4 deletions src/DataTableFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Omines\DataTablesBundle;

use Omines\DataTablesBundle\DependencyInjection\Instantiator;
use Symfony\Component\HttpFoundation\Request;

class DataTableFactory
{
Expand Down Expand Up @@ -58,10 +59,10 @@ public function create(array $options = [])

return (new DataTable(array_merge($config['options'] ?? [], $options), $this->instantiator))
->setRenderer($this->renderer)
->setMethod($config['method'])
->setTranslationDomain($config['translation_domain'])
->setLanguageFromCDN($config['language_from_cdn'])
->setTemplate($config['template'], $config['template_parameters'])
->setMethod($config['method'] ?? Request::METHOD_POST)
->setTranslationDomain($config['translation_domain'] ?? 'messages')
->setLanguageFromCDN($config['language_from_cdn'] ?? true)
->setTemplate($config['template'] ?? DataTable::DEFAULT_TEMPLATE, $config['template_parameters'] ?? [])
;
}

Expand Down Expand Up @@ -102,6 +103,7 @@ private function resolveType(string $type): DataTableTypeInterface
} elseif (class_exists($type) && in_array(DataTableTypeInterface::class, class_implements($type), true)) {
return new $type();
}

throw new \InvalidArgumentException(sprintf('Could not resolve type "%s" to a service or class', $type));
}
}
23 changes: 5 additions & 18 deletions tests/Unit/DataTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,12 @@ public function testBundle()

public function testFactory()
{
$this->markTestSkipped('Incomplete after refactor');
$factory = new DataTableFactory(['language_from_cdn' => false], $this->createMock(TwigRenderer::class));

$factory = new DataTableFactory(['class_name' => 'foo'], ['dom' => 'bar'], $this->createMock(TwigRenderer::class));
$factory->setAdapterLocator(new ServiceLocator([]));

$table = $factory->create(['name' => 'bar'], ['pageLength' => 684]);
$this->assertSame('bar', $table->getSetting('name'));
$this->assertSame('foo', $table->getSetting('class_name'));
$this->assertSame('bar', $table->getOption('dom'));
$table = $factory->create(['pageLength' => 684, 'dom' => 'bar']);
$this->assertSame(684, $table->getOption('pageLength'));
$this->assertArrayHasKey('name', $table->getSettings());

$table = $factory->create(['class_name' => 'bar'], ['dom' => 'foo']);
$this->assertSame('bar', $table->getSetting('class_name'));
$this->assertSame('foo', $table->getOption('dom'));
$this->assertNull($table->getSetting('none'));
$this->assertSame('bar', $table->getOption('dom'));
$this->assertFalse($table->isLanguageFromCDN());
$this->assertNull($table->getOption('invalid'));

$table->setAdapter(new ArrayAdapter());
Expand All @@ -72,10 +62,7 @@ public function testFactory()

public function testFactoryRemembersInstances()
{
$this->markTestSkipped('Incomplete after refactor');

$factory = new DataTableFactory([], [], $this->createMock(TwigRenderer::class));
$factory->setAdapterLocator(new ServiceLocator([]));
$factory = new DataTableFactory([], $this->createMock(TwigRenderer::class));

$reflection = new \ReflectionClass(DataTableFactory::class);
$property = $reflection->getProperty('resolvedTypes');
Expand Down

0 comments on commit f592055

Please sign in to comment.