Skip to content

Commit

Permalink
ExcelOpenSpoutExporter: test case for exporter collection
Browse files Browse the repository at this point in the history
  • Loading branch information
mhvis committed Mar 5, 2024
1 parent efe123c commit 4754054
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/Exporter/Excel/ExcelOpenSpoutExporter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?php

/*
* Symfony DataTables Bundle
* (c) Omines Internetbureau B.V. - https://omines.nl/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Omines\DataTablesBundle\Exporter\Excel;
Expand All @@ -9,7 +18,7 @@
use OpenSpout\Writer\XLSX\Writer;

/**
* Excel exporter using OpenShout.
* Excel exporter using OpenSpout.
*/
class ExcelOpenSpoutExporter implements DataTableExporterInterface
{
Expand Down
15 changes: 11 additions & 4 deletions tests/Functional/Exporter/Excel/ExcelOpenSpoutExporterTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?php

/*
* Symfony DataTables Bundle
* (c) Omines Internetbureau B.V. - https://omines.nl/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Functional\Exporter\Excel;
Expand Down Expand Up @@ -56,6 +65,7 @@ public function testEmptyDataTable(): void

static::assertTrue($response->isSuccessful());

// Using PhpSpreadsheet for tests
$sheet = IOFactory::load($response->getFile()->getPathname())->getActiveSheet();

static::assertSame('dt.columns.firstName', $sheet->getCell('A1')->getFormattedValue());
Expand All @@ -65,10 +75,6 @@ public function testEmptyDataTable(): void
static::assertEmpty($sheet->getCell('B2')->getFormattedValue());
}

/**
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
*/
public function testWithSearch(): void
{
$this->client->request('POST', '/exporter', [
Expand All @@ -80,6 +86,7 @@ public function testWithSearch(): void
/** @var BinaryFileResponse $response */
$response = $this->client->getResponse();

// Using PhpSpreadsheet for tests
$sheet = IOFactory::load($response->getFile()->getPathname())->getActiveSheet();

static::assertSame('dt.columns.firstName', $sheet->getCell('A1')->getFormattedValue());
Expand Down
40 changes: 40 additions & 0 deletions tests/Unit/Exporter/ExcelOpenSpoutExporterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* Symfony DataTables Bundle
* (c) Omines Internetbureau B.V. - https://omines.nl/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Unit\Exporter;

use Omines\DataTablesBundle\Exporter\DataTableExporterCollection;
use Omines\DataTablesBundle\Exporter\Excel\ExcelOpenSpoutExporter;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class ExcelOpenSpoutExporterTest extends KernelTestCase
{
/** @var DataTableExporterCollection */
private $exporterCollection;

protected function setUp(): void
{
$this->bootKernel();

$this->exporterCollection = $this->getContainer()->get(DataTableExporterCollection::class);
}

public function testTag(): void
{
$this->assertInstanceOf(ExcelOpenSpoutExporter::class, $this->exporterCollection->getByName('excel-openspout'));
}

public function testName(): void
{
$this->assertSame('excel-openspout', $this->exporterCollection->getByName('excel-openspout')->getName());
}
}

0 comments on commit 4754054

Please sign in to comment.