Skip to content

Commit 861a86d

Browse files
authored
Merge pull request #1144 from sergeysviridenko/3.2.fix_file_name
Fix different model file name
2 parents 12833b9 + cbc46d2 commit 861a86d

File tree

8 files changed

+370
-2
lines changed

8 files changed

+370
-2
lines changed

scripts/Phalcon/Builder/Model.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ public function __construct(array $options)
7777
}
7878

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

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

8787
if (!isset($options['abstract'])) {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
class TestModel extends \Phalcon\Mvc\Model
4+
{
5+
6+
/**
7+
*
8+
* @var integer
9+
* @Primary
10+
* @Identity
11+
* @Column(type="integer", length=10, nullable=false)
12+
*/
13+
public $id;
14+
15+
/**
16+
*
17+
* @var string
18+
* @Column(type="string", length=20, nullable=false)
19+
*/
20+
public $someCol;
21+
22+
/**
23+
*
24+
* @var string
25+
* @Column(type="string", length=20, nullable=false)
26+
*/
27+
public $someCol2;
28+
29+
/**
30+
*
31+
* @var string
32+
* @Column(type="string", length=20, nullable=false)
33+
*/
34+
public $someCol3;
35+
36+
/**
37+
* Initialize method for model.
38+
*/
39+
public function initialize()
40+
{
41+
$this->setSchema("devtools");
42+
$this->setSource("testModel");
43+
}
44+
45+
/**
46+
* Returns table name mapped in the model.
47+
*
48+
* @return string
49+
*/
50+
public function getSource()
51+
{
52+
return 'testModel';
53+
}
54+
55+
/**
56+
* Allows to query a set of records that match the specified conditions
57+
*
58+
* @param mixed $parameters
59+
* @return TestModel[]|TestModel|\Phalcon\Mvc\Model\ResultSetInterface
60+
*/
61+
public static function find($parameters = null)
62+
{
63+
return parent::find($parameters);
64+
}
65+
66+
/**
67+
* Allows to query the first record that match the specified conditions
68+
*
69+
* @param mixed $parameters
70+
* @return TestModel|\Phalcon\Mvc\Model\ResultInterface
71+
*/
72+
public static function findFirst($parameters = null)
73+
{
74+
return parent::findFirst($parameters);
75+
}
76+
77+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
class TestModel2 extends \Phalcon\Mvc\Model
4+
{
5+
6+
/**
7+
*
8+
* @var integer
9+
* @Primary
10+
* @Identity
11+
* @Column(type="integer", length=10, nullable=false)
12+
*/
13+
public $id;
14+
15+
/**
16+
*
17+
* @var string
18+
* @Column(type="string", length=45, nullable=false)
19+
*/
20+
public $name;
21+
22+
/**
23+
* Initialize method for model.
24+
*/
25+
public function initialize()
26+
{
27+
$this->setSchema("devtools");
28+
$this->setSource("test-model2");
29+
}
30+
31+
/**
32+
* Returns table name mapped in the model.
33+
*
34+
* @return string
35+
*/
36+
public function getSource()
37+
{
38+
return 'test-model2';
39+
}
40+
41+
/**
42+
* Allows to query a set of records that match the specified conditions
43+
*
44+
* @param mixed $parameters
45+
* @return TestModel2[]|TestModel2|\Phalcon\Mvc\Model\ResultSetInterface
46+
*/
47+
public static function find($parameters = null)
48+
{
49+
return parent::find($parameters);
50+
}
51+
52+
/**
53+
* Allows to query the first record that match the specified conditions
54+
*
55+
* @param mixed $parameters
56+
* @return TestModel2|\Phalcon\Mvc\Model\ResultInterface
57+
*/
58+
public static function findFirst($parameters = null)
59+
{
60+
return parent::findFirst($parameters);
61+
}
62+
63+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
class TestModel3 extends \Phalcon\Mvc\Model
4+
{
5+
6+
/**
7+
*
8+
* @var integer
9+
* @Primary
10+
* @Identity
11+
* @Column(type="integer", length=10, nullable=false)
12+
*/
13+
public $id;
14+
15+
/**
16+
*
17+
* @var string
18+
* @Column(type="string", length=45, nullable=false)
19+
*/
20+
public $name;
21+
22+
/**
23+
* Initialize method for model.
24+
*/
25+
public function initialize()
26+
{
27+
$this->setSchema("devtools");
28+
$this->setSource("test_model3");
29+
}
30+
31+
/**
32+
* Returns table name mapped in the model.
33+
*
34+
* @return string
35+
*/
36+
public function getSource()
37+
{
38+
return 'test_model3';
39+
}
40+
41+
/**
42+
* Allows to query a set of records that match the specified conditions
43+
*
44+
* @param mixed $parameters
45+
* @return TestModel3[]|TestModel3|\Phalcon\Mvc\Model\ResultSetInterface
46+
*/
47+
public static function find($parameters = null)
48+
{
49+
return parent::find($parameters);
50+
}
51+
52+
/**
53+
* Allows to query the first record that match the specified conditions
54+
*
55+
* @param mixed $parameters
56+
* @return TestModel3|\Phalcon\Mvc\Model\ResultInterface
57+
*/
58+
public static function findFirst($parameters = null)
59+
{
60+
return parent::findFirst($parameters);
61+
}
62+
63+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
class Testmodel4 extends \Phalcon\Mvc\Model
4+
{
5+
6+
/**
7+
*
8+
* @var integer
9+
* @Primary
10+
* @Identity
11+
* @Column(type="integer", length=10, nullable=false)
12+
*/
13+
public $id;
14+
15+
/**
16+
*
17+
* @var string
18+
* @Column(type="string", length=45, nullable=false)
19+
*/
20+
public $name;
21+
22+
/**
23+
* Initialize method for model.
24+
*/
25+
public function initialize()
26+
{
27+
$this->setSchema("devtools");
28+
$this->setSource("Testmodel4");
29+
}
30+
31+
/**
32+
* Returns table name mapped in the model.
33+
*
34+
* @return string
35+
*/
36+
public function getSource()
37+
{
38+
return 'Testmodel4';
39+
}
40+
41+
/**
42+
* Allows to query a set of records that match the specified conditions
43+
*
44+
* @param mixed $parameters
45+
* @return Testmodel4[]|Testmodel4|\Phalcon\Mvc\Model\ResultSetInterface
46+
*/
47+
public static function find($parameters = null)
48+
{
49+
return parent::find($parameters);
50+
}
51+
52+
/**
53+
* Allows to query the first record that match the specified conditions
54+
*
55+
* @param mixed $parameters
56+
* @return Testmodel4|\Phalcon\Mvc\Model\ResultInterface
57+
*/
58+
public static function findFirst($parameters = null)
59+
{
60+
return parent::findFirst($parameters);
61+
}
62+
63+
}

tests/_data/schemas/mysql/dump.sql

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,32 @@ CREATE TABLE `issue595_2` (
6161
`name` varchar(45) NOT NULL,
6262
PRIMARY KEY (`id`)
6363
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
64+
65+
--
66+
-- Table structures for testing generating models
67+
--
68+
CREATE TABLE testModel (
69+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
70+
`some-col` varchar(20) NOT NULL,
71+
`someCol2` varchar(20) NOT NULL,
72+
`SomeCol3` varchar(20) NOT NULL,
73+
PRIMARY KEY (`id`)
74+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
75+
76+
CREATE TABLE `test-model2` (
77+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
78+
`name` varchar(45) NOT NULL,
79+
PRIMARY KEY (`id`)
80+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
81+
82+
CREATE TABLE `test_model3` (
83+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
84+
`name` varchar(45) NOT NULL,
85+
PRIMARY KEY (`id`)
86+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
87+
88+
CREATE TABLE `Testmodel4` (
89+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
90+
`name` varchar(45) NOT NULL,
91+
PRIMARY KEY (`id`)
92+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* @var Codeception\Scenario $scenario
5+
*/
6+
7+
$I = new ConsoleTester($scenario);
8+
9+
$I->wantToTest('Generating models');
10+
$I->amInPath(dirname(app_path()));
11+
mkdir(tests_path('_data/console/app/models/all_model_test'), 0777, true);
12+
13+
$I->runShellCommand('phalcon all-models --config=app/mysql/config.php --output=app/models/all_model_test');
14+
15+
$I->seeFileFound(app_path('models/all_model_test/TestModel.php'));
16+
$I->seeFileFound(app_path('models/all_model_test/TestModel2.php'));
17+
$I->seeFileFound(app_path('models/all_model_test/TestModel3.php'));
18+
$I->seeFileFound(app_path('models/all_model_test/Testmodel4.php'));
19+
20+
$file1 = file_get_contents(app_path('models/files/TestModel.php'));
21+
$file2 = file_get_contents(app_path('models/files/TestModel2.php'));
22+
$file3 = file_get_contents(app_path('models/files/TestModel3.php'));
23+
$file4 = file_get_contents(app_path('models/files/Testmodel4.php'));
24+
25+
$I->openFile(app_path('models/all_model_test/TestModel.php'));
26+
$I->seeFileContentsEqual($file1);
27+
28+
$I->openFile(app_path('models/all_model_test/TestModel2.php'));
29+
$I->seeFileContentsEqual($file2);
30+
31+
$I->openFile(app_path('models/all_model_test/TestModel3.php'));
32+
$I->seeFileContentsEqual($file3);
33+
34+
$I->openFile(app_path('models/all_model_test/Testmodel4.php'));
35+
$I->seeFileContentsEqual($file4);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* @var Codeception\Scenario $scenario
5+
*/
6+
7+
$I = new ConsoleTester($scenario);
8+
9+
$I->wantToTest('Generating models');
10+
$I->amInPath(dirname(app_path()));
11+
mkdir(tests_path('_data/console/app/models/model_test'), 0777, true);
12+
13+
$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=testModel --output=app/models/model_test');
14+
$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test-model2 --output=app/models/model_test');
15+
$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=test_model3 --output=app/models/model_test');
16+
$I->runShellCommand('phalcon model --config=app/mysql/config.php --name=Testmodel4 --output=app/models/model_test');
17+
18+
$I->seeFileFound(app_path('models/model_test/TestModel.php'));
19+
$I->seeFileFound(app_path('models/model_test/TestModel2.php'));
20+
$I->seeFileFound(app_path('models/model_test/TestModel3.php'));
21+
$I->seeFileFound(app_path('models/model_test/Testmodel4.php'));
22+
23+
$file1 = file_get_contents(app_path('models/files/TestModel.php'));
24+
$file2 = file_get_contents(app_path('models/files/TestModel2.php'));
25+
$file3 = file_get_contents(app_path('models/files/TestModel3.php'));
26+
$file4 = file_get_contents(app_path('models/files/Testmodel4.php'));
27+
28+
$I->openFile(app_path('models/model_test/TestModel.php'));
29+
$I->seeFileContentsEqual($file1);
30+
31+
$I->openFile(app_path('models/model_test/TestModel2.php'));
32+
$I->seeFileContentsEqual($file2);
33+
34+
$I->openFile(app_path('models/model_test/TestModel3.php'));
35+
$I->seeFileContentsEqual($file3);
36+
37+
$I->openFile(app_path('models/model_test/Testmodel4.php'));
38+
$I->seeFileContentsEqual($file4);

0 commit comments

Comments
 (0)