Skip to content

Commit

Permalink
style(*): start using short array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinsh committed Dec 23, 2018
1 parent ed1d7e4 commit 7a6b3b4
Show file tree
Hide file tree
Showing 37 changed files with 3,836 additions and 3,287 deletions.
685 changes: 416 additions & 269 deletions system/tests/kohana/ArrTest.php

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions system/tests/kohana/Config/File/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class Kohana_Config_File_ReaderTest extends Kohana_Unittest_TestCase
{
/**
* If we don't pass a directory to the reader then it should assume
* If we don't pass a directory to the reader then it should assume
* that we want to search the dir 'config' by default
*
* @test
Expand All @@ -32,7 +32,7 @@ public function test_default_search_dir_is_config()
}

/**
* If we pass a directory to the constructor of the file reader it
* If we pass a directory to the constructor of the file reader it
* should change the search directory
*
* @test
Expand All @@ -46,7 +46,7 @@ public function test_constructor_sets_search_dir_from_param()
}

/**
* If the config dir does not exist then the function should just
* If the config dir does not exist then the function should just
* return an empty array
*
* @test
Expand All @@ -56,11 +56,11 @@ public function test_load_returns_empty_array_if_conf_dir_dnx()
{
$config = new Kohana_Config_File_Reader('gafloogle');

$this->assertSame(array(), $config->load('values'));
$this->assertSame([], $config->load('values'));
}

/**
* If the requested config group does not exist then the reader
* If the requested config group does not exist then the reader
* should return an empty array
*
* @test
Expand All @@ -70,11 +70,11 @@ public function test_load_returns_empty_array_if_conf_dnx()
{
$config = new Kohana_Config_File_Reader;

$this->assertSame(array(), $config->load('gafloogle'));
$this->assertSame([], $config->load('gafloogle'));
}

/**
* Test that the load() function is actually loading the
* Test that the load() function is actually loading the
* configuration from the files.
*
* @test
Expand All @@ -86,11 +86,11 @@ public function test_loads_config_from_files()

$values = $config->load('inflector');

// Due to the way the cascading filesystem works there could be
// any number of modifications to the system config in the
// actual output. Therefore to increase compatability we just
// Due to the way the cascading filesystem works there could be
// any number of modifications to the system config in the
// actual output. Therefore to increase compatability we just
// check that we've got an array and that it's not empty
$this->assertNotSame(array(), $values);
$this->assertNotSame([], $values);
$this->assertInternalType('array', $values);
}

Expand Down
29 changes: 15 additions & 14 deletions system/tests/kohana/Config/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function get_mock_config()
* @param Kohana_Config $instance Instance of Kohana_Config
* @return Kohana_Config_Group
*/
public function get_mock_group($group, $config = array(), $instance = NULL)
public function get_mock_group($group, $config = [], $instance = NULL)
{
if ($instance === NULL) {
$instance = $this->get_mock_config();
Expand All @@ -54,7 +54,7 @@ public function get_mock_group($group, $config = array(), $instance = NULL)
public function test_loads_group_name_and_values_in_constructor()
{
$group_name = 'information';
$group_values = array('var' => 'value');
$group_values = ['var' => 'value'];

$group = $this->get_mock_group($group_name, $group_values);

Expand All @@ -77,7 +77,7 @@ public function test_allows_empty_group_values()
{
$group = $this->get_mock_group('informatica');

$this->assertSame(array(), $group->getArrayCopy());
$this->assertSame([], $group->getArrayCopy());
}

/**
Expand All @@ -88,7 +88,7 @@ public function test_allows_empty_group_values()
*/
public function test_get_fetches_config_value()
{
$group = $this->get_mock_group('kohana', array('status' => 'awesome'));
$group = $this->get_mock_group('kohana', ['status' => 'awesome']);

$this->assertSame('awesome', $group->get('status'));
}
Expand Down Expand Up @@ -116,7 +116,7 @@ public function test_get_returns_default_value_if_config_option_dnx()
*/
public function test_set_modifies_existing_config()
{
$group = $this->get_mock_group('kohana', array('status' => 'pre-awesome'));
$group = $this->get_mock_group('kohana', ['status' => 'pre-awesome']);

$group->set('status', 'awesome');

Expand All @@ -126,7 +126,7 @@ public function test_set_modifies_existing_config()
/**
* If we modify the config via set() [$var] or ->$var then the change should be passed to
* the parent config instance so that the config writers can be notified.
*
*
* The modification to the config should also stick
*
* @test
Expand All @@ -142,7 +142,7 @@ public function test_writes_changes_to_config()
->method('_write_config')
->with('kohana', 'status', $this->LogicalOr('totally', 'maybe', 'not'));

$group = $this->get_mock_group('kohana', array('status' => 'kool'), $mock);
$group = $this->get_mock_group('kohana', ['status' => 'kool'], $mock);

$group['status'] = 'totally';

Expand All @@ -159,21 +159,22 @@ public function test_writes_changes_to_config()
*/
public function test_as_array_returns_full_array()
{
$config = $this->get_mock_group('something', array('var' => 'value'));
$config = $this->get_mock_group('something', ['var' => 'value']);

$this->assertSame(array('var' => 'value'), $config->as_array());
$this->assertSame(['var' => 'value'], $config->as_array());

// Now change some vars **ahem**
$config->var = 'LOLCAT';
$config->lolcat = 'IN UR CODE';

$this->assertSame(
array('var' => 'LOLCAT', 'lolcat' => 'IN UR CODE'), $config->as_array()
);
$this->assertSame([
'var' => 'LOLCAT',
'lolcat' => 'IN UR CODE'
], $config->as_array());

// And if we remove an item it should be removed from the exported array
unset($config['lolcat']);
$this->assertSame(array('var' => 'LOLCAT'), $config->as_array());
$this->assertSame(['var' => 'LOLCAT'], $config->as_array());
}

/**
Expand All @@ -184,7 +185,7 @@ public function test_as_array_returns_full_array()
*/
public function test_to_string_serializes_array_output()
{
$vars = array('kohana' => 'cool', 'unit_tests' => 'boring');
$vars = ['kohana' => 'cool', 'unit_tests' => 'boring'];
$config = $this->get_mock_group('hehehe', $vars);

$this->assertSame(serialize($vars), (string) $config);
Expand Down
66 changes: 35 additions & 31 deletions system/tests/kohana/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function test_initially_there_are_no_sources()
{
$config = new Config;

$this->assertAttributeSame(array(), '_sources', $config);
$this->assertAttributeSame([], '_sources', $config);
}

/**
Expand Down Expand Up @@ -69,15 +69,15 @@ public function test_attach_adds_reader_to_front_of_queue()

// Rather than do two assertContains we'll do an assertSame to assert
// the order of the readers
$this->assertAttributeSame(array($reader2, $reader1), '_sources', $config);
$this->assertAttributeSame([$reader2, $reader1], '_sources', $config);

// Now we test using the second parameter
$config = new Config;

$config->attach($reader1);
$config->attach($reader2, TRUE);

$this->assertAttributeSame(array($reader2, $reader1), '_sources', $config);
$this->assertAttributeSame([$reader2, $reader1], '_sources', $config);
}

/**
Expand All @@ -96,7 +96,7 @@ public function test_attach_can_add_reader_to_end_of_queue()
$config->attach($reader1);
$config->attach($reader2, FALSE);

$this->assertAttributeSame(array($reader1, $reader2), '_sources', $config);
$this->assertAttributeSame([$reader1, $reader2], '_sources', $config);
}

/**
Expand Down Expand Up @@ -163,7 +163,7 @@ public function test_load_can_get_var_from_dot_path()
->expects($this->once())
->method('load')
->with('beer')
->will($this->returnValue(array('stout' => 'Guinness')));
->will($this->returnValue(['stout' => 'Guinness']));

$config->attach($reader);

Expand All @@ -172,7 +172,7 @@ public function test_load_can_get_var_from_dot_path()

/**
* If we've already loaded a config group then the correct variable
* should be returned if we use the dot path notation to to request
* should be returned if we use the dot path notation to to request
* a var
*
* @test
Expand All @@ -189,7 +189,7 @@ public function test_load_can_get_var_from_dot_path_for_loaded_group()
$reader->expects($this->once())
->method('load')
->with('beer')
->will($this->returnValue(array('stout' => 'Guinness')));
->will($this->returnValue(['stout' => 'Guinness']));

$config->attach($reader);

Expand Down Expand Up @@ -222,13 +222,13 @@ public function test_load_throws_exception_if_there_are_no_sources()
*/
public function provider_load_throws_exception_if_no_group_is_given()
{
return array(
array(NULL),
array(''),
array(array()),
array(array('foo' => 'bar')),
array(new StdClass),
);
return [
[NULL],
[''],
[[]],
[['foo' => 'bar']],
[new StdClass],
];
}

/**
Expand All @@ -253,7 +253,7 @@ public function test_load_throws_exception_if_invalid_group($value)
}

/**
* Make sure that _write_config() passes the changed configuration to all
* Make sure that _write_config() passes the changed configuration to all
* writers in the queue
*
* @test
Expand Down Expand Up @@ -307,31 +307,32 @@ public function test_config_is_loaded_from_top_to_bottom_of_stack()
$reader1->expects($this->once())
->method('load')
->with($group_name)
->will($this->returnValue(array('foo' => 'bar', 'kohana' => 'awesome', 'life' => array('normal', 'fated'))));
->will($this->returnValue([
'foo' => 'bar',
'kohana' => 'awesome',
'life' => ['normal', 'fated']
]));

$reader2->expects($this->once())
->method('load')
->with($group_name)
->will($this->returnValue(array('kohana' => 'sweet', 'music' => 'tasteful', 'life' => array('extraordinary', 'destined'))));
->will($this->returnValue([
'kohana' => 'sweet',
'music' => 'tasteful',
'life' => ['extraordinary', 'destined']
]));

$config = new Kohana_Config;

// Attach $reader1 at the "top" and reader2 at the "bottom"
$config->attach($reader1)->attach($reader2, FALSE);

$this->assertSame(
array(
$this->assertSame([
'kohana' => 'awesome',
'music' => 'tasteful',
'life' => array(
'extraordinary',
'destined',
'normal',
'fated',
),
'life' => ['extraordinary', 'destined', 'normal', 'fated'],
'foo' => 'bar',
), $config->load($group_name)->as_array()
);
], $config->load($group_name)->as_array());
}

/**
Expand All @@ -350,7 +351,7 @@ public function test_load_reuses_config_groups()
$reader->expects($this->once())
->method('load')
->with('something')
->will($this->returnValue(array()));
->will($this->returnValue([]));

$config = new Kohana_Config;

Expand Down Expand Up @@ -382,12 +383,15 @@ public function test_copy_copies_merged_config_to_all_writers()
$reader1->expects($this->once())
->method('load')
->with('something')
->will($this->returnValue(array('pie' => 'good', 'kohana' => 'awesome')));
->will($this->returnValue([
'pie' => 'good',
'kohana' => 'awesome'
]));

$reader2->expects($this->once())
->method('load')
->with('something')
->will($this->returnValue(array('kohana' => 'good')));
->will($this->returnValue(['kohana' => 'good']));

$writer1 = $this->getMockBuilder('Kohana_Config_Writer')
->setMethods(['write'])
Expand All @@ -399,7 +403,7 @@ public function test_copy_copies_merged_config_to_all_writers()
// Due to crazy limitations in phpunit's mocking engine we have to be fairly
// liberal here as to what order we receive the config items
// Good news is that order shouldn't matter *yay*
//
//
// Now save your eyes and skip the next... 13 lines!
$key = $this->logicalOr('pie', 'kohana');
$val = $this->logicalOr('good', 'awesome');
Expand Down
Loading

0 comments on commit 7a6b3b4

Please sign in to comment.