Skip to content

Commit

Permalink
A bunch of small improvements and refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinai committed Nov 17, 2020
1 parent 954d704 commit cec1f17
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Api/HyvaGridArrayProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface HyvaGridArrayProviderInterface
/**
* @return array[]
*/
public function getArray(): array;
public function getHyvaGridData(): array;
}
2 changes: 1 addition & 1 deletion Model/Config/GridConfigReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Magento\Framework\Config\ValidationStateInterface;
use function array_reduce as reduce;

class GridConfigReader
class GridConfigReader implements HyvaGridConfigReaderInterface
{
private GridDefinitionConfigFiles $definitionConfigFiles;

Expand Down
8 changes: 8 additions & 0 deletions Model/Config/HyvaGridConfigReaderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Hyva\Admin\Model\Config;

interface HyvaGridConfigReaderInterface
{
public function getGridConfiguration(string $gridName): array;
}
2 changes: 1 addition & 1 deletion Model/GridSourceType/ArrayProviderGridSourceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function fetchData(): RawGridSourceContainer
{
if (!isset($this->memoizedGridData)) {
$provider = $this->arrayProviderFactory->create($this->arrayProviderClass);
$this->memoizedGridData = RawGridSourceContainer::forData($provider->getArray());
$this->memoizedGridData = RawGridSourceContainer::forData($provider->getHyvaGridData());
}

return $this->memoizedGridData;
Expand Down
20 changes: 20 additions & 0 deletions Test/Functional/Model/Config/GridConfigReaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace Hyva\Admin\Test\Functional\Model\Config;

use Hyva\Admin\Model\Config\GridConfigReader;
use Hyva\Admin\Model\Config\HyvaGridConfigReaderInterface;
use Magento\TestFramework\ObjectManager;
use PHPUnit\Framework\TestCase;

/**
* @magentoAppArea adminhtml
*/
class GridConfigReaderTest extends TestCase
{
public function testIsKnownToObjectManager(): void
{
$reader = ObjectManager::getInstance()->create(HyvaGridConfigReaderInterface::class);
$this->assertInstanceOf(GridConfigReader::class, $reader);
}
}
2 changes: 1 addition & 1 deletion Test/Functional/TestingGridDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static function withArray(array $testGridData): string
return self::class;
}

public function getArray(): array
public function getHyvaGridData(): array
{
$testGridData = self::$testGridData;
return $testGridData;
Expand Down
20 changes: 19 additions & 1 deletion Test/Unit/Model/GridSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Hyva\Admin\ViewModel\HyvaGrid\ColumnDefinitionInterfaceFactory;
use PHPUnit\Framework\TestCase;

use function array_map as map;

class GridSourceTest extends TestCase
{
private function assertContainsColumn(ColumnDefinitionInterface $actual, array $columns, string $msg = ''): void
Expand Down Expand Up @@ -94,10 +96,26 @@ public function testMergesInIncludedColumnSpecifications(): void
new ColumnDefinition('bar', null, 'int'), // configured type
];

$sut = new GridSource($gridSourceType, $stubColumnDefinitionFactory);
$sut = new GridSource($gridSourceType, $stubColumnDefinitionFactory);
$extractedColumns = $sut->extractColumnDefinitions($configuredIncludeColumns);
$this->assertContainsColumn(new ColumnDefinition('foo', 'Foo Label', 'string'), $extractedColumns);
$this->assertContainsColumn(new ColumnDefinition('bar', 'Bar', 'int'), $extractedColumns);
}

public function testExtractsAllColumnKeysFromSourceIfNoneAreConfigured(): void
{
$sourceColumnKeys = ['foo', 'bar', 'baz'];
$stubColumnDefinitionFactory = $this->createStubColumnDefinitionFactory();
$gridSourceType = $this->createStubGridSourceType($sourceColumnKeys);

$configuredIncludeColumns = [];

$sut = new GridSource($gridSourceType, $stubColumnDefinitionFactory);
$extractedColumns = $sut->extractColumnDefinitions($configuredIncludeColumns);
$extractedKeys = map(function (ColumnDefinitionInterface $columnDefinition): string {
return $columnDefinition->getKey();
}, $extractedColumns);
$this->assertSame($sourceColumnKeys, $extractedKeys);
}

}
2 changes: 2 additions & 0 deletions etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<preference for="Hyva\Admin\ViewModel\HyvaGrid\CellInterface" type="Hyva\Admin\ViewModel\HyvaGrid\Cell"/>
<preference for="Hyva\Admin\ViewModel\HyvaGrid\NavigationInterface"
type="Hyva\Admin\ViewModel\HyvaGrid\TemporaryDummyNavigation"/>
<preference for="Hyva\Admin\Model\Config\HyvaGridConfigReaderInterface"
type="Hyva\Admin\Model\Config\GridConfigReader"/>
<type name="Hyva\Admin\Block\Adminhtml\HyvaGrid">
<arguments>
<argument name="gridTemplate" xsi:type="string">Hyva_Admin::grid.phtml</argument>
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@

This module aims to make creating grids and forms in the Magento 2 adminhtml area for developers joyful and fast.
It does not use any UI components.


## next steps (a.k. todo)

* implement repository source type
* add caching to grid config reader
* implement navigation related types
* create schema for grid xml
* implement collection source type

0 comments on commit cec1f17

Please sign in to comment.