Skip to content

Commit 4fe54ea

Browse files
authored
Merge pull request #560 from flightphp/php83-fixes
phpunit fixes for deprecated notices. Also Collection reset removal
2 parents 8d772b5 + 79ffb61 commit 4fe54ea

File tree

6 files changed

+7
-55
lines changed

6 files changed

+7
-55
lines changed

flight/database/PdoWrapper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public function runQuery(string $sql, array $params = []): PDOStatement
4949
public function fetchField(string $sql, array $params = [])
5050
{
5151
$result = $this->fetchRow($sql, $params);
52-
return reset($result);
52+
$data = $result->getData();
53+
return reset($data);
5354
}
5455

5556
/**

flight/util/Collection.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@
2020
*/
2121
class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
2222
{
23-
/**
24-
* This is to allow for reset() to work properly.
25-
*
26-
* WARNING! This MUST be the first variable in this class!!!
27-
*
28-
* PHPStan is ignoring this because we don't need actually to read the property
29-
*
30-
* @var mixed
31-
* @phpstan-ignore-next-line
32-
*/
33-
private $first_property = null;
34-
3523
/**
3624
* Collection data.
3725
*
@@ -47,7 +35,6 @@ class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
4735
public function __construct(array $data = [])
4836
{
4937
$this->data = $data;
50-
$this->handleReset();
5138
}
5239

5340
/**
@@ -68,7 +55,6 @@ public function __get(string $key)
6855
public function __set(string $key, $value): void
6956
{
7057
$this->data[$key] = $value;
71-
$this->handleReset();
7258
}
7359

7460
/**
@@ -85,7 +71,6 @@ public function __isset(string $key): bool
8571
public function __unset(string $key): void
8672
{
8773
unset($this->data[$key]);
88-
$this->handleReset();
8974
}
9075

9176
/**
@@ -115,7 +100,6 @@ public function offsetSet($offset, $value): void
115100
} else {
116101
$this->data[$offset] = $value;
117102
}
118-
$this->handleReset();
119103
}
120104

121105
/**
@@ -136,17 +120,6 @@ public function offsetExists($offset): bool
136120
public function offsetUnset($offset): void
137121
{
138122
unset($this->data[$offset]);
139-
$this->handleReset();
140-
}
141-
142-
/**
143-
* This is to allow for reset() of a Collection to work properly.
144-
*
145-
* @return void
146-
*/
147-
public function handleReset()
148-
{
149-
$this->first_property = reset($this->data);
150123
}
151124

152125
/**
@@ -234,7 +207,6 @@ public function getData(): array
234207
public function setData(array $data): void
235208
{
236209
$this->data = $data;
237-
$this->handleReset();
238210
}
239211

240212
#[\ReturnTypeWillChange]

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
</testsuites>
2424
<logging />
2525
<php>
26+
<ini name="error_reporting" value="-1"/>
2627
<env name="PHPUNIT_TEST" value="true" force="true" />
2728
</php>
2829
</phpunit>

tests/CollectionTest.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,4 @@ public function testClear()
9999
$this->collection->clear();
100100
$this->assertEquals(0, $this->collection->count());
101101
}
102-
103-
public function testResetByProperty()
104-
{
105-
$this->collection->a = 11;
106-
$this->collection->b = 22;
107-
$result = reset($this->collection);
108-
$this->assertEquals(11, $result);
109-
}
110-
111-
public function testResetBySetData()
112-
{
113-
$this->collection->setData(['a' => 11, 'b' => 22]);
114-
$result = reset($this->collection);
115-
$this->assertEquals(11, $result);
116-
}
117-
118-
public function testResetByArraySet()
119-
{
120-
$this->collection['a'] = 11;
121-
$this->collection['b'] = 22;
122-
$result = reset($this->collection);
123-
$this->assertEquals(11, $result);
124-
}
125102
}

tests/DispatcherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public function testExecuteStringClassDefaultContainerArraySyntax(): void
305305
public function testExecuteStringClassDefaultContainerButForgotInjectingEngine(): void
306306
{
307307
$this->expectException(TypeError::class);
308-
$this->expectExceptionMessageMatches('#Argument 1 passed to tests\\\\classes\\\\ContainerDefault::__construct\(\) must be an instance of flight\\\\Engine, null given#');
308+
$this->expectExceptionMessageMatches('#tests\\\\classes\\\\ContainerDefault::__construct\(\).+flight\\\\Engine, null given#');
309309
$result = $this->dispatcher->execute([ ContainerDefault::class, 'testTheContainer' ]);
310310
}
311311
}

tests/EngineTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace tests;
66

7+
use ErrorException;
78
use Exception;
89
use flight\database\PdoWrapper;
910
use flight\Engine;
@@ -750,8 +751,8 @@ public function testContainerDicePdoWrapperTestBadParams() {
750751
$engine->route('/container', Container::class.'->testThePdoWrapper');
751752
$engine->request()->url = '/container';
752753

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

756757
$engine->start();
757758
}

0 commit comments

Comments
 (0)