diff --git a/README.md b/README.md index 00a081135..27e39bbcc 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ This command should display something similar to: ```sh $ phalcon --help -Phalcon DevTools (3.2.10) +Phalcon DevTools (3.2.11) Help: Lists the commands available in Phalcon devtools diff --git a/scripts/Phalcon/Builder/Model.php b/scripts/Phalcon/Builder/Model.php index 26db0c66f..321c3bb47 100644 --- a/scripts/Phalcon/Builder/Model.php +++ b/scripts/Phalcon/Builder/Model.php @@ -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'])) { diff --git a/scripts/Phalcon/Devtools/Version.php b/scripts/Phalcon/Devtools/Version.php index 6f038b325..0a1e3989c 100644 --- a/scripts/Phalcon/Devtools/Version.php +++ b/scripts/Phalcon/Devtools/Version.php @@ -39,6 +39,6 @@ class Version extends PhVersion */ protected static function _getVersion() { - return [3, 2, 10, 4, 0]; + return [3, 2, 11, 4, 0]; } } diff --git a/scripts/Phalcon/Mvc/Model/Migration.php b/scripts/Phalcon/Mvc/Model/Migration.php index 2c8f90dd1..e79ac181e 100644 --- a/scripts/Phalcon/Mvc/Model/Migration.php +++ b/scripts/Phalcon/Mvc/Model/Migration.php @@ -862,7 +862,7 @@ public function batchInsert($tableName, $fields) while (($line = fgetcsv($batchHandler)) !== false) { $values = array_map( function ($value) { - return null === $value ? null : $value; + return null === $value ? null : stripslashes($value); }, $line ); @@ -893,7 +893,7 @@ public function batchDelete($tableName) while (($line = fgetcsv($batchHandler)) !== false) { $values = array_map( function ($value) { - return null === $value ? null : $value; + return null === $value ? null : stripslashes($value); }, $line ); diff --git a/tests/_data/console/app/models/files/TestModel.php b/tests/_data/console/app/models/files/TestModel.php new file mode 100644 index 000000000..a2e08f5ed --- /dev/null +++ b/tests/_data/console/app/models/files/TestModel.php @@ -0,0 +1,77 @@ +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); + } + +} diff --git a/tests/_data/console/app/models/files/TestModel2.php b/tests/_data/console/app/models/files/TestModel2.php new file mode 100644 index 000000000..af1abb0ff --- /dev/null +++ b/tests/_data/console/app/models/files/TestModel2.php @@ -0,0 +1,63 @@ +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); + } + +} diff --git a/tests/_data/console/app/models/files/TestModel3.php b/tests/_data/console/app/models/files/TestModel3.php new file mode 100644 index 000000000..f189513ce --- /dev/null +++ b/tests/_data/console/app/models/files/TestModel3.php @@ -0,0 +1,63 @@ +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); + } + +} diff --git a/tests/_data/console/app/models/files/Testmodel4.php b/tests/_data/console/app/models/files/Testmodel4.php new file mode 100644 index 000000000..c88e9e64e --- /dev/null +++ b/tests/_data/console/app/models/files/Testmodel4.php @@ -0,0 +1,63 @@ +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); + } + +} diff --git a/tests/_data/schemas/mysql/dump.sql b/tests/_data/schemas/mysql/dump.sql index 10aa3c96d..ea12c2c72 100644 --- a/tests/_data/schemas/mysql/dump.sql +++ b/tests/_data/schemas/mysql/dump.sql @@ -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; diff --git a/tests/console/GenerateMultyModelsCept.php b/tests/console/GenerateMultyModelsCept.php new file mode 100644 index 000000000..1cd6c05bb --- /dev/null +++ b/tests/console/GenerateMultyModelsCept.php @@ -0,0 +1,35 @@ +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); diff --git a/tests/console/GenerateSingleModelCept.php b/tests/console/GenerateSingleModelCept.php new file mode 100644 index 000000000..e6db07e8d --- /dev/null +++ b/tests/console/GenerateSingleModelCept.php @@ -0,0 +1,38 @@ +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);