Skip to content

Commit

Permalink
Fixed DataGridItem::hasIdentifier()
Browse files Browse the repository at this point in the history
  • Loading branch information
pfilsx committed Oct 21, 2019
1 parent 53508c4 commit 0d605b9
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 48 deletions.
5 changes: 2 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="./tests/bootstrap.php"
>
Expand All @@ -12,12 +11,12 @@
<env name="APP_ENV" value="test"/>
<env name="SHELL_VERBOSITY" value="-1"/>
<server name="KERNEL_DIR" value="./tests/app/"/>
<server name="KERNEL_CLASS" value="Pfilsx\tests\AppKernel"/>
<server name="KERNEL_CLASS" value="Pfilsx\tests\app\AppKernel"/>
</php>

<testsuites>
<testsuite name="DataGridBundle Test Suite">
<directory suffix="Test.php">./tests</directory>
<directory>./tests</directory>
</testsuite>
</testsuites>

Expand Down
10 changes: 9 additions & 1 deletion src/Grid/DataGridBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,16 @@ public function getInstance(): string {

/**
* @param string $name
* @return DataGridBuilderInterface
*/
public function setInstance(string $name): void {
public function setInstance(string $name): DataGridBuilderInterface {
$this->instance = $name;
return $this;
}

public function setTranslationDomain(string $domain): DataGridBuilderInterface
{
$this->configuration->setTranslationDomain($domain);
return $this;
}
}
30 changes: 23 additions & 7 deletions src/Grid/DataGridBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,60 @@ public function enablePagination(bool $enabled = true, int $limit = 10): self;

public function setCountFieldName(string $name): self;

public function setInstance(string $name): self;

public function setTranslationDomain(string $domain): self;

/**
* @internal
* @return AbstractColumn[]
* @internal
*/
public function getColumns(): array;


public function getProvider(): DataProviderInterface;

/**
* @internal
* @param DataProviderInterface $provider
* @internal
*/
public function setProvider(DataProviderInterface $provider): void;

/**
* @return bool
* @internal
*/
public function hasFilters(): bool;

/**
* @internal
* @param array $filters
* @internal
*/
public function setFiltersValues(array $filters): void;

/**
* @internal
* @return Pager
* @internal
*/
public function getPager(): Pager;

/**
* @internal
* @return bool
* @internal
*/
public function hasPagination(): bool;

/**
* @return ConfigurationInterface
* @internal
*/
public function getConfiguration(): ConfigurationInterface;

public function setInstance(string $name): void;

/**
* @return string
* @internal
*/
public function getInstance(): string;


}
2 changes: 1 addition & 1 deletion src/Grid/Items/DataGridItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final function setData($data)

public final function hasIdentifier(): bool
{
return $this->identifier !== null;
return $this->identifier !== null && $this->has($this->identifier);
}

public final function getIdentifier()
Expand Down
32 changes: 32 additions & 0 deletions tests/DataGridServiceContainerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php


namespace Pfilsx\tests;



use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

class DataGridServiceContainerTest extends KernelTestCase
{
public function testContainer(){
$this->assertInstanceOf(ManagerRegistry::class, $this->serviceContainer->getDoctrine());
$this->assertEquals($this->serviceContainer->getDoctrine(), $this->serviceContainer->get('doctrine'));

$this->assertInstanceOf(RouterInterface::class, $this->serviceContainer->getRouter());
$this->assertEquals($this->serviceContainer->getRouter(), $this->serviceContainer->get('router'));

$this->assertInstanceOf(Environment::class, $this->serviceContainer->getTwig());
$this->assertEquals($this->serviceContainer->getTwig(), $this->serviceContainer->get('twig'));

$this->assertInstanceOf(RequestStack::class, $this->serviceContainer->getRequest());
$this->assertEquals($this->serviceContainer->getRequest(), $this->serviceContainer->get('request'));

$this->assertInstanceOf(TranslatorInterface::class, $this->serviceContainer->getTranslator());
$this->assertEquals($this->serviceContainer->getTranslator(), $this->serviceContainer->get('translator'));
}
}
44 changes: 44 additions & 0 deletions tests/KernelTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php


namespace Pfilsx\tests;


use Pfilsx\DataGrid\DataGridServiceContainer;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;

class KernelTestCase extends \Symfony\Bundle\FrameworkBundle\Test\KernelTestCase
{
/**
* @var DataGridServiceContainer
*/
protected $serviceContainer;

/**
* @var Application
*/
protected $application;

protected function setUp(): void
{
$kernel = self::bootKernel();
$this->application = new Application($kernel);
$this->application->setAutoExit(false);
$this->application->run(new ArrayInput(array(
'doctrine:schema:drop',
'--force' => true
)));
$this->application->run(new ArrayInput(array(
'doctrine:schema:create'
)));
/** @noinspection PhpParamsInspection */
$this->serviceContainer = new DataGridServiceContainer(
$kernel->getContainer()->get('doctrine'),
$kernel->getContainer()->get('router'),
$kernel->getContainer()->get('twig'),
$kernel->getContainer()->get('request_stack'),
$kernel->getContainer()->get('translator')
);
}
}
30 changes: 1 addition & 29 deletions tests/OrmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

use DateTime;
use Doctrine\ORM\EntityManager;
use Pfilsx\DataGrid\DataGridServiceContainer;
use Pfilsx\tests\app\Entity\Node;
use Pfilsx\tests\app\Entity\NodeAssoc;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Twig\Template;

class OrmTestCase extends KernelTestCase
Expand All @@ -20,11 +16,6 @@ class OrmTestCase extends KernelTestCase
* @var EntityManager
*/
protected $em;

/**
* @var DataGridServiceContainer
*/
protected $serviceContainer;
/**
* @var Template
*/
Expand All @@ -33,26 +24,7 @@ class OrmTestCase extends KernelTestCase

protected function setUp(): void
{
$kernel = self::bootKernel();
$application = new Application($kernel);
$application->setAutoExit(false);
$application->run(new ArrayInput(array(
'doctrine:schema:drop',
'--force' => true
)));
$application->run(new ArrayInput(array(
'doctrine:schema:create'
)));


/** @noinspection PhpParamsInspection */
$this->serviceContainer = new DataGridServiceContainer(
$kernel->getContainer()->get('doctrine'),
$kernel->getContainer()->get('router'),
$kernel->getContainer()->get('twig'),
$kernel->getContainer()->get('request_stack'),
$kernel->getContainer()->get('translator')
);
parent::setUp();

$this->createEntityManager();

Expand Down
8 changes: 4 additions & 4 deletions tests/AppKernel.php → tests/app/AppKernel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Pfilsx\tests;
namespace Pfilsx\tests\app;


use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
Expand All @@ -25,20 +25,20 @@ public function registerBundles()
$bundles = array(
new FrameworkBundle(),
new DoctrineBundle(),
new DataGridBundle(),
new TwigBundle(),
new DataGridBundle(),
);
return $bundles;
}


public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__ . '/app/config/config_' . $this->getEnvironment() . '.yml');
$loader->load(__DIR__ . '/config/config_' . $this->getEnvironment() . '.yml');
}

public function getCacheDir()
{
return __DIR__ . '/app/cache/' . $this->environment;
return __DIR__ . '/cache/' . $this->environment;
}
}
1 change: 1 addition & 0 deletions tests/app/Grid/NodeGridType2.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function buildGrid(DataGridBuilderInterface $builder): void
->addActionColumn([
'prefix' => 'test_prefix_'
])
->setTranslationDomain('test')
->enablePagination(false);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ framework:
templating:
engines: ['twig']
router:
resource: "%kernel.root_dir%/app/config/routing.yml"
resource: "%kernel.root_dir%/config/routing.yml"
twig:
paths:
"%kernel.root_dir%/app/Resources/views/": __main__
"%kernel.root_dir%/Resources/views/": __main__
doctrine:
dbal:
driver: 'pdo_sqlite'
Expand All @@ -25,5 +25,5 @@ doctrine:
mappings:
Pfilsx\tests\app\Entity\Node:
type: xml
dir: "%kernel.root_dir%/app/Resources/config/doctrine"
dir: "%kernel.root_dir%/Resources/config/doctrine"
prefix: Pfilsx\tests\app\Entity
41 changes: 41 additions & 0 deletions tests/providers/RepositoryDataProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php


namespace Pfilsx\tests\providers;


use Pfilsx\DataGrid\Grid\Pager;
use Pfilsx\DataGrid\Grid\Providers\RepositoryDataProvider;
use Pfilsx\tests\app\Entity\Node;
use Pfilsx\tests\OrmTestCase;

class RepositoryDataProviderTest extends OrmTestCase
{
/**
* @var RepositoryDataProvider
*/
private $provider;

public function setUp(): void
{
parent::setUp();
$this->provider = new RepositoryDataProvider($this->getEntityManager()->getRepository(Node::class), $this->serviceContainer->getDoctrine());
$this->provider->setPager(new Pager());
}

public function testGetItems(): void
{
$items = $this->provider->getItems();
$this->assertIsArray($items);
$this->assertNotEmpty($items);
$this->assertCount(11, $items);
}

public function testEmpty(): void
{
$this->provider->addEqualFilter('id', 12);
$items = $this->provider->getItems();
$this->assertIsArray($items);
$this->assertEmpty($items);
}
}

0 comments on commit 0d605b9

Please sign in to comment.