Skip to content

Commit

Permalink
Merge pull request phalcon#1145 from phalcon/3.2.x
Browse files Browse the repository at this point in the history
v3.2.11
  • Loading branch information
sergeyklay authored Nov 9, 2017
2 parents e57276b + 38a6b61 commit 18e352c
Show file tree
Hide file tree
Showing 11 changed files with 374 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
2 changes: 1 addition & 1 deletion scripts/Phalcon/Devtools/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ class Version extends PhVersion
*/
protected static function _getVersion()
{
return [3, 2, 10, 4, 0];
return [3, 2, 11, 4, 0];
}
}
4 changes: 2 additions & 2 deletions scripts/Phalcon/Mvc/Model/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
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);
Loading

0 comments on commit 18e352c

Please sign in to comment.