Commit cffc6aa7 authored by claudiu.cristea's avatar claudiu.cristea Committed by claudiu.cristea

Issue #3175258 by claudiu.cristea: Fix tests for branch 2.0.x

parent c826ca6f
<?php
declare(strict_types = 1);
namespace Drupal\Tests\migrate_spreadsheet\Unit;
use Drupal\migrate_spreadsheet\SpreadsheetIterator;
use Drupal\Tests\UnitTestCase;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\TestCase;
/**
* Tests the spreadsheet iterator.
......@@ -13,7 +16,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
*
* @group migrate_spreadsheet
*/
class SpreadsheetIteratorTest extends UnitTestCase {
class SpreadsheetIteratorTest extends TestCase {
/**
* A worksheet.
......@@ -32,7 +35,7 @@ class SpreadsheetIteratorTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp(): void {
parent::setUp();
$this->iterator = (new SpreadsheetIterator())
......@@ -48,7 +51,7 @@ class SpreadsheetIteratorTest extends UnitTestCase {
* @covers ::getRowsCount
* @covers ::getColumnsCount
*/
public function testRowsAndColumnsCount() {
public function testRowsAndColumnsCount(): void {
$this->assertEquals(5, $this->iterator->getRowsCount());
$this->assertEquals(7, $this->iterator->getColumnsCount());
}
......@@ -62,11 +65,11 @@ class SpreadsheetIteratorTest extends UnitTestCase {
* @param bool $expect_exception
* If a exception is expected.
*/
public function testGetOrigin($origin, $expect_exception) {
public function testGetOrigin(string $origin, bool $expect_exception): void {
$config = ['origin' => $origin] + $this->iterator->getConfiguration();
$this->iterator->setConfiguration($config);
if ($expect_exception) {
$this->setExpectedException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
}
$this->assertEquals($origin, $this->iterator->getOrigin());
}
......@@ -77,27 +80,21 @@ class SpreadsheetIteratorTest extends UnitTestCase {
* @return array[]
* A list of test parameters to be passed to ::testGetOrigin().
*/
public function providerTestGetException() {
public function providerTestGetException(): array {
return [
// The minimum valid origin.
['A1', FALSE],
// A valid origin.
['B3', FALSE],
// Column out of bounds.
['H3', TRUE],
// Row out of bounds.
['E6', TRUE],
// Both, row and column, out of bounds.
['H6', TRUE],
// The maximum valid value.
['G5', FALSE],
'The minimum valid origin' => ['A1', FALSE],
'A valid origin' => ['B3', FALSE],
'Column out of bounds' => ['H3', TRUE],
'Row out of bounds' => ['E6', TRUE],
'Both, row and column, out of bounds' => ['H6', TRUE],
'The maximum valid value' => ['G5', FALSE],
];
}
/**
* @covers ::getHeaders
*/
public function testGetHeaders() {
public function testGetHeaders(): void {
$cols = [
'column b' => 'B',
'column c' => 'C',
......@@ -124,14 +121,14 @@ class SpreadsheetIteratorTest extends UnitTestCase {
$this->getWorksheet()->setCellValue('C2', 'column b');
$config['header_row'] = 2;
$this->iterator->setConfiguration($config);
$this->setExpectedException('RuntimeException');
$this->expectException('RuntimeException');
$this->iterator->getHeaders();
}
/**
* @covers ::current
*/
public function testIteration() {
public function testIteration(): void {
$config = $this->iterator->getConfiguration();
$config['row_index_column'] = 'row';
$this->iterator->setConfiguration($config);
......@@ -232,7 +229,7 @@ class SpreadsheetIteratorTest extends UnitTestCase {
* @return \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
* A PhpSpreadsheet worksheet object.
*/
protected function getWorksheet() {
protected function getWorksheet(): Worksheet {
if (!isset($this->worksheet)) {
// Test case:
// - origin: B3;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment