Browse Source

Remove additional test stubs that are not required.

Remove code that can easily be replicated in the test method.
Fix doc blocks in fixtures.
Mark Story 11 years ago
parent
commit
73210d710d

+ 8 - 9
src/ORM/AssociationCollection.php

@@ -14,7 +14,6 @@
  */
 namespace Cake\ORM;
 
-use Cake\Collection\Collection;
 use Cake\ORM\Association;
 use Cake\ORM\AssociationsNormalizerTrait;
 use Cake\ORM\Entity;
@@ -260,15 +259,15 @@ class AssociationCollection
      */
     public function cascadeDelete(Entity $entity, array $options)
     {
-        $assocs = new Collection($this->_items);
-        $assocs = $assocs->filter(function ($assoc) use ($entity, $options) {
-            if ($assoc->cascadeCallbacks()) {
-                $assoc->cascadeDelete($entity, $options);
-                return false;
+        $noCascade = [];
+        foreach ($this->_items as $assoc) {
+            if (!$assoc->cascadeCallbacks()) {
+                $noCascade[] = $assoc;
+                continue;
             }
-            return true;
-        })->toArray();
-        foreach ($assocs as $assoc) {
+            $assoc->cascadeDelete($entity, $options);
+        }
+        foreach ($noCascade as $assoc) {
             $assoc->cascadeDelete($entity, $options);
         }
     }

+ 1 - 1
tests/Fixture/GroupsFixture.php

@@ -9,7 +9,7 @@
  *
  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @since         1.2.0
+ * @since         3.0.2
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
 namespace Cake\Test\Fixture;

+ 1 - 1
tests/Fixture/GroupsMembersFixture.php

@@ -9,7 +9,7 @@
  *
  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @since         1.2.0
+ * @since         3.0.2
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
 namespace Cake\Test\Fixture;

+ 1 - 1
tests/Fixture/MembersFixture.php

@@ -9,7 +9,7 @@
  *
  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @since         1.2.0
+ * @since         3.0.2
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
 namespace Cake\Test\Fixture;

+ 22 - 5
tests/TestCase/ORM/TableTest.php

@@ -2468,17 +2468,34 @@ class TableTest extends TestCase
         $this->assertNull($query->all()->first(), 'Should not find any rows.');
     }
 
+    /**
+     * Test that cascading associations are deleted first.
+     *
+     * @return void
+     */
     public function testDeleteAssociationsCascadingCallbacksOrder()
     {
-        $Members = TableRegistry::get('Members');
+        $groups = TableRegistry::get('Groups');
+        $members = TableRegistry::get('Members');
+        $groupsMembers = TableRegistry::get('GroupsMembers');
+
+        $groups->belongsToMany('Members');
+        $groups->hasMany('GroupsMembers', [
+            'dependent' => true,
+            'cascadeCallbacks' => true,
+        ]);
+        $groupsMembers->belongsTo('Members');
+        $groupsMembers->addBehavior('CounterCache', [
+            'Members' => ['group_count']
+        ]);
 
-        $member = $Members->get(1);
+        $member = $members->get(1);
         $this->assertEquals(2, $member->group_count);
 
-        $group = $Members->Groups->get(1);
-        $Members->Groups->delete($group);
+        $group = $groups->get(1);
+        $groups->delete($group);
 
-        $member = $Members->get(1);
+        $member = $members->get(1);
         $this->assertEquals(1, $member->group_count);
     }
 

+ 0 - 30
tests/test_app/TestApp/Model/Table/GroupsMembersTable.php

@@ -1,30 +0,0 @@
-<?php
-/**
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @since         3.0.0
- * @license       http://www.opensource.org/licenses/mit-license.php MIT License
- */
-namespace TestApp\Model\Table;
-
-use Cake\ORM\Table;
-
-/**
- * Article table class
- *
- */
-class GroupsMembersTable extends Table
-{
-
-    public function initialize(array $config)
-    {
-        $this->belongsTo('Members');
-
-        $this->addBehavior('CounterCache', ['Members' => ['group_count']]);
-    }
-}

+ 0 - 33
tests/test_app/TestApp/Model/Table/GroupsTable.php

@@ -1,33 +0,0 @@
-<?php
-/**
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @since         3.0.0
- * @license       http://www.opensource.org/licenses/mit-license.php MIT License
- */
-namespace TestApp\Model\Table;
-
-use Cake\ORM\Table;
-
-/**
- * Article table class
- *
- */
-class GroupsTable extends Table
-{
-
-    public function initialize(array $config)
-    {
-        $this->belongsToMany('Members');
-
-        $this->hasMany('GroupsMembers', [
-            'dependent' => true,
-            'cascadeCallbacks' => true
-        ]);
-    }
-}

+ 0 - 28
tests/test_app/TestApp/Model/Table/MembersTable.php

@@ -1,28 +0,0 @@
-<?php
-/**
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @since         3.0.0
- * @license       http://www.opensource.org/licenses/mit-license.php MIT License
- */
-namespace TestApp\Model\Table;
-
-use Cake\ORM\Table;
-
-/**
- * Article table class
- *
- */
-class MembersTable extends Table
-{
-
-    public function initialize(array $config)
-    {
-        $this->belongsToMany('Groups');
-    }
-}