Skip to content

Commit

Permalink
Merge branch 'issue/500-decimal-no-precision' of github.com:CakeDC/ca…
Browse files Browse the repository at this point in the history
…kephp-migrations into issue/500-decimal-no-precision
  • Loading branch information
ajibarra committed Sep 23, 2022
2 parents e7d7f1b + b8dd776 commit 2c2cd1f
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 10 deletions.
27 changes: 23 additions & 4 deletions src/Command/BakeMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,29 @@ public function getOptionParser(): ConsoleOptionParser
* The types are the abstract database column types in CakePHP.
* The <warning>?</warning> value indicates if a column is nullable.
e.x. `role:string?`.
* Length option must be enclosed in `[]` e.x. `name:string[100]`
* The `index` attribute can define the column as having a unique
key with `unique` or a primary key with `primary`.
e.x. <warning>role:string?</warning>.
* Length option must be enclosed in <warning>[]</warning>, for example: <warning>name:string[100]</warning>.
* The <warning>index</warning> attribute can define the column as having a unique
key with <warning>unique</warning> or a primary key with <warning>primary</warning>.
<info>Examples</info>
<warning>bin/cake bake migration AddOrgIdToProjects org_id:int</warning>
Create a migration that adds a column (<warning>org_id INT</warning>) to the <warning>projects</warning>
table.
<warning>bin/cake bake migration AddOrgIdToProjects org_id:int?</warning>
Create a migration that adds a nullable column (<warning>org_id INT NULL</warning>) to the <warning>projects</warning>
table.
<warning>bin/cake bake migration AddNameToProjects name:string[128]</warning>
Create a migration that adds (<warning>name VARCHAR(128)</warning>) to the <warning>projects</warning>
table.
<warning>bin/cake bake migration AddSlugToProjects name:string[128]:unique</warning>
Create a migration that adds (<warning>name VARCHAR(128)</warning> and a <warning>UNIQUE<.warning index)
to the <warning>projects</warning> table.

TEXT;

$parser->setDescription($text);
Expand Down
3 changes: 2 additions & 1 deletion src/Command/BakeSeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public function templateData(Arguments $arguments): array
}

/** @var array $records */
$records = $query->toArray();
$records = $query->disableResultsCasting()->toArray();

$records = $this->prettifyArray($records);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Command/BakeSeedCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public function testWithData()
$path = __FUNCTION__ . '.php';
if (getenv('DB') === 'pgsql') {
$path = getenv('DB') . DS . $path;
} elseif (PHP_VERSION_ID >= 80100) {
$path = 'php81' . DS . $path;
}

$this->assertExitCode(BaseCommand::CODE_SUCCESS);
Expand Down Expand Up @@ -115,6 +117,8 @@ public function testWithDataAndLimit()
$path = __FUNCTION__ . '.php';
if (getenv('DB') === 'pgsql') {
$path = getenv('DB') . DS . $path;
} elseif (PHP_VERSION_ID >= 80100) {
$path = 'php81' . DS . $path;
}

$this->assertExitCode(BaseCommand::CODE_SUCCESS);
Expand Down
51 changes: 51 additions & 0 deletions tests/comparisons/Seeds/php81/testWithData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);

use Migrations\AbstractSeed;

/**
* Events seed.
*/
class EventsSeed extends AbstractSeed
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeds is available here:
* https://book.cakephp.org/phinx/0/en/seeding.html
*
* @return void
*/
public function run()
{
$data = [
[
'id' => 1,
'title' => 'Lorem ipsum dolor sit amet',
'description' => 'Lorem ipsum dolor sit amet, aliquet feugiat.',
'published' => 'Y',
],
[
'id' => 2,
'title' => 'Second event',
'description' => 'Second event description.',
'published' => 'Y',
],
[
'id' => 3,
'title' => 'Lorem ipsum dolor sit amet',
'description' => 'Lorem ipsum dolor sit amet, aliquet feugiat.
Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget \'sollicitudin\' venenatis cum
nullam, vivamus ut a sed, mollitia lectus.
Nulla vestibulum massa neque ut et, id hendrerit sit, feugiat in taciti enim proin nibh, tempor dignissim, rhoncus
duis vestibulum nunc mattis convallis.',
'published' => 'Y',
],
];

$table = $this->table('events');
$table->insert($data)->save();
}
}
41 changes: 41 additions & 0 deletions tests/comparisons/Seeds/php81/testWithDataAndLimit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);

use Migrations\AbstractSeed;

/**
* Events seed.
*/
class EventsSeed extends AbstractSeed
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeds is available here:
* https://book.cakephp.org/phinx/0/en/seeding.html
*
* @return void
*/
public function run()
{
$data = [
[
'id' => 1,
'title' => 'Lorem ipsum dolor sit amet',
'description' => 'Lorem ipsum dolor sit amet, aliquet feugiat.',
'published' => 'Y',
],
[
'id' => 2,
'title' => 'Second event',
'description' => 'Second event description.',
'published' => 'Y',
],
];

$table = $this->table('events');
$table->insert($data)->save();
}
}
6 changes: 3 additions & 3 deletions tests/comparisons/Seeds/testWithData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public function run()
{
$data = [
[
'id' => 1,
'id' => '1',
'title' => 'Lorem ipsum dolor sit amet',
'description' => 'Lorem ipsum dolor sit amet, aliquet feugiat.',
'published' => 'Y',
],
[
'id' => 2,
'id' => '2',
'title' => 'Second event',
'description' => 'Second event description.',
'published' => 'Y',
],
[
'id' => 3,
'id' => '3',
'title' => 'Lorem ipsum dolor sit amet',
'description' => 'Lorem ipsum dolor sit amet, aliquet feugiat.
Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget \'sollicitudin\' venenatis cum
Expand Down
4 changes: 2 additions & 2 deletions tests/comparisons/Seeds/testWithDataAndLimit.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public function run()
{
$data = [
[
'id' => 1,
'id' => '1',
'title' => 'Lorem ipsum dolor sit amet',
'description' => 'Lorem ipsum dolor sit amet, aliquet feugiat.',
'published' => 'Y',
],
[
'id' => 2,
'id' => '2',
'title' => 'Second event',
'description' => 'Second event description.',
'published' => 'Y',
Expand Down

0 comments on commit 2c2cd1f

Please sign in to comment.