Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve types and test functions #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Lunr/Core/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Configuration implements ArrayAccess, Iterator, Countable
* @param array<int|string,mixed>|bool $bootstrap Bootstrap config values, aka config values used before
* the class has been instantiated.
*/
public function __construct($bootstrap = FALSE)
public function __construct(array|bool $bootstrap = FALSE)
{
if (!is_array($bootstrap))
{
Expand Down Expand Up @@ -248,7 +248,7 @@ public function offsetUnset(mixed $offset): void
*/
public function offsetGet(mixed $offset): mixed
{
return isset($this->config[$offset]) ? $this->config[$offset] : NULL;
return $this->config[$offset] ?? NULL;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Lunr/Core/Tests/ConfigurationArrayAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function setUp(): void
*
* @dataProvider existingConfigPairProvider
*/
public function testOffsetExists($offset): void
public function testOffsetExists(mixed $offset): void
{
$this->assertTrue($this->class->offsetExists($offset));
}
Expand All @@ -46,7 +46,7 @@ public function testOffsetExists($offset): void
*
* @dataProvider nonExistingConfigPairProvider
*/
public function testOffsetDoesNotExist($offset): void
public function testOffsetDoesNotExist(mixed $offset): void
{
$this->assertFalse($this->class->offsetExists($offset));
}
Expand All @@ -58,7 +58,7 @@ public function testOffsetDoesNotExist($offset): void
*
* @dataProvider existingConfigPairProvider
*/
public function testOffsetGetWithExistingOffset($offset): void
public function testOffsetGetWithExistingOffset(mixed $offset): void
{
$this->assertEquals($this->config[$offset], $this->class->offsetGet($offset));
}
Expand All @@ -70,7 +70,7 @@ public function testOffsetGetWithExistingOffset($offset): void
*
* @dataProvider nonExistingConfigPairProvider
*/
public function testOffsetGetWithNonExistingOffset($offset): void
public function testOffsetGetWithNonExistingOffset(mixed $offset): void
{
$this->assertNull($this->class->offsetGet($offset));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Lunr/Core/Tests/ConfigurationArrayUsageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testArrayWriteAccess(): void
* @dataProvider existingConfigPairProvider
* @depends Lunr\Core\Tests\ConfigurationArrayAccessTest::testOffsetExists
*/
public function testIssetOnExistingOffset($offset): void
public function testIssetOnExistingOffset(mixed $offset): void
{
$this->assertTrue(isset($this->class[$offset]));
}
Expand All @@ -74,7 +74,7 @@ public function testIssetOnExistingOffset($offset): void
* @dataProvider nonExistingConfigPairProvider
* @depends Lunr\Core\Tests\ConfigurationArrayAccessTest::testOffsetDoesNotExist
*/
public function testIssetOnNonExistingOffset($offset): void
public function testIssetOnNonExistingOffset(mixed $offset): void
{
$this->assertFalse(isset($this->class[$offset]));
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public function testForeach(): void
++$iteration;
}

$this->assertEquals($iteration, count($this->class));
$this->assertCount($iteration, $this->class);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/Lunr/Core/Tests/ConfigurationBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function testNextIncreasesPosition(): void
public function testCountIsZero(): void
{
$this->assertEquals(0, $this->class->count());
$this->assertEquals(0, count($this->class));
$this->assertCount(0, $this->class);
}

}
Expand Down
24 changes: 19 additions & 5 deletions src/Lunr/Core/Tests/ConfigurationConvertArrayToClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,28 @@
$this->setUpArray([]);
}

/**
* Test convert_array_to_class() with non-array input values.
*
* @param mixed $input Various invalid values
*
* @dataProvider nonArrayValueProvider
* @covers Lunr\Core\Configuration::convert_array_to_class
*/
public function testConvertArrayToClassWithNonArrayValues(mixed$input): void

Check failure on line 38 in src/Lunr/Core/Tests/ConfigurationConvertArrayToClassTest.php

View workflow job for this annotation

GitHub Actions / php-tests / phpcs / PHPCS

Expected 1 space between type hint and argument "$input"; 0 found

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space

{
$method = $this->get_reflection_method('convert_array_to_class');
$this->assertEquals($input, $method->invokeArgs($this->class, [ $input ]));
}

/**
* Test convert_array_to_class() with an empty array as input.
*
* @covers Lunr\Core\Configuration::convert_array_to_class
*/
public function testConvertArrayToClassWithEmptyArrayValue(): void
{
$method = $this->get_accessible_reflection_method('convert_array_to_class');
$method = $this->get_reflection_method('convert_array_to_class');
$output = $method->invokeArgs($this->class, [ [] ]);

$this->assertArrayEmpty($output);
Expand All @@ -51,7 +65,7 @@
$input['test'] = 'String';
$input['test1'] = 1;

$method = $this->get_accessible_reflection_method('convert_array_to_class');
$method = $this->get_reflection_method('convert_array_to_class');
$output = $method->invokeArgs($this->class, [ $input ]);

$this->assertEquals($input, $output);
Expand All @@ -71,17 +85,17 @@
$config['test2']['test3'] = 1;
$config['test2']['test4'] = FALSE;

$method = $this->get_accessible_reflection_method('convert_array_to_class');
$method = $this->get_reflection_method('convert_array_to_class');
$output = $method->invokeArgs($this->class, [ $config ]);

$this->assertTrue(is_array($output));

$this->assertInstanceOf('Lunr\Core\Configuration', $output['test2']);

$property = $this->get_accessible_reflection_property('size');
$property = $this->get_reflection_property('size');
$this->assertEquals(2, $property->getValue($output['test2']));

$property = $this->get_accessible_reflection_property('config');
$property = $this->get_reflection_property('config');
$this->assertEquals($config['test2'], $property->getValue($output['test2']));
}

Expand Down
18 changes: 3 additions & 15 deletions src/Lunr/Core/Tests/ConfigurationLoadFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public function testLoadCorrectFile(): void
$this->config['load']['one'] = 'Value';
$this->config['load']['two'] = 'String';

$property = $this->reflection->getProperty('config');
$property->setAccessible(TRUE);

$this->assertEquals($this->config, $this->class->toArray());
}

Expand All @@ -53,9 +50,6 @@ public function testLoadCorrectFile(): void
*/
public function testLoadFileOverwritesValues(): void
{
$property = $this->reflection->getProperty('config');
$property->setAccessible(TRUE);

$this->class->load_file('overwrite');

$config = [];
Expand All @@ -74,9 +68,6 @@ public function testLoadFileOverwritesValues(): void
*/
public function testLoadFileMergesArrays(): void
{
$property = $this->reflection->getProperty('config');
$property->setAccessible(TRUE);

$this->class->load_file('merge');

$config = [];
Expand All @@ -94,8 +85,7 @@ public function testLoadFileMergesArrays(): void
*/
public function testLoadInvalidFile(): void
{
$property = $this->reflection->getProperty('config');
$property->setAccessible(TRUE);
$property = $this->get_reflection_property('config');

$before = $property->getValue($this->class);

Expand All @@ -122,8 +112,7 @@ public function testLoadNonExistingFile(): void
$this->expectException('\PHPUnit_Framework_Error');
}

$property = $this->reflection->getProperty('config');
$property->setAccessible(TRUE);
$property = $this->get_reflection_property('config');

$before = $property->getValue($this->class);

Expand All @@ -139,8 +128,7 @@ public function testLoadNonExistingFile(): void
*/
public function testLoadFileInvalidatesSize(): void
{
$property = $this->reflection->getProperty('size_invalid');
$property->setAccessible(TRUE);
$property = $this->get_reflection_property('size_invalid');

$this->assertFalse($property->getValue($this->class));

Expand Down
4 changes: 2 additions & 2 deletions src/Lunr/Core/Tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class ConfigurationTest extends LunrBaseTest
* Default config values.
* @var array
*/
protected $config;
protected array $config;

/**
* Instance of the tested class.
Expand All @@ -53,7 +53,7 @@ protected function setUpNonArray(): void
*
* @return void
*/
protected function setUpArray($config): void
protected function setUpArray(array $config): void
{
$this->config = $config;
$this->class = new Configuration($config);
Expand Down
Loading