2015-10-06 15:36:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2015-11-04 14:36:38 +01:00
|
|
|
* @dataProvider ../databases.ini
|
2015-10-06 15:36:05 +02:00
|
|
|
*/
|
|
|
|
|
2017-06-09 22:20:47 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-10-06 15:36:05 +02:00
|
|
|
use Tester\Assert;
|
|
|
|
|
|
|
|
require __DIR__ . '/bootstrap.php';
|
|
|
|
|
2015-10-08 02:13:22 +02:00
|
|
|
$conn = new Dibi\Connection($config);
|
2015-10-06 15:36:05 +02:00
|
|
|
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
|
|
|
|
|
|
|
|
|
|
|
$row = $conn->fetch('SELECT * FROM [products] ORDER BY product_id');
|
|
|
|
|
|
|
|
// existing
|
|
|
|
Assert::same('Chair', $row->title);
|
|
|
|
Assert::true(isset($row->title));
|
|
|
|
Assert::same('Chair', $row['title']);
|
|
|
|
Assert::true(isset($row['title']));
|
|
|
|
|
|
|
|
|
|
|
|
// missing
|
|
|
|
Assert::error(function () use ($row) {
|
|
|
|
$x = $row->missing;
|
2015-10-06 13:23:46 +02:00
|
|
|
}, E_USER_NOTICE, "Attempt to read missing column 'missing'.");
|
2015-10-06 15:36:05 +02:00
|
|
|
|
|
|
|
Assert::error(function () use ($row) {
|
|
|
|
$x = $row['missing'];
|
2015-10-06 13:23:46 +02:00
|
|
|
}, E_USER_NOTICE, "Attempt to read missing column 'missing'.");
|
2015-10-06 15:36:05 +02:00
|
|
|
|
|
|
|
Assert::false(isset($row->missing));
|
|
|
|
Assert::false(isset($row['missing']));
|
|
|
|
|
|
|
|
|
2015-10-06 13:23:46 +02:00
|
|
|
// suggestions
|
|
|
|
Assert::error(function () use ($row) {
|
|
|
|
$x = $row->tilte;
|
|
|
|
}, E_USER_NOTICE, "Attempt to read missing column 'tilte', did you mean 'title'?");
|
|
|
|
|
|
|
|
Assert::error(function () use ($row) {
|
|
|
|
$x = $row['tilte'];
|
|
|
|
}, E_USER_NOTICE, "Attempt to read missing column 'tilte', did you mean 'title'?");
|
|
|
|
|
|
|
|
|
2015-10-06 15:36:05 +02:00
|
|
|
// to array
|
2015-11-04 14:23:14 +01:00
|
|
|
Assert::same(['product_id' => num(1), 'title' => 'Chair'], iterator_to_array($row));
|
|
|
|
Assert::same(['product_id' => num(1), 'title' => 'Chair'], $row->toArray());
|
2015-10-06 15:36:05 +02:00
|
|
|
|
|
|
|
// counting
|
|
|
|
Assert::same(2, count($row));
|