-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fixed a bug with string setters being executed as callables #35
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
namespace Duplicatable\Test\TestCase\Model\Behavior; | ||
|
||
use Cake\Datasource\EntityInterface; | ||
use Cake\ORM\TableRegistry; | ||
use Cake\TestSuite\TestCase; | ||
|
||
|
@@ -180,4 +181,25 @@ public function testWithTranslation() | |
->all(); | ||
$this->assertEquals(2, $records->count()); | ||
} | ||
|
||
public function testDuplicateWithSetters() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new test passes even without the change you have done to the behavior, so it's not really useful 🙂. In general when fixing a bug write a failing test first and then fix the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 I'll have to revise this test. |
||
{ | ||
$this->Invoices->removeBehavior('Duplicatable'); | ||
$this->Invoices->addBehavior('Duplicatable.Duplicatable', [ | ||
'set' => [ | ||
'copied' => true, | ||
'name' => 'mail', | ||
'contact_name' => function (EntityInterface $entity) { | ||
return strrev($entity->get('contact_name')); | ||
} | ||
] | ||
]); | ||
|
||
$result = $this->Invoices->duplicate(1); | ||
$invoice = $this->Invoices->get($result->id); | ||
|
||
$this->assertEquals('mail', $invoice->name); | ||
$this->assertEquals('eman tcatnoC', $invoice->contact_name); | ||
$this->assertEquals(1, $invoice->copied); | ||
} | ||
} |
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.
Micro optimisation, the
!is_string()
check could be done first.