Convert some old array() calls to new [] syntax

This commit is contained in:
Christian Bläul
2024-08-29 17:06:16 +02:00
parent 259e9a6c31
commit 24e229ddfa
3 changed files with 8 additions and 11 deletions

View File

@@ -326,7 +326,7 @@ class ParseTest extends TestCase {
* @return mixed Method return. * @return mixed Method return.
*/ */
private function invokeMethod($object, $methodName, $parameters = []) { private function invokeMethod($object, $methodName, $parameters = []) {
$reflection = new ReflectionClass(get_class($object)); $reflection = new ReflectionClass($object::class);
$method = $reflection->getMethod($methodName); $method = $reflection->getMethod($methodName);
$method->setAccessible(true); $method->setAccessible(true);

View File

@@ -51,7 +51,7 @@ class SaveTest extends TestCase {
public function testSaveWithNewHeader() { public function testSaveWithNewHeader() {
$this->csv->linefeed = "\n"; $this->csv->linefeed = "\n";
$this->csv->titles = array("NewTitle"); $this->csv->titles = ["NewTitle"];
$expected = "NewTitle\n0444\n5555\n"; $expected = "NewTitle\n0444\n5555\n";
$this->saveAndCompare($expected); $this->saveAndCompare($expected);
} }

View File

@@ -20,7 +20,7 @@ class UnparseTest extends Testcase {
} }
public function testUnparseWithParameters() { public function testUnparseWithParameters() {
$fields = array('a' => 'AA', 'b' => 'BB'); $fields = ['a' => 'AA', 'b' => 'BB'];
$data = [['a' => 'value1', 'b' => 'value2']]; $data = [['a' => 'value1', 'b' => 'value2']];
$csv_object = new Csv(); $csv_object = new Csv();
$csv_string = $csv_object->unparse($data, $fields); $csv_string = $csv_object->unparse($data, $fields);
@@ -52,24 +52,21 @@ class UnparseTest extends Testcase {
public function testUnparseRenameFields() { public function testUnparseRenameFields() {
$expected = "C1,C2\rvalue1,value2\rvalue3,value4\r"; $expected = "C1,C2\rvalue1,value2\rvalue3,value4\r";
$this->unparseAndCompare($expected, array("C1", "C2")); $this->unparseAndCompare($expected, ["C1", "C2"]);
} }
public function testReorderFields() { public function testReorderFields() {
$expected = "column2,column1\rvalue2,value1\rvalue4,value3\r"; $expected = "column2,column1\rvalue2,value1\rvalue4,value3\r";
$this->unparseAndCompare($expected, array("column2", "column1")); $this->unparseAndCompare($expected, ["column2", "column1"]);
} }
public function testSubsetFields() { public function testSubsetFields() {
$expected = "column1\rvalue1\rvalue3\r"; $expected = "column1\rvalue1\rvalue3\r";
$this->unparseAndCompare($expected, array("column1")); $this->unparseAndCompare($expected, ["column1"]);
} }
public function testReorderAndRenameFields() { public function testReorderAndRenameFields() {
$fields = array( $fields = ['column2' => 'C2', 'column1' => 'C1'];
'column2' => 'C2',
'column1' => 'C1',
);
$expected = "C2,C1\rvalue2,value1\rvalue4,value3\r"; $expected = "C2,C1\rvalue2,value1\rvalue4,value3\r";
$this->unparseAndCompare($expected, $fields); $this->unparseAndCompare($expected, $fields);
} }
@@ -99,7 +96,7 @@ class UnparseTest extends Testcase {
$this->unparseAndCompare($expected); $this->unparseAndCompare($expected);
} }
private function unparseAndCompare($expected, $fields = array()) { private function unparseAndCompare($expected, $fields = []) {
$str = $this->csv->unparse($this->csv->data, $fields); $str = $this->csv->unparse($this->csv->data, $fields);
$this->assertEquals($expected, $str); $this->assertEquals($expected, $str);
} }