phpunit fixes for deprecated notices. Also pdowrapper reset removal

pull/560/head
n0nag0n 10 months ago
parent 8d772b51b8
commit 79ffb61f94

@ -49,7 +49,8 @@ class PdoWrapper extends PDO
public function fetchField(string $sql, array $params = []) public function fetchField(string $sql, array $params = [])
{ {
$result = $this->fetchRow($sql, $params); $result = $this->fetchRow($sql, $params);
return reset($result); $data = $result->getData();
return reset($data);
} }
/** /**

@ -20,18 +20,6 @@ use JsonSerializable;
*/ */
class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable 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. * Collection data.
* *
@ -47,7 +35,6 @@ class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
$this->data = $data; $this->data = $data;
$this->handleReset();
} }
/** /**
@ -68,7 +55,6 @@ class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
public function __set(string $key, $value): void public function __set(string $key, $value): void
{ {
$this->data[$key] = $value; $this->data[$key] = $value;
$this->handleReset();
} }
/** /**
@ -85,7 +71,6 @@ class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
public function __unset(string $key): void public function __unset(string $key): void
{ {
unset($this->data[$key]); unset($this->data[$key]);
$this->handleReset();
} }
/** /**
@ -115,7 +100,6 @@ class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
} else { } else {
$this->data[$offset] = $value; $this->data[$offset] = $value;
} }
$this->handleReset();
} }
/** /**
@ -136,17 +120,6 @@ class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
public function offsetUnset($offset): void public function offsetUnset($offset): void
{ {
unset($this->data[$offset]); 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);
} }
/** /**
@ -234,7 +207,6 @@ class Collection implements ArrayAccess, Iterator, Countable, JsonSerializable
public function setData(array $data): void public function setData(array $data): void
{ {
$this->data = $data; $this->data = $data;
$this->handleReset();
} }
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]

@ -23,6 +23,7 @@
</testsuites> </testsuites>
<logging /> <logging />
<php> <php>
<ini name="error_reporting" value="-1"/>
<env name="PHPUNIT_TEST" value="true" force="true" /> <env name="PHPUNIT_TEST" value="true" force="true" />
</php> </php>
</phpunit> </phpunit>

@ -99,27 +99,4 @@ class CollectionTest extends TestCase
$this->collection->clear(); $this->collection->clear();
$this->assertEquals(0, $this->collection->count()); $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);
}
} }

@ -305,7 +305,7 @@ class DispatcherTest extends TestCase
public function testExecuteStringClassDefaultContainerButForgotInjectingEngine(): void public function testExecuteStringClassDefaultContainerButForgotInjectingEngine(): void
{ {
$this->expectException(TypeError::class); $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' ]); $result = $this->dispatcher->execute([ ContainerDefault::class, 'testTheContainer' ]);
} }
} }

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace tests; namespace tests;
use ErrorException;
use Exception; use Exception;
use flight\database\PdoWrapper; use flight\database\PdoWrapper;
use flight\Engine; use flight\Engine;
@ -750,8 +751,8 @@ class EngineTest extends TestCase
$engine->route('/container', Container::class.'->testThePdoWrapper'); $engine->route('/container', Container::class.'->testThePdoWrapper');
$engine->request()->url = '/container'; $engine->request()->url = '/container';
$this->expectException(PDOException::class); $this->expectException(ErrorException::class);
$this->expectExceptionMessage("invalid data source name"); $this->expectExceptionMessageMatches("/Passing null to parameter/");
$engine->start(); $engine->start();
} }

Loading…
Cancel
Save