Skip to content

Commit

Permalink
Merge 5d20e82 into a5e8c07
Browse files Browse the repository at this point in the history
  • Loading branch information
othercorey committed Jan 12, 2020
2 parents a5e8c07 + 5d20e82 commit 99f979b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions src/Database/TypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions src/ORM/Marshaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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)) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/DatatypesFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
27 changes: 23 additions & 4 deletions tests/TestCase/ORM/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 99f979b

Please sign in to comment.