-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.1.x model code fix #12674
Merged
Merged
3.1.x model code fix #12674
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Phalcon\Test\Models\Validation; | ||
|
||
use Phalcon\Mvc\Model; | ||
use Phalcon\Mvc\Model\Resultset\Simple; | ||
use Phalcon\Test\Models\RobotsParts; | ||
use Phalcon\Validation; | ||
use Phalcon\Validation\Validator\StringLength; | ||
|
||
/** | ||
* \Phalcon\Test\Models\Validation\Robots | ||
* | ||
* @method static int countByType(string $type) | ||
* @method static Simple findByType(string $type) | ||
* @method static Robots findFirstById(string | int $id) | ||
* | ||
* @copyright 2011-2017 Phalcon Team | ||
* @link https://phalconphp.com | ||
* @author Andres Gutierrez <[email protected]> | ||
* @author Nikolaos Dimopoulos <[email protected]> | ||
* @package Phalcon\Test\Models\Validation | ||
* | ||
* The contents of this file are subject to the New BSD License that is | ||
* bundled with this package in the file docs/LICENSE.txt | ||
* | ||
* If you did not receive a copy of the license and are unable to obtain it | ||
* through the world-wide-web, please send an email to [email protected] | ||
* so that we can send you a copy immediately. | ||
*/ | ||
class Robots extends Model | ||
{ | ||
public function initialize() | ||
{ | ||
$this->hasMany( | ||
'id', | ||
RobotsParts::class, | ||
'robots_id', | ||
[ | ||
'foreignKey' => true, | ||
'reusable' => false, | ||
'alias' => 'parts', | ||
] | ||
); | ||
} | ||
|
||
public function validation() | ||
{ | ||
$validation = new Validation(); | ||
$validation->add( | ||
'name', | ||
new StringLength( | ||
[ | ||
'min' => '7', | ||
'max' => '50', | ||
'code' => 20, | ||
] | ||
) | ||
); | ||
|
||
return $this->validate($validation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace Phalcon\Test\Models; | ||
namespace Phalcon\Test\Models\Validation; | ||
|
||
use Phalcon\Mvc\Model; | ||
use Phalcon\Validation; | ||
|
@@ -14,7 +14,7 @@ | |
use Phalcon\Validation\Validator\StringLength; | ||
|
||
/** | ||
* \Phalcon\Test\Models\Subscriptores | ||
* \Phalcon\Test\Models\Validation\Subscriptores | ||
* | ||
* @property int id | ||
* @property string email | ||
|
@@ -25,7 +25,7 @@ | |
* @link http://www.phalconphp.com | ||
* @author Andres Gutierrez <[email protected]> | ||
* @author Serghei Iakovlev <[email protected]> | ||
* @package Phalcon\Test\Models | ||
* @package Phalcon\Test\Models\Validation | ||
* | ||
* The contents of this file are subject to the New BSD License that is | ||
* bundled with this package in the file docs/LICENSE.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace Phalcon\Test\Unit\Mvc; | ||
|
||
use Helper\ModelTrait; | ||
use Phalcon\Mvc\Model\Message; | ||
use Phalcon\Test\Models\Users; | ||
use Phalcon\Cache\Backend\Apc; | ||
use Phalcon\Test\Models\Robots; | ||
|
@@ -19,6 +20,7 @@ | |
use Phalcon\Test\Models\BodyParts\Body; | ||
use Phalcon\Test\Models\News\Subscribers; | ||
use Phalcon\Test\Models\AlbumORama\Albums; | ||
use Phalcon\Test\Models\Validation; | ||
|
||
/** | ||
* \Phalcon\Test\Unit\Mvc\ModelTest | ||
|
@@ -613,4 +615,35 @@ function () { | |
} | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Tests setting code in message from validation messages | ||
* | ||
* @issue 12645 | ||
* @author Wojciech Ślawski <[email protected]> | ||
* @since 2017-03-03 | ||
*/ | ||
public function testIssue12645() | ||
{ | ||
$this->specify( | ||
"Issue #12645 is not fixed", | ||
function () { | ||
$robots = new Validation\Robots( | ||
[ | ||
'name' => 'asd', | ||
'type' => 'mechanical', | ||
'year' => 2017, | ||
'datetime' => (new \DateTime())->format('Y-m-d'), | ||
'text' => 'asd', | ||
] | ||
); | ||
expect($robots->create())->false(); | ||
/** @var Message $message */ | ||
$message = $robots->getMessages()[0]; | ||
expect($message)->isInstanceOf(Message::class); | ||
expect($message->getCode())->equals(20); | ||
} | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not really sure about this null, it should be
this
here anyway, but this will break tests(not sure about apps).