diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b80185714617..df3b4cbebf3d 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 --testsuite=database else - vendor/bin/phpunit --verbose + vendor/bin/phpunit --verbose --testsuite=database fi coding-standard: diff --git a/src/Database/TypeFactory.php b/src/Database/TypeFactory.php index 95eb8c6d87b4..f45b03053de9 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); } diff --git a/src/ORM/Marshaller.php b/src/ORM/Marshaller.php index 22c8e3763d62..fa34919699db 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) { diff --git a/tests/Fixture/DatatypesFixture.php b/tests/Fixture/DatatypesFixture.php index aa15ab9018c2..bee22a1dbcd3 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 01ba4eb32cea..dd34da31630a 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; @@ -3182,12 +3183,15 @@ 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); + $out = $table->find() ->where([ 'cost' => $big, @@ -3196,19 +3200,34 @@ public function testSelectLargeNumbers() $this->assertNotEmpty($out, 'Should get a record'); $this->assertSame($big, $out->cost); - $small = '0.12345678901234'; + $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 - ' . gettype($extracted['fraction']) . PHP_EOL; + + 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([ 'fraction' => $small, ]) ->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);