Skip to content

Commit

Permalink
convert fixture task to use bake_compare
Browse files Browse the repository at this point in the history
  • Loading branch information
AD7six committed Nov 24, 2014
1 parent bc7381e commit 2535a03
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 17 deletions.
35 changes: 18 additions & 17 deletions tests/TestCase/Shell/Task/FixtureTaskTest.php
Expand Up @@ -99,14 +99,8 @@ public function testImportRecordsFromDatabaseWithConditionsPoo() {

$result = $this->Task->bake('Articles');

$this->assertContains('namespace App\Test\Fixture;', $result);
$this->assertContains('use Cake\TestSuite\Fixture\TestFixture;', $result);
$this->assertContains('class ArticlesFixture extends TestFixture', $result);
$this->assertContains('public $records', $result);
$this->assertContains('public $import', $result);
$this->assertContains("'title' => 'First Article'", $result, 'Missing import data %s');
$this->assertContains('Second Article', $result, 'Missing import data %s');
$this->assertContains('Third Article', $result, 'Missing import data %s');
$expected = file_get_contents(CORE_TESTS . '/bake_compare/test/Fixture/ArticleImportWithConditionsFixture.php');
$this->assertTextEquals($expected, $result);
}

/**
Expand All @@ -118,7 +112,9 @@ public function testImportOptionsAlternateConnection() {
$this->Task->connection = 'test';
$this->Task->params = ['schema' => true];
$result = $this->Task->bake('Article');
$this->assertContains("'connection' => 'test'", $result);

$expected = file_get_contents(CORE_TESTS . '/bake_compare/test/Fixture/ArticleAlternateConnectionFixture.php');
$this->assertTextEquals($expected, $result);
}

/**
Expand All @@ -133,7 +129,9 @@ public function testImportRecordsNoEscaping() {
$this->Task->connection = 'test';
$this->Task->params = ['schema' => 'true', 'records' => true];
$result = $this->Task->bake('Article');
$this->assertContains("'body' => 'Body \"value\"'", $result, 'Data has bad escaping');

$expected = file_get_contents(CORE_TESTS . '/bake_compare/test/Fixture/ArticleNoEscapingFixture.php');
$this->assertTextEquals($expected, $result, 'Data has bad escaping');
}

/**
Expand Down Expand Up @@ -318,7 +316,11 @@ public function testMainImportSchema() {
$this->logicalNot($this->stringContains('public $fields')),
$this->logicalNot($this->stringContains('public $records'))
));
$this->Task->bake('Article', 'comments');

$result = $this->Task->bake('Article', 'comments');

$expected = file_get_contents(CORE_TESTS . '/bake_compare/test/Fixture/ArticleCommentsFixture.php');
$this->assertTextEquals($expected, $result);
}

/**
Expand All @@ -330,14 +332,13 @@ public function testRecordGenerationForBinaryAndFloat() {
$this->Task->connection = 'test';

$result = $this->Task->bake('Article', 'datatypes');
$this->assertContains("'float_field' => 1", $result);
$this->assertContains("'bool' => 1", $result);
$this->assertContains("_constraints", $result);
$this->assertContains("'primary' => ['type' => 'primary'", $result);
$this->assertContains("'columns' => ['id']", $result);

$expected = file_get_contents(CORE_TESTS . '/bake_compare/test/Fixture/ArticleDatatypesFixture.php');
$this->assertTextEquals($expected, $result);

$result = $this->Task->bake('Article', 'binary_tests');
$this->assertContains("'data' => 'Lorem ipsum dolor sit amet'", $result);
$expected = file_get_contents(CORE_TESTS . '/bake_compare/test/Fixture/ArticleBinaryTestFixture.php');
$this->assertTextEquals($expected, $result);
}

/**
Expand Down
@@ -0,0 +1,34 @@
<?php
namespace App\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* ArticleFixture
*
*/
class ArticleFixture extends TestFixture {

/**
* Import
*
* @var array
*/
public $import = ['model' => 'Article', 'connection' => 'test'];

/**
* Records
*
* @var array
*/
public $records = [
[
'id' => 1,
'author_id' => 1,
'title' => 'Lorem ipsum dolor sit amet',
'body' => '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' => 'Lorem ipsum dolor sit ame'
],
];

}
44 changes: 44 additions & 0 deletions tests/bake_compare/test/Fixture/ArticleBinaryTestFixture.php
@@ -0,0 +1,44 @@
<?php
namespace App\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* ArticleFixture
*
*/
class ArticleFixture extends TestFixture {

/**
* Table name
*
* @var string
*/
public $table = 'binary_tests';

/**
* Fields
*
* @var array
*/
public $fields = [
'id' => ['type' => 'integer', 'length' => null, 'unsigned' => false, 'null' => false, 'default' => null, 'autoIncrement' => true, 'precision' => null, 'comment' => null],
'data' => ['type' => 'binary', 'length' => null, 'null' => true, 'default' => null, 'precision' => null, 'comment' => null],
'_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
],
];

/**
* Records
*
* @var array
*/
public $records = [
[
'id' => 1,
'data' => 'Lorem ipsum dolor sit amet'
],
];

}
26 changes: 26 additions & 0 deletions tests/bake_compare/test/Fixture/ArticleCommentsFixture.php
@@ -0,0 +1,26 @@
<?php
namespace App\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* ArticleFixture
*
*/
class ArticleFixture extends TestFixture {

/**
* Table name
*
* @var string
*/
public $table = 'comments';

/**
* Import
*
* @var array
*/
public $import = ['model' => 'Article', 'records' => true, 'connection' => 'test'];

}
50 changes: 50 additions & 0 deletions tests/bake_compare/test/Fixture/ArticleDatatypesFixture.php
@@ -0,0 +1,50 @@
<?php
namespace App\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* ArticleFixture
*
*/
class ArticleFixture extends TestFixture {

/**
* Table name
*
* @var string
*/
public $table = 'datatypes';

/**
* Fields
*
* @var array
*/
public $fields = [
'id' => ['type' => 'integer', 'length' => null, 'unsigned' => false, 'null' => false, 'default' => null, 'autoIncrement' => true, 'precision' => null, 'comment' => null],
'decimal_field' => ['type' => 'decimal', 'length' => null, 'unsigned' => false, 'null' => true, 'default' => '0.000', 'precision' => null, 'comment' => null],
'float_field' => ['type' => 'float', 'length' => null, 'unsigned' => false, 'null' => false, 'default' => null, 'precision' => null, 'comment' => null],
'huge_int' => ['type' => 'biginteger', 'length' => null, 'unsigned' => false, 'null' => true, 'default' => null, 'precision' => null, 'comment' => null, 'autoIncrement' => null],
'bool' => ['type' => 'boolean', 'length' => null, 'null' => false, 'default' => 'FALSE', 'precision' => null, 'comment' => null],
'_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
],
];

/**
* Records
*
* @var array
*/
public $records = [
[
'id' => 1,
'decimal_field' => '',
'float_field' => 1,
'huge_int' => '',
'bool' => 1
],
];

}
@@ -0,0 +1,48 @@
<?php
namespace App\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* ArticlesFixture
*
*/
class ArticlesFixture extends TestFixture {

/**
* Import
*
* @var array
*/
public $import = ['model' => 'Articles', 'connection' => 'test'];

/**
* Records
*
* @var array
*/
public $records = [
[
'id' => 1,
'author_id' => 1,
'title' => 'First Article',
'body' => 'First Article Body',
'published' => 'Y'
],
[
'id' => 2,
'author_id' => 3,
'title' => 'Second Article',
'body' => 'Second Article Body',
'published' => 'Y'
],
[
'id' => 3,
'author_id' => 1,
'title' => 'Third Article',
'body' => 'Third Article Body',
'published' => 'Y'
],
];

}
48 changes: 48 additions & 0 deletions tests/bake_compare/test/Fixture/ArticleNoEscapingFixture.php
@@ -0,0 +1,48 @@
<?php
namespace App\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* ArticleFixture
*
*/
class ArticleFixture extends TestFixture {

/**
* Import
*
* @var array
*/
public $import = ['model' => 'Article', 'connection' => 'test'];

/**
* Records
*
* @var array
*/
public $records = [
[
'id' => 1,
'author_id' => 1,
'title' => 'First Article',
'body' => 'Body "value"',
'published' => 'Y'
],
[
'id' => 2,
'author_id' => 3,
'title' => 'Second Article',
'body' => 'Body "value"',
'published' => 'Y'
],
[
'id' => 3,
'author_id' => 1,
'title' => 'Third Article',
'body' => 'Body "value"',
'published' => 'Y'
],
];

}

0 comments on commit 2535a03

Please sign in to comment.