Skip to content
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 1 commit into from
Mar 8, 2017
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Fixed `Phalcon\Session\Bag::remove` to initialize the bag before removing a value [#12647](https://github.com/phalcon/cphalcon/pull/12647)
- Fixed `Phalcon\Mvc\Model::getChangedFields` to correct detect changes from NULL to Zero [#12628](https://github.com/phalcon/cphalcon/issues/12628)
- Fixed `Phalcon\Mvc\Model` to create/refresh snapshot after create/update/refresh operation [#11007](https://github.com/phalcon/cphalcon/issues/11007), [#11818](https://github.com/phalcon/cphalcon/issues/11818), [#11424](https://github.com/phalcon/cphalcon/issues/11424)
- Fixed `Phalcon\Mvc\Model::validate` to correctly set code message [#12645](https://github.com/phalcon/cphalcon/issues/12645)

# [3.0.4](https://github.com/phalcon/cphalcon/releases/tag/v3.0.4) (2017-02-20)
- Fixed Isnull check is not correct when the model field defaults to an empty string. [#12507](https://github.com/phalcon/cphalcon/issues/12507)
Expand Down
4 changes: 3 additions & 1 deletion phalcon/mvc/model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,9 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
new Message(
message->getMessage(),
message->getField(),
message->getType()
message->getType(),
null,
Copy link
Contributor Author

@Jurigag Jurigag Mar 3, 2017

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).

message->getCode()
)
);
}
Expand Down
63 changes: 63 additions & 0 deletions tests/_data/models/Validation/Robots.php
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);
}
}
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;
Expand All @@ -14,7 +14,7 @@
use Phalcon\Validation\Validator\StringLength;

/**
* \Phalcon\Test\Models\Subscriptores
* \Phalcon\Test\Models\Validation\Subscriptores
*
* @property int id
* @property string email
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Mvc/Model/Helpers/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use UnitTester;
use Phalcon\Db\RawValue;
use Phalcon\Mvc\Model\Message;
use Phalcon\Test\Models\Subscriptores;
use Phalcon\Test\Models\Validation\Subscriptores;

class Validation
{
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/Mvc/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
);
}
}