Skip to content

Commit

Permalink
Fixing some failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Dec 26, 2014
1 parent b001256 commit 10ead5b
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions tests/TestCase/ORM/RulesCheckerIntegrationTest.php
Expand Up @@ -396,11 +396,19 @@ public function testUseBeforeRules() {
$rules = $table->rulesChecker();
$rules->add($rules->existsIn('author_id', TableRegistry::get('Authors'), 'Nope'));

$table->eventManager()->attach(function ($event, Entity $entity, RulesChecker $check) {
$this->assertSame($event->subject()->rulesChecker(), $check);
$event->stopPropagation();
return true;
}, 'Model.beforeRules');
$table->eventManager()->attach(
function ($event, Entity $entity, \ArrayObject $options, $operation, RulesChecker $check) {
$this->assertEquals(
['atomic' => true, 'associated' => true, 'checkRules' => true],
$options->getArrayCopy()
);
$this->assertEquals('create', $operation);
$this->assertSame($event->subject()->rulesChecker(), $check);
$event->stopPropagation();
return true;
},
'Model.beforeRules'
);

$this->assertSame($entity, $table->save($entity));
}
Expand All @@ -421,12 +429,20 @@ public function testUseAfterRules() {
$rules = $table->rulesChecker();
$rules->add($rules->existsIn('author_id', TableRegistry::get('Authors'), 'Nope'));

$table->eventManager()->attach(function ($event, Entity $entity, RulesChecker $check, $result) {
$this->assertSame($event->subject()->rulesChecker(), $check);
$this->assertFalse($result);
$event->stopPropagation();
return true;
}, 'Model.afterRules');
$table->eventManager()->attach(
function ($event, Entity $entity, \ArrayObject $options, $result, $operation, RulesChecker $check) {
$this->assertEquals(
['atomic' => true, 'associated' => true, 'checkRules' => true],
$options->getArrayCopy()
);
$this->assertEquals('create', $operation);
$this->assertSame($event->subject()->rulesChecker(), $check);
$this->assertFalse($result);
$event->stopPropagation();
return true;
},
'Model.afterRules'
);

$this->assertSame($entity, $table->save($entity));
}
Expand Down

0 comments on commit 10ead5b

Please sign in to comment.