Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/Phalcon/Builder/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public function __construct(array $options)
}

if (!isset($options['className'])) {
$options['className'] = Text::camelize($options['name'], '_-');
$options['className'] = Utils::lowerCamelizeWithDelimiter($options['name'], '_-');
}

if (!isset($options['fileName'])) {
$options['fileName'] = Text::camelize($options['name'], '_-');
$options['fileName'] = Utils::lowerCamelizeWithDelimiter($options['name'], '_-');
}

if (!isset($options['abstract'])) {
Expand Down
77 changes: 77 additions & 0 deletions tests/_data/console/app/models/files/TestModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

class TestModel extends \Phalcon\Mvc\Model
{

/**
*
* @var integer
* @Primary
* @Identity
* @Column(type="integer", length=10, nullable=false)
*/
public $id;

/**
*
* @var string
* @Column(type="string", length=20, nullable=false)
*/
public $someCol;

/**
*
* @var string
* @Column(type="string", length=20, nullable=false)
*/
public $someCol2;

/**
*
* @var string
* @Column(type="string", length=20, nullable=false)
*/
public $someCol3;

/**
* Initialize method for model.
*/
public function initialize()
{
$this->setSchema("devtools");
$this->setSource("testModel");
}

/**
* Returns table name mapped in the model.
*
* @return string
*/
public function getSource()
{
return 'testModel';
}

/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return TestModel[]|TestModel|\Phalcon\Mvc\Model\ResultSetInterface
*/
public static function find($parameters = null)
{
return parent::find($parameters);
}

/**
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return TestModel|\Phalcon\Mvc\Model\ResultInterface
*/
public static function findFirst($parameters = null)
{
return parent::findFirst($parameters);
}

}
63 changes: 63 additions & 0 deletions tests/_data/console/app/models/files/TestModel2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

class TestModel2 extends \Phalcon\Mvc\Model
{

/**
*
* @var integer
* @Primary
* @Identity
* @Column(type="integer", length=10, nullable=false)
*/
public $id;

/**
*
* @var string
* @Column(type="string", length=45, nullable=false)
*/
public $name;

/**
* Initialize method for model.
*/
public function initialize()
{
$this->setSchema("devtools");
$this->setSource("test-model2");
}

/**
* Returns table name mapped in the model.
*
* @return string
*/
public function getSource()
{
return 'test-model2';
}

/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return TestModel2[]|TestModel2|\Phalcon\Mvc\Model\ResultSetInterface
*/
public static function find($parameters = null)
{
return parent::find($parameters);
}

/**
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return TestModel2|\Phalcon\Mvc\Model\ResultInterface
*/
public static function findFirst($parameters = null)
{
return parent::findFirst($parameters);
}

}
63 changes: 63 additions & 0 deletions tests/_data/console/app/models/files/TestModel3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

class TestModel3 extends \Phalcon\Mvc\Model
{

/**
*
* @var integer
* @Primary
* @Identity
* @Column(type="integer", length=10, nullable=false)
*/
public $id;

/**
*
* @var string
* @Column(type="string", length=45, nullable=false)
*/
public $name;

/**
* Initialize method for model.
*/
public function initialize()
{
$this->setSchema("devtools");
$this->setSource("test_model3");
}

/**
* Returns table name mapped in the model.
*
* @return string
*/
public function getSource()
{
return 'test_model3';
}

/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return TestModel3[]|TestModel3|\Phalcon\Mvc\Model\ResultSetInterface
*/
public static function find($parameters = null)
{
return parent::find($parameters);
}

/**
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return TestModel3|\Phalcon\Mvc\Model\ResultInterface
*/
public static function findFirst($parameters = null)
{
return parent::findFirst($parameters);
}

}
63 changes: 63 additions & 0 deletions tests/_data/console/app/models/files/Testmodel4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

class Testmodel4 extends \Phalcon\Mvc\Model
{

/**
*
* @var integer
* @Primary
* @Identity
* @Column(type="integer", length=10, nullable=false)
*/
public $id;

/**
*
* @var string
* @Column(type="string", length=45, nullable=false)
*/
public $name;

/**
* Initialize method for model.
*/
public function initialize()
{
$this->setSchema("devtools");
$this->setSource("Testmodel4");
}

/**
* Returns table name mapped in the model.
*
* @return string
*/
public function getSource()
{
return 'Testmodel4';
}

/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return Testmodel4[]|Testmodel4|\Phalcon\Mvc\Model\ResultSetInterface
*/
public static function find($parameters = null)
{
return parent::find($parameters);
}

/**
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return Testmodel4|\Phalcon\Mvc\Model\ResultInterface
*/
public static function findFirst($parameters = null)
{
return parent::findFirst($parameters);
}

}
29 changes: 29 additions & 0 deletions tests/_data/schemas/mysql/dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,32 @@ CREATE TABLE `issue595_2` (
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structures for testing generating models
--
CREATE TABLE testModel (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`some-col` varchar(20) NOT NULL,
`someCol2` varchar(20) NOT NULL,
`SomeCol3` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `test-model2` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `test_model3` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `Testmodel4` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
35 changes: 35 additions & 0 deletions tests/console/GenerateMultyModelsCept.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* @var Codeception\Scenario $scenario
*/

$I = new ConsoleTester($scenario);

$I->wantToTest('Generating models');
$I->amInPath(dirname(app_path()));
mkdir(tests_path('_data/console/app/models/all_model_test'), 0777, true);

$I->runShellCommand('phalcon all-models --config=app/mysql/config.php --output=app/models/all_model_test');

$I->seeFileFound(app_path('models/all_model_test/TestModel.php'));
$I->seeFileFound(app_path('models/all_model_test/TestModel2.php'));
$I->seeFileFound(app_path('models/all_model_test/TestModel3.php'));
$I->seeFileFound(app_path('models/all_model_test/Testmodel4.php'));

$file1 = file_get_contents(app_path('models/files/TestModel.php'));
$file2 = file_get_contents(app_path('models/files/TestModel2.php'));
$file3 = file_get_contents(app_path('models/files/TestModel3.php'));
$file4 = file_get_contents(app_path('models/files/Testmodel4.php'));

$I->openFile(app_path('models/all_model_test/TestModel.php'));
$I->seeFileContentsEqual($file1);

$I->openFile(app_path('models/all_model_test/TestModel2.php'));
$I->seeFileContentsEqual($file2);

$I->openFile(app_path('models/all_model_test/TestModel3.php'));
$I->seeFileContentsEqual($file3);

$I->openFile(app_path('models/all_model_test/Testmodel4.php'));
$I->seeFileContentsEqual($file4);
38 changes: 38 additions & 0 deletions tests/console/GenerateSingleModelCept.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* @var Codeception\Scenario $scenario
*/

$I = new ConsoleTester($scenario);

$I->wantToTest('Generating models');
$I->amInPath(dirname(app_path()));
mkdir(tests_path('_data/console/app/models/model_test'), 0777, true);

$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=testModel --output=app/models/model_test');
$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test-model2 --output=app/models/model_test');
$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test_model3 --output=app/models/model_test');
$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=Testmodel4 --output=app/models/model_test');

$I->seeFileFound(app_path('models/model_test/TestModel.php'));
$I->seeFileFound(app_path('models/model_test/TestModel2.php'));
$I->seeFileFound(app_path('models/model_test/TestModel3.php'));
$I->seeFileFound(app_path('models/model_test/Testmodel4.php'));

$file1 = file_get_contents(app_path('models/files/TestModel.php'));
$file2 = file_get_contents(app_path('models/files/TestModel2.php'));
$file3 = file_get_contents(app_path('models/files/TestModel3.php'));
$file4 = file_get_contents(app_path('models/files/Testmodel4.php'));

$I->openFile(app_path('models/model_test/TestModel.php'));
$I->seeFileContentsEqual($file1);

$I->openFile(app_path('models/model_test/TestModel2.php'));
$I->seeFileContentsEqual($file2);

$I->openFile(app_path('models/model_test/TestModel3.php'));
$I->seeFileContentsEqual($file3);

$I->openFile(app_path('models/model_test/Testmodel4.php'));
$I->seeFileContentsEqual($file4);