Browse Source

Adding an integration test for the SaveOptionBuilder

Florian Krämer 9 years ago
parent
commit
2f1bebd674
2 changed files with 26 additions and 1 deletions
  1. 1 1
      src/ORM/Table.php
  2. 25 0
      tests/TestCase/ORM/TableTest.php

+ 1 - 1
src/ORM/Table.php

@@ -2371,7 +2371,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
     /**
      * Gets a SaveOptionsBuilder instance.
      *
-     * @param array $options Options to load into the builder.
+     * @param array $options Options to parse by the builder.
      * @return \Cake\ORM\SaveOptionsBuilder
      */
     public function getSaveOptionsBuilder(array $options = [])

+ 25 - 0
tests/TestCase/ORM/TableTest.php

@@ -32,6 +32,7 @@ use Cake\ORM\Association\HasMany;
 use Cake\ORM\Entity;
 use Cake\ORM\Query;
 use Cake\ORM\RulesChecker;
+use Cake\ORM\SaveOptionsBuilder;
 use Cake\ORM\Table;
 use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
@@ -3815,6 +3816,30 @@ class TableTest extends TestCase
     }
 
     /**
+     * Test that a save call takes a SaveOptionBuilder object as well.
+     *
+     * @group save
+     * @return void
+     */
+    public function testSaveWithOptionBuilder()
+    {
+        $table = $this->getMockBuilder('\Cake\ORM\Table')
+            ->setMethods(['_processSave'])
+            ->getMock();
+
+        $optionBuilder = new SaveOptionsBuilder($table, [
+            'associated' => []
+        ]);
+
+        $entity = new \Cake\ORM\Entity(
+            ['id' => 'foo'],
+            ['markNew' => false, 'markClean' => true]
+        );
+
+        $this->assertSame($entity, $table->save($entity, $optionBuilder));
+    }
+
+    /**
      * Tests that saving a persisted and clean entity will is a no-op
      *
      * @group save