Skip to content

Commit

Permalink
Merge pull request #461 from dmromanov/bugfix/short-dummy-text-gen
Browse files Browse the repository at this point in the history
Fixed dummy text generation for short text fields
  • Loading branch information
markstory authored Nov 4, 2018
2 parents 7356656 + b2cd43e commit d4b1a92
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Shell/Task/FixtureTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/Fixture/BinaryTestsFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']]]
];
Expand Down
23 changes: 23 additions & 0 deletions tests/TestCase/Shell/Task/FixtureTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit d4b1a92

Please sign in to comment.