Skip to content

Commit

Permalink
Fix ModelCommandTest::testBakeEntityWithPlugin()
Browse files Browse the repository at this point in the history
  • Loading branch information
ajibarra committed Jul 15, 2022
1 parent 9b923fe commit dc59fbc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 58 deletions.
4 changes: 2 additions & 2 deletions tests/TestCase/Command/ModelCommandTest.php
Expand Up @@ -1765,9 +1765,9 @@ public function testBakeEntityWithPlugin()
$this->_loadTestPlugin('BakeTest');
$path = Plugin::path('BakeTest');

$this->generatedFile = $path . 'src/Model/Table/UsersTable.php';
$this->generatedFile = $path . 'src/Model/Entity/User.php';

$this->exec('bake model --no-validation --no-test --no-fixture --no-entity -p BakeTest Users');
$this->exec('bake model --no-validation --no-test --no-fixture --no-table BakeTest.Users');

$this->assertExitCode(CommandInterface::CODE_SUCCESS);
$this->assertFileExists($this->generatedFile);
Expand Down
86 changes: 30 additions & 56 deletions tests/comparisons/Model/testBakeEntityWithPlugin.php
@@ -1,74 +1,48 @@
<?php
declare(strict_types=1);

namespace BakeTest\Model\Table;
namespace BakeTest\Model\Entity;

use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Cake\ORM\Entity;

/**
* Users Model
* User Entity
*
* @property \BakeTest\Model\Table\CommentsTable&\Cake\ORM\Association\HasMany $Comments
* @property \BakeTest\Model\Table\TodoItemsTable&\Cake\ORM\Association\HasMany $TodoItems
* @property int $id
* @property string|null $username
* @property string|null $password
* @property \Cake\I18n\FrozenTime|null $created
* @property \Cake\I18n\FrozenTime|null $updated
*
* @method \BakeTest\Model\Entity\User newEmptyEntity()
* @method \BakeTest\Model\Entity\User newEntity(array $data, array $options = [])
* @method \BakeTest\Model\Entity\User[] newEntities(array $data, array $options = [])
* @method \BakeTest\Model\Entity\User get($primaryKey, $options = [])
* @method \BakeTest\Model\Entity\User findOrCreate($search, ?callable $callback = null, $options = [])
* @method \BakeTest\Model\Entity\User patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
* @method \BakeTest\Model\Entity\User[] patchEntities(iterable $entities, array $data, array $options = [])
* @method \BakeTest\Model\Entity\User|false save(\Cake\Datasource\EntityInterface $entity, $options = [])
* @method \BakeTest\Model\Entity\User saveOrFail(\Cake\Datasource\EntityInterface $entity, $options = [])
* @method \BakeTest\Model\Entity\User[]|\Cake\Datasource\ResultSetInterface|false saveMany(iterable $entities, $options = [])
* @method \BakeTest\Model\Entity\User[]|\Cake\Datasource\ResultSetInterface saveManyOrFail(iterable $entities, $options = [])
* @method \BakeTest\Model\Entity\User[]|\Cake\Datasource\ResultSetInterface|false deleteMany(iterable $entities, $options = [])
* @method \BakeTest\Model\Entity\User[]|\Cake\Datasource\ResultSetInterface deleteManyOrFail(iterable $entities, $options = [])
*
* @mixin \Cake\ORM\Behavior\TimestampBehavior
* @property \BakeTest\Model\Entity\Comment[] $comments
* @property \BakeTest\Model\Entity\TodoItem[] $todo_items
*/
class UsersTable extends Table
class User extends Entity
{
/**
* Initialize method
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* Note that when '*' is set to true, this allows all unspecified fields to
* be mass assigned. For security purposes, it is advised to set '*' to false
* (or remove it), and explicitly make individual fields accessible as needed.
*
* @param array $config The configuration for the Table.
* @return void
* @var array<string, bool>
*/
public function initialize(array $config): void
{
parent::initialize($config);

$this->setTable('users');
$this->setDisplayField('id');
$this->setPrimaryKey('id');

$this->addBehavior('Timestamp');

$this->hasMany('Comments', [
'foreignKey' => 'user_id',
'className' => 'BakeTest.Comments',
]);
$this->hasMany('TodoItems', [
'foreignKey' => 'user_id',
'className' => 'BakeTest.TodoItems',
]);
}
protected $_accessible = [
'username' => true,
'password' => true,
'created' => true,
'updated' => true,
'comments' => true,
'todo_items' => true,
];

/**
* Returns a rules checker object that will be used for validating
* application integrity.
* Fields that are excluded from JSON versions of the entity.
*
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
* @var array<string>
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['username']), ['errorField' => 'username']);

return $rules;
}
protected $_hidden = [
'password',
];
}

0 comments on commit dc59fbc

Please sign in to comment.