Log message #4208866

# At Username Text
# Oct 14th 2019, 21:27 daniel.upshaw Your `isUnique` is in there, that's probably right... but would think that goes in validation
# Oct 14th 2019, 21:27 daniel.upshaw Oh hmm
# Oct 14th 2019, 21:26 daniel.upshaw Looks like `buildRules` is for associations?
# Oct 14th 2019, 21:26 daniel.upshaw Hmm
# Oct 14th 2019, 21:26 daniel.upshaw ``` * Default validation rules. * * @param \Cake\Validation\Validator $validator Validator instance. * @return \Cake\Validation\Validator */ public function validationDefault(Validator $validator)```
# Oct 14th 2019, 21:26 daniel.upshaw ``` * Returns a rules checker object that will be used for validating * application integrity. * * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. * @return \Cake\ORM\RulesChecker */ public function buildRules(RulesChecker $rules)```
# Oct 14th 2019, 21:25 tippexs91 Oh... Maybe testValidationDefault? Should I add something here?
# Oct 14th 2019, 21:23 tippexs91 Still passing. https://gist.github.com/tippexs/87f3b127f3022263cc1679325e111c38
# Oct 14th 2019, 21:22 dereuromark assertFalse is cleaner usually if it returns entity or false.
# Oct 14th 2019, 21:20 slackebot1 $this->assertEmpty($this->Invoices->save($entity)); } ```
# Oct 14th 2019, 21:20 tippexs91 ``` public function testIsUniquePaymentId() { $config = TableRegistry::exists('Invoices') ? [] : ['className' => InvoicesTable::class]; $this->Invoices = TableRegistry::get('Invoices', $config); $entity = $this->Invoices->newEntity(['payment_id' => 1]); $this->assertEmpty($this->Invoices->save($entity)); $entity = $this->Invoices->newEntity(['payment_id' => 1]);
# Oct 14th 2019, 21:17 tippexs91 will give it a try
# Oct 14th 2019, 21:17 tippexs91 Hi @dereuromark. Perfect. Sounds great. So create a new Entity with `$this->Invoices->newEntity([])` and try `$this-Invoices->save($entity)`
# Oct 14th 2019, 21:12 dereuromark Yeah, you can test e.g. save() directly in Table tests
# Oct 14th 2019, 21:04 slackebot1 $entity = $invoices->newEntity(['invoicenr' => 'TestInvoice01', 'payment_id' => 1]); $this->assertEmpty($entity->getErrors()); } ``` How to test the isUnique Validation? For me, it feels lightly wrong to test it in the controller? Is it possible to test the validations in the TableTests? Thanks for your help
# Oct 14th 2019, 21:04 tippexs91 hi @here. Any Testing-Specialist arround? I need to test the Validation-Rules. ``` // InvoicesTable public function buildRules(RulesChecker $rules) { $rules->add($rules->existsIn(['payment_id'], 'Payments')); $rules->add($rules->isUnique(['payment_id'])); return $rules; ``` The Controller-Test ``` public function testAdd() { $invoices = TableRegistry::getTableLocator()->get('Invoices');
# Oct 14th 2019, 19:08 daniel.upshaw It's a `select` element on the page
# Oct 14th 2019, 19:01 daniel.upshaw If I add `$this->Form->unlockField('new_field_name');`, it works, but I can't see why it wouldn't treat it like every other field in the table/model
# Oct 14th 2019, 18:59 daniel.upshaw This particular application uses `"cakephp/cakephp": "3.5.*"`, so hopefully that's not why
# Oct 14th 2019, 18:58 daniel.upshaw This is empty, but if I remove the input field that supplies the post data for that column, the form still saves
# Oct 14th 2019, 18:57 daniel.upshaw `<input type="hidden" name="_Token[unlocked]" autocomplete="off" value="">`
# Oct 14th 2019, 18:57 daniel.upshaw `Unexpected field in POST data` after adding a new column :S It's added to the `Entity` as accessible, as well as the validator in the `Table`.. The form is created the standard way of `$this->Form->create($modelName);`
# Oct 14th 2019, 18:34 ndm The plugin installer updates that file when the composer autoloader is dumped. https://github.com/cakephp/app/blob/master/composer.json#L40 It handles both types of plugins, local ones, and ones that are composer dependencies. Bake will trigger the `dump-autoload` command when a plugin is baked.
# Oct 14th 2019, 18:27 dereuromark Then you need to declare it in root composer.json. see my sandbox for examples.
# Oct 14th 2019, 18:25 david mmm, but my plugin is not loaded via composer
# Oct 14th 2019, 18:24 dereuromark composer plugin itself
# Oct 14th 2019, 18:23 david which command has updated my vendor/cakephp-plugins.php ?
# Oct 14th 2019, 18:20 graziel no problem its just probably something silly you will find in time
# Oct 14th 2019, 18:20 ricksaccous now you're baking with cake
# Oct 14th 2019, 18:20 david thank you!
# Oct 14th 2019, 18:20 david I will try that way
# Oct 14th 2019, 18:19 graziel thats why bake is so fun
# Oct 14th 2019, 18:18 david ...
# Oct 14th 2019, 18:18 david if I bake a plugin and then a plugin shell, it works
# Oct 14th 2019, 18:17 david hmmmm
# Oct 14th 2019, 18:15 graziel try to use new installation to bake your plugin
# Oct 14th 2019, 18:13 dereuromark after commit/backup etc
# Oct 14th 2019, 18:13 dereuromark also documented is the -o or sth for overwritig existing files
# Oct 14th 2019, 18:13 david after manually copying bin from a new cakephp installation
# Oct 14th 2019, 18:13 david no changes
# Oct 14th 2019, 18:10 dereuromark I actually do, it is documented as "skeleton task"