Skip to content

Commit

Permalink
Merge pull request #560 from flightphp/php83-fixes
Browse files Browse the repository at this point in the history
phpunit fixes for deprecated notices. Also Collection reset removal
  • Loading branch information
n0nag0n authored Mar 23, 2024
2 parents 8d772b5 + 79ffb61 commit 4fe54ea
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 55 deletions.
3 changes: 2 additions & 1 deletion flight/database/PdoWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public function runQuery(string $sql, array $params = []): PDOStatement
public function fetchField(string $sql, array $params = [])
{
$result = $this->fetchRow($sql, $params);
return reset($result);
$data = $result->getData();
return reset($data);
}

/**
Expand Down
28 changes: 0 additions & 28 deletions flight/util/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@
*/
class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
{
/**
* This is to allow for reset() to work properly.
*
* WARNING! This MUST be the first variable in this class!!!
*
* PHPStan is ignoring this because we don't need actually to read the property
*
* @var mixed
* @phpstan-ignore-next-line
*/
private $first_property = null;

/**
* Collection data.
*
Expand All @@ -47,7 +35,6 @@ class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
public function __construct(array $data = [])
{
$this->data = $data;
$this->handleReset();
}

/**
Expand All @@ -68,7 +55,6 @@ public function __get(string $key)
public function __set(string $key, $value): void
{
$this->data[$key] = $value;
$this->handleReset();
}

/**
Expand All @@ -85,7 +71,6 @@ public function __isset(string $key): bool
public function __unset(string $key): void
{
unset($this->data[$key]);
$this->handleReset();
}

/**
Expand Down Expand Up @@ -115,7 +100,6 @@ public function offsetSet($offset, $value): void
} else {
$this->data[$offset] = $value;
}
$this->handleReset();
}

/**
Expand All @@ -136,17 +120,6 @@ public function offsetExists($offset): bool
public function offsetUnset($offset): void
{
unset($this->data[$offset]);
$this->handleReset();
}

/**
* This is to allow for reset() of a Collection to work properly.
*
* @return void
*/
public function handleReset()
{
$this->first_property = reset($this->data);
}

/**
Expand Down Expand Up @@ -234,7 +207,6 @@ public function getData(): array
public function setData(array $data): void
{
$this->data = $data;
$this->handleReset();
}

#[\ReturnTypeWillChange]
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</testsuites>
<logging />
<php>
<ini name="error_reporting" value="-1"/>
<env name="PHPUNIT_TEST" value="true" force="true" />
</php>
</phpunit>
23 changes: 0 additions & 23 deletions tests/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,4 @@ public function testClear()
$this->collection->clear();
$this->assertEquals(0, $this->collection->count());
}

public function testResetByProperty()
{
$this->collection->a = 11;
$this->collection->b = 22;
$result = reset($this->collection);
$this->assertEquals(11, $result);
}

public function testResetBySetData()
{
$this->collection->setData(['a' => 11, 'b' => 22]);
$result = reset($this->collection);
$this->assertEquals(11, $result);
}

public function testResetByArraySet()
{
$this->collection['a'] = 11;
$this->collection['b'] = 22;
$result = reset($this->collection);
$this->assertEquals(11, $result);
}
}
2 changes: 1 addition & 1 deletion tests/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public function testExecuteStringClassDefaultContainerArraySyntax(): void
public function testExecuteStringClassDefaultContainerButForgotInjectingEngine(): void
{
$this->expectException(TypeError::class);
$this->expectExceptionMessageMatches('#Argument 1 passed to tests\\\\classes\\\\ContainerDefault::__construct\(\) must be an instance of flight\\\\Engine, null given#');
$this->expectExceptionMessageMatches('#tests\\\\classes\\\\ContainerDefault::__construct\(\).+flight\\\\Engine, null given#');
$result = $this->dispatcher->execute([ ContainerDefault::class, 'testTheContainer' ]);
}
}
5 changes: 3 additions & 2 deletions tests/EngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace tests;

use ErrorException;
use Exception;
use flight\database\PdoWrapper;
use flight\Engine;
Expand Down Expand Up @@ -750,8 +751,8 @@ public function testContainerDicePdoWrapperTestBadParams() {
$engine->route('/container', Container::class.'->testThePdoWrapper');
$engine->request()->url = '/container';

$this->expectException(PDOException::class);
$this->expectExceptionMessage("invalid data source name");
$this->expectException(ErrorException::class);
$this->expectExceptionMessageMatches("/Passing null to parameter/");

$engine->start();
}
Expand Down

0 comments on commit 4fe54ea

Please sign in to comment.