Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/composer.lock
/vendor
.phpunit.cache
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"php": ">=7.1.0",
"php": ">=8.1.0",
"atlas/pdo": "~1.0",
"atlas/query": "~1.0"
},
Expand All @@ -24,7 +24,7 @@
"require-dev": {
"atlas/testing": "~1.0",
"pds/skeleton": "~1.0",
"phpunit/phpunit": "~7.0"
"phpunit/phpunit": "~10.0 || ~11.0 || ~12.0"
},
"autoload-dev": {
"psr-4": {
Expand Down
23 changes: 12 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<phpunit bootstrap="phpunit.php">
<testsuites>
<testsuite name="atlas/table">
<directory>tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="phpunit.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="atlas/table">
<directory>tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/TableLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TableLocator

protected $factory;

protected $tables = [];
protected $instances = [];

public static function new(...$args) : TableLocator
{
Expand All @@ -33,7 +33,7 @@ public static function new(...$args) : TableLocator
public function __construct(
ConnectionLocator $connectionLocator,
TableQueryFactory $tableQueryFactory,
callable $factory = null
?callable $factory = null
) {
$this->connectionLocator = $connectionLocator;
$this->tableQueryFactory = $tableQueryFactory;
Expand Down
4 changes: 3 additions & 1 deletion tests/TableLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

class TableLocatorTest extends \PHPUnit\Framework\TestCase
{
protected function setUp()
protected $tableLocator;

protected function setUp() : void
{
$connection = (new DataSourceFixture())->exec();
$this->tableLocator = TableLocator::new($connection);
Expand Down
10 changes: 5 additions & 5 deletions tests/TableSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TableSelectTest extends \PHPUnit\Framework\TestCase

protected $table;

protected function setUp()
protected function setUp() : void
{
$connection = (new DataSourceFixture())->exec();
$this->table = TableLocator::new($connection)->get(EmployeeTable::CLASS);
Expand All @@ -31,7 +31,7 @@ public function testFetchRow()
// success
$actual = $this->select->where('id = ', '1')->fetchRow();
$this->assertInstanceOf(EmployeeRow::CLASS, $actual);
$this->assertSame($expect, $actual->getArrayCopy());
$this->assertSame($expect, array_map('strval', $actual->getArrayCopy()));

// failure
$actual = $this->select->where('id = ', '-1')->fetchRow();
Expand Down Expand Up @@ -64,9 +64,9 @@ public function testFetchRows()
// success
$actual = $this->select->where('id IN ', [1, 2, 3])->fetchRows();
$this->assertCount(3, $actual);
$this->assertSame($expect[0], $actual[0]->getArrayCopy());
$this->assertSame($expect[1], $actual[1]->getArrayCopy());
$this->assertSame($expect[2], $actual[2]->getArrayCopy());
$this->assertSame($expect[0], array_map('strval', $actual[0]->getArrayCopy()));
$this->assertSame($expect[1], array_map('strval', $actual[1]->getArrayCopy()));
$this->assertSame($expect[2], array_map('strval', $actual[2]->getArrayCopy()));

// failure
$actual = $this->select->where('id IN ', [997, 998, 999])->fetchRows();
Expand Down
19 changes: 10 additions & 9 deletions tests/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TableTest extends \PHPUnit\Framework\TestCase

protected $tableLocator;

protected function setUp()
protected function setUp() : void
{
$connection = (new DataSourceFixture())->exec();
(new CompositeDataSourceFixture($connection))->exec();
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testFetchRow()
$this->logQueries();
$row = $this->table->fetchRow(1);
$this->assertInstanceOf(EmployeeRow::CLASS, $row);
$this->assertSame($expect, $row->getArrayCopy());
$this->assertSame($expect, array_map('strval', $row->getArrayCopy()));

// check quoting
$queries = $this->getQueries();
Expand Down Expand Up @@ -101,7 +101,7 @@ public function testFetchRow_compositeKey()
'course_number' => '100'
]);

$this->assertSame($expect, $actual->getArrayCopy());
$this->assertSame($expect, array_map('strval', $actual->getArrayCopy()));

// check quoting
$queries = $this->getQueries();
Expand Down Expand Up @@ -174,9 +174,9 @@ public function testFetchRows()
$this->assertInstanceOf(EmployeeRow::CLASS, $actual[0]);
$this->assertInstanceOf(EmployeeRow::CLASS, $actual[1]);
$this->assertInstanceOf(EmployeeRow::CLASS, $actual[2]);
$this->assertSame($expect[0], $actual[0]->getArrayCopy());
$this->assertSame($expect[1], $actual[1]->getArrayCopy());
$this->assertSame($expect[2], $actual[2]->getArrayCopy());
$this->assertSame($expect[0], array_map('strval', $actual[0]->getArrayCopy()));
$this->assertSame($expect[1], array_map('strval', $actual[1]->getArrayCopy()));
$this->assertSame($expect[2], array_map('strval', $actual[2]->getArrayCopy()));

// check quoting
$queries = $this->getQueries();
Expand Down Expand Up @@ -224,9 +224,9 @@ public function testFetchRows_compositeKey()
$this->assertInstanceOf(CourseRow::CLASS, $actual[0]);
$this->assertInstanceOf(CourseRow::CLASS, $actual[1]);
$this->assertInstanceOf(CourseRow::CLASS, $actual[2]);
$this->assertSame($expect[0], $actual[0]->getArrayCopy());
$this->assertSame($expect[1], $actual[1]->getArrayCopy());
$this->assertSame($expect[2], $actual[2]->getArrayCopy());
$this->assertSame($expect[0], array_map('strval', $actual[0]->getArrayCopy()));
$this->assertSame($expect[1], array_map('strval', $actual[1]->getArrayCopy()));
$this->assertSame($expect[2], array_map('strval', $actual[2]->getArrayCopy()));

// check quoting
$queries = $this->getQueries();
Expand Down Expand Up @@ -287,6 +287,7 @@ public function testInsertRow()
$actual = $this->table->getReadConnection()->fetchOne(
'SELECT * FROM employee WHERE id = 13'
);
$actual = array_map('strval', $actual);
$this->assertSame($expect, $actual);

// try to insert again, should fail on unique name
Expand Down