From b2cd43ea2a20da7298e4bda647759895056e7473 Mon Sep 17 00:00:00 2001 From: Dmitrii Romanov Date: Thu, 30 Aug 2018 14:35:01 +0300 Subject: [PATCH] Fixed dummy text generation for short text fields --- composer.json | 2 +- src/Shell/Task/FixtureTask.php | 2 +- tests/Fixture/BinaryTestsFixture.php | 1 + tests/TestCase/Shell/Task/FixtureTaskTest.php | 23 +++++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 05ef8a9f5..558907ac2 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ }, "require": { "php": ">=5.6.0", - "cakephp/cakephp": "^3.6.0", + "cakephp/cakephp": "^3.6.12", "cakephp/plugin-installer": "^1.0", "wyrihaximus/twig-view": "^4.3.4" }, diff --git a/src/Shell/Task/FixtureTask.php b/src/Shell/Task/FixtureTask.php index 492e44bc4..a142f4119 100644 --- a/src/Shell/Task/FixtureTask.php +++ b/src/Shell/Task/FixtureTask.php @@ -366,7 +366,7 @@ protected function _generateRecords(TableSchema $table, $recordCount = 1) } else { $insert = "Lorem ipsum dolor sit amet"; if (!empty($fieldInfo['length'])) { - $insert = substr($insert, 0, (int)$fieldInfo['length'] - 2); + $insert = substr($insert, 0, (int)$fieldInfo['length'] > 2 ? (int)$fieldInfo['length'] - 2 : (int)$fieldInfo['length']); } } break; diff --git a/tests/Fixture/BinaryTestsFixture.php b/tests/Fixture/BinaryTestsFixture.php index f0ead760b..aa02bef44 100644 --- a/tests/Fixture/BinaryTestsFixture.php +++ b/tests/Fixture/BinaryTestsFixture.php @@ -29,6 +29,7 @@ class BinaryTestsFixture extends TestFixture */ public $fields = [ 'id' => ['type' => 'integer'], + 'byte' => ['type' => 'binary', 'length' => 1], 'data' => ['type' => 'binary', 'length' => 300], '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]] ]; diff --git a/tests/TestCase/Shell/Task/FixtureTaskTest.php b/tests/TestCase/Shell/Task/FixtureTaskTest.php index 038abd3a3..104ce1cf1 100644 --- a/tests/TestCase/Shell/Task/FixtureTaskTest.php +++ b/tests/TestCase/Shell/Task/FixtureTaskTest.php @@ -18,6 +18,8 @@ use Bake\Test\TestCase\TestCase; use Cake\Console\Shell; use Cake\Core\Plugin; +use Cake\Database\Driver\Postgres; +use Cake\Datasource\ConnectionManager; use Cake\ORM\TableRegistry; /** @@ -360,10 +362,31 @@ public function testRecordGenerationForDatatypes() */ public function testRecordGenerationForBinaryType() { + $driver = ConnectionManager::get('test')->getDriver(); + $this->skipIf($driver instanceof Postgres, 'Incompatible with postgres'); + + $this->generatedFile = ROOT . 'tests/Fixture/BinaryTestsFixture.php'; + $this->exec('bake fixture --connection test BinaryTests'); + + $this->assertFileContains("'data' => 'Lorem ipsum dolor sit amet'", $this->generatedFile); + $this->assertFileContains("'byte' => 'L'", $this->generatedFile); + } + + /** + * test record generation with float and binary types + * + * @return void + */ + public function testRecordGenerationForBinaryTypePostgres() + { + $driver = ConnectionManager::get('test')->getDriver(); + $this->skipIf(($driver instanceof Postgres) === false, 'Only compatible with postgres'); + $this->generatedFile = ROOT . 'tests/Fixture/BinaryTestsFixture.php'; $this->exec('bake fixture --connection test BinaryTests'); $this->assertFileContains("'data' => 'Lorem ipsum dolor sit amet'", $this->generatedFile); + $this->assertFileContains("'byte' => 'Lorem ipsum dolor sit amet'", $this->generatedFile); } /**