From 7bc781ad606260608ecf9402de0bfe041d7d012d Mon Sep 17 00:00:00 2001 From: jake johns Date: Wed, 20 Sep 2023 14:45:00 -0400 Subject: [PATCH 1/5] Fix property name typo Removes deprecation notice for dynamic property creation --- src/TableLocator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TableLocator.php b/src/TableLocator.php index 768fd38..056dc81 100644 --- a/src/TableLocator.php +++ b/src/TableLocator.php @@ -20,7 +20,7 @@ class TableLocator protected $factory; - protected $tables = []; + protected $instances = []; public static function new(...$args) : TableLocator { From aaae93eb1d6c2b3b9b11d3dfbd755e42564d0902 Mon Sep 17 00:00:00 2001 From: jake johns Date: Wed, 20 Sep 2023 21:35:42 -0400 Subject: [PATCH 2/5] Update and Comply with PHPUnit --- composer.json | 4 ++-- phpunit.xml.dist | 23 ++++++++++++----------- tests/TableLocatorTest.php | 4 +++- tests/TableSelectTest.php | 2 +- tests/TableTest.php | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 86cf896..fb92452 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "php": ">=7.1.0", + "php": ">=8.1.0", "atlas/pdo": "~1.0", "atlas/query": "~1.0" }, @@ -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": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bb5c098..b26ac20 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,12 +1,13 @@ - - - - tests/ - - - - - ./src - - + + + + + ./src + + + + + tests/ + + diff --git a/tests/TableLocatorTest.php b/tests/TableLocatorTest.php index 20a684b..57fc831 100644 --- a/tests/TableLocatorTest.php +++ b/tests/TableLocatorTest.php @@ -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); diff --git a/tests/TableSelectTest.php b/tests/TableSelectTest.php index 1ddb6b2..5298f5d 100644 --- a/tests/TableSelectTest.php +++ b/tests/TableSelectTest.php @@ -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); diff --git a/tests/TableTest.php b/tests/TableTest.php index f57d6e2..a3d39c4 100644 --- a/tests/TableTest.php +++ b/tests/TableTest.php @@ -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(); From 6c1d5892f7a910b7c1ac2e4eda1fb344a8357d66 Mon Sep 17 00:00:00 2001 From: jake johns Date: Wed, 20 Sep 2023 22:10:21 -0400 Subject: [PATCH 3/5] Cast test results to strings for php8 See bug: https://bugs.php.net/bug.php?id=80808 --- tests/TableSelectTest.php | 8 ++++---- tests/TableTest.php | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/TableSelectTest.php b/tests/TableSelectTest.php index 5298f5d..ce66846 100644 --- a/tests/TableSelectTest.php +++ b/tests/TableSelectTest.php @@ -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(); @@ -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(); diff --git a/tests/TableTest.php b/tests/TableTest.php index a3d39c4..ad13f3c 100644 --- a/tests/TableTest.php +++ b/tests/TableTest.php @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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 From 7fd4f8e12eb394f76c5240372dcd2affe3c835ad Mon Sep 17 00:00:00 2001 From: jake johns Date: Sat, 1 Mar 2025 23:31:10 -0500 Subject: [PATCH 4/5] Migrate phpunit config --- .gitignore | 1 + phpunit.xml.dist | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index ff72e2d..f272444 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /composer.lock /vendor +.phpunit.cache diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b26ac20..e8622b7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,13 @@ - - - - ./src - - + tests/ + + + ./src + + From 9fde41c05198937666dd02d8d2f9ea7e4ea9f194 Mon Sep 17 00:00:00 2001 From: jake johns Date: Sat, 1 Mar 2025 23:31:32 -0500 Subject: [PATCH 5/5] Use explicit nullable type --- src/TableLocator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TableLocator.php b/src/TableLocator.php index 056dc81..07dc541 100644 --- a/src/TableLocator.php +++ b/src/TableLocator.php @@ -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;