From df724a99e4948445be064f6fa366933e25688e18 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 19:42:48 -0600 Subject: [PATCH 01/12] Revert "Try a larger value for the fractional tests." This reverts commit 75792dc8ed71b032bcc906af41f1cb3557a02512. --- tests/Fixture/DatatypesFixture.php | 2 +- tests/TestCase/ORM/QueryTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Fixture/DatatypesFixture.php b/tests/Fixture/DatatypesFixture.php index aa15ab9018c..bee22a1dbcd 100644 --- a/tests/Fixture/DatatypesFixture.php +++ b/tests/Fixture/DatatypesFixture.php @@ -27,7 +27,7 @@ class DatatypesFixture extends TestFixture public $fields = [ 'id' => ['type' => 'biginteger'], 'cost' => ['type' => 'decimal', 'length' => 20, 'precision' => 1, 'null' => true], - 'fraction' => ['type' => 'decimal', 'length' => 15, 'precision' => 14, 'null' => true], + 'fraction' => ['type' => 'decimal', 'length' => 20, 'precision' => 19, 'null' => true], 'floaty' => ['type' => 'float', 'null' => true], 'small' => ['type' => 'smallinteger', 'null' => true], 'tiny' => ['type' => 'tinyinteger', 'null' => true], diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index 01ba4eb32ce..13731e6ec9b 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -3196,7 +3196,7 @@ public function testSelectLargeNumbers() $this->assertNotEmpty($out, 'Should get a record'); $this->assertSame($big, $out->cost); - $small = '0.12345678901234'; + $small = '0.123456789012345'; $entity = $table->newEntity(['fraction' => $small]); $table->saveOrFail($entity); @@ -3206,9 +3206,9 @@ public function testSelectLargeNumbers() ]) ->first(); $this->assertNotEmpty($out, 'Should get a record'); - $this->assertRegExp('/^0?\.12345678901234/', $out->fraction); + $this->assertRegExp('/^0?\.123456789012345/', $out->fraction); - $small = 0.12345678901234; + $small = 0.123456789012345; $entity = $table->newEntity(['fraction' => $small]); $table->saveOrFail($entity); From 99f46a56b877627df2244c820109a33979a4976f Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 19:46:15 -0600 Subject: [PATCH 02/12] Add logging to decimal test --- tests/TestCase/ORM/QueryTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index 13731e6ec9b..1aec662170e 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -3182,12 +3182,16 @@ public function testSelectLargeNumbers() $big = '1234567890123456789.2'; $table = $this->getTableLocator()->get('Datatypes'); + print_r($table->getSchema()); + $entity = $table->newEntity([]); $entity->cost = $big; $entity->tiny = 1; $entity->small = 10; $table->saveOrFail($entity); + print_r($table->find()->all()->toList()); + $out = $table->find() ->where([ 'cost' => $big, From 8ba49f7cf5ef2fded532cf85705b1838b7168ceb Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 20:02:41 -0600 Subject: [PATCH 03/12] Add logging --- tests/TestCase/ORM/QueryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index 1aec662170e..40f9e3bf6ed 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -3190,7 +3190,6 @@ public function testSelectLargeNumbers() $entity->small = 10; $table->saveOrFail($entity); - print_r($table->find()->all()->toList()); $out = $table->find() ->where([ @@ -3204,6 +3203,7 @@ public function testSelectLargeNumbers() $entity = $table->newEntity(['fraction' => $small]); $table->saveOrFail($entity); + print_r($table->find()->all()->toList()); $out = $table->find() ->where([ 'fraction' => $small, From c137ec1d480f9ef6989461d1a1ba45b4af50167b Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 20:40:58 -0600 Subject: [PATCH 04/12] Add logging --- tests/TestCase/ORM/QueryTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index 40f9e3bf6ed..60e453f5ff7 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -3202,7 +3202,16 @@ public function testSelectLargeNumbers() $small = '0.123456789012345'; $entity = $table->newEntity(['fraction' => $small]); + Log::setConfig('queryLog', [ + 'className' => 'Array', + 'scopes' => ['queriesLog'], + ]); + $this->connection->enableQueryLogging(); $table->saveOrFail($entity); + $this->connection->disableQueryLogging(); + print_r(Log::engine('queryLog')->read()); + Log::drop('queryLog'); + print_r($table->find()->all()->toList()); $out = $table->find() ->where([ From 82d7701b233ec8afdc951a4142961b90914481f0 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 20:41:29 -0600 Subject: [PATCH 05/12] Add logging --- tests/TestCase/ORM/QueryTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index 60e453f5ff7..bfd63fcedf7 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -28,6 +28,7 @@ use Cake\Event\EventInterface; use Cake\I18n\FrozenTime; use Cake\I18n\Time; +use Cake\Log\Log; use Cake\ORM\Query; use Cake\ORM\ResultSet; use Cake\TestSuite\TestCase; From 98b12c9019f44a57cfa85fb08c8ec6a2f6d6768b Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 20:55:35 -0600 Subject: [PATCH 06/12] Add logging --- tests/TestCase/ORM/QueryTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index bfd63fcedf7..29d2b26ed74 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -3201,7 +3201,9 @@ public function testSelectLargeNumbers() $this->assertSame($big, $out->cost); $small = '0.123456789012345'; + print_r($small); $entity = $table->newEntity(['fraction' => $small]); + print_r($entity->extract(['fraction'])); Log::setConfig('queryLog', [ 'className' => 'Array', From aa9a732e56b502f1068efb487598f9b8ab78997f Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 21:16:37 -0600 Subject: [PATCH 07/12] Add logging --- tests/TestCase/ORM/QueryTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index 29d2b26ed74..ac7ecfd35cd 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -3201,9 +3201,11 @@ public function testSelectLargeNumbers() $this->assertSame($big, $out->cost); $small = '0.123456789012345'; - print_r($small); + echo $small . ' - ' . gettype($small) . PHP_EOL; $entity = $table->newEntity(['fraction' => $small]); - print_r($entity->extract(['fraction'])); + $extracted = $entity->extract(['fraction']); + print_r($extracted); + echo 'fraction - ' . $extracted['fraction'] . PHP_EOL; Log::setConfig('queryLog', [ 'className' => 'Array', From 5eabba7fb690c970a78a1e84eb72bab05d6c2f12 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 21:17:36 -0600 Subject: [PATCH 08/12] Add logging --- tests/TestCase/ORM/QueryTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index ac7ecfd35cd..3d6dc6b500c 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -3203,6 +3203,7 @@ public function testSelectLargeNumbers() $small = '0.123456789012345'; echo $small . ' - ' . gettype($small) . PHP_EOL; $entity = $table->newEntity(['fraction' => $small]); + print_r($entity); $extracted = $entity->extract(['fraction']); print_r($extracted); echo 'fraction - ' . $extracted['fraction'] . PHP_EOL; From 8cff0ea45a3920b59de64f42fc5b67a7bff345a0 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 21:32:01 -0600 Subject: [PATCH 09/12] Add logging --- .github/workflows/ci.yml | 4 ++-- src/ORM/Marshaller.php | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8018571461..c1e923f7e8a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,9 +65,9 @@ jobs: if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_DSN='postgres://postgres@127.0.0.1:${{ job.services.postgres.ports['5432'] }}/postgres'; fi if [[ ${{ matrix.php-version }} == '7.2' ]]; then - vendor/bin/phpunit + vendor/bin/phpunit --filter testSelectLargeNumbers "tests\TestCase\ORM\QueryTest.php" else - vendor/bin/phpunit --verbose + vendor/bin/phpunit --verbose --filter testSelectLargeNumbers "tests\TestCase\ORM\QueryTest.php" fi coding-standard: diff --git a/src/ORM/Marshaller.php b/src/ORM/Marshaller.php index 22c8e3763d6..f7e49b55577 100644 --- a/src/ORM/Marshaller.php +++ b/src/ORM/Marshaller.php @@ -169,6 +169,8 @@ protected function _buildPropertyMap(array $data, array $options): array public function one(array $data, array $options = []): EntityInterface { [$data, $options] = $this->_prepareDataAndOptions($data, $options); + echo 'Marshaller::one' . PHP_EOL; + print_r($data); $primaryKey = (array)$this->_table->getPrimaryKey(); $entityClass = $this->_table->getEntityClass(); @@ -182,6 +184,8 @@ public function one(array $data, array $options = []): EntityInterface } } $errors = $this->_validate($data, $options, true); + echo 'Marshaller::one - _validate' . PHP_EOL; + print_r($data); $options['isMerge'] = false; $propertyMap = $this->_buildPropertyMap($data, $options); @@ -205,6 +209,8 @@ public function one(array $data, array $options = []): EntityInterface } } + echo 'Marshaller::one - properties' . PHP_EOL; + print_r($properties); if (isset($options['fields'])) { foreach ((array)$options['fields'] as $field) { if (array_key_exists($field, $properties)) { @@ -215,6 +221,9 @@ public function one(array $data, array $options = []): EntityInterface $entity->set($properties); } + echo 'Marshaller::one - set' . PHP_EOL; + print_r($entity); + // Don't flag clean association entities as // dirty so we don't persist empty records. foreach ($properties as $field => $value) { From 58758dcc6cf1889ad92b5c65b2a42dabf3b3eb6c Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 21:38:09 -0600 Subject: [PATCH 10/12] Add logging --- src/ORM/Marshaller.php | 16 ++++++++-------- tests/TestCase/ORM/QueryTest.php | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ORM/Marshaller.php b/src/ORM/Marshaller.php index f7e49b55577..fa34919699d 100644 --- a/src/ORM/Marshaller.php +++ b/src/ORM/Marshaller.php @@ -169,8 +169,8 @@ protected function _buildPropertyMap(array $data, array $options): array public function one(array $data, array $options = []): EntityInterface { [$data, $options] = $this->_prepareDataAndOptions($data, $options); - echo 'Marshaller::one' . PHP_EOL; - print_r($data); + //echo 'Marshaller::one' . PHP_EOL; + //print_r($data); $primaryKey = (array)$this->_table->getPrimaryKey(); $entityClass = $this->_table->getEntityClass(); @@ -184,8 +184,8 @@ public function one(array $data, array $options = []): EntityInterface } } $errors = $this->_validate($data, $options, true); - echo 'Marshaller::one - _validate' . PHP_EOL; - print_r($data); + //echo 'Marshaller::one - _validate' . PHP_EOL; + //print_r($data); $options['isMerge'] = false; $propertyMap = $this->_buildPropertyMap($data, $options); @@ -209,8 +209,8 @@ public function one(array $data, array $options = []): EntityInterface } } - echo 'Marshaller::one - properties' . PHP_EOL; - print_r($properties); + //echo 'Marshaller::one - properties' . PHP_EOL; + //print_r($properties); if (isset($options['fields'])) { foreach ((array)$options['fields'] as $field) { if (array_key_exists($field, $properties)) { @@ -221,8 +221,8 @@ public function one(array $data, array $options = []): EntityInterface $entity->set($properties); } - echo 'Marshaller::one - set' . PHP_EOL; - print_r($entity); + //echo 'Marshaller::one - set' . PHP_EOL; + //print_r($entity); // Don't flag clean association entities as // dirty so we don't persist empty records. diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index 3d6dc6b500c..dd34da31630 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -3206,7 +3206,7 @@ public function testSelectLargeNumbers() print_r($entity); $extracted = $entity->extract(['fraction']); print_r($extracted); - echo 'fraction - ' . $extracted['fraction'] . PHP_EOL; + echo 'fraction - ' . gettype($extracted['fraction']) . PHP_EOL; Log::setConfig('queryLog', [ 'className' => 'Array', From 04a925b8ab57f20928a1f4c7f414903667786317 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 21:42:01 -0600 Subject: [PATCH 11/12] Add logging --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1e923f7e8a..df3b4cbebf3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,9 +65,9 @@ jobs: if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_DSN='postgres://postgres@127.0.0.1:${{ job.services.postgres.ports['5432'] }}/postgres'; fi if [[ ${{ matrix.php-version }} == '7.2' ]]; then - vendor/bin/phpunit --filter testSelectLargeNumbers "tests\TestCase\ORM\QueryTest.php" + vendor/bin/phpunit --testsuite=database else - vendor/bin/phpunit --verbose --filter testSelectLargeNumbers "tests\TestCase\ORM\QueryTest.php" + vendor/bin/phpunit --verbose --testsuite=database fi coding-standard: From 5d20e82bc5aa364e95cc8470a8a612a8b9ba17d7 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 11 Jan 2020 22:04:37 -0600 Subject: [PATCH 12/12] Add logging --- src/Database/TypeFactory.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Database/TypeFactory.php b/src/Database/TypeFactory.php index 95eb8c6d87b..f45b03053de 100644 --- a/src/Database/TypeFactory.php +++ b/src/Database/TypeFactory.php @@ -77,6 +77,10 @@ public static function build(string $name): TypeInterface throw new InvalidArgumentException(sprintf('Unknown type "%s"', $name)); } + if ($name === 'decimal' && static::$_types[$name] !== Type\DecimalType::class) { + throw new \RuntimeException('Not set to DecimalType'); + } + /** @var \Cake\Database\TypeInterface */ return static::$_builtTypes[$name] = new static::$_types[$name]($name); }