Browse Source

Merge pull request #8527 from cakephp/fix-travis-test

Fix travis tests
Mark Story 10 years ago
parent
commit
2f7b0327dc

+ 1 - 1
.travis.yml

@@ -69,7 +69,7 @@ before_script:
   - set +H
 
 script:
-  - sh -c "if [ '$DEFAULT' = '1' ]; then phpunit; fi"
+  - sh -c "if [ '$DEFAULT' = '1' ]; then vendor/bin/phpunit; fi"
 
   - sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi"
 

+ 9 - 2
tests/TestCase/Console/ShellTest.php

@@ -962,7 +962,11 @@ TEXT;
      */
     public function testRunCommandBaseclassMethod()
     {
-        $shell = $this->getMock('Cake\Console\Shell', ['startup', 'getOptionParser', 'out'], [], '', false);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['startup', 'getOptionParser', 'out', 'hr'])
+            ->disableOriginalConstructor()
+            ->getMock();
+
         $shell->io($this->getMock('Cake\Console\ConsoleIo'));
         $parser = $this->getMock('Cake\Console\ConsoleOptionParser', [], [], '', false);
 
@@ -982,7 +986,10 @@ TEXT;
      */
     public function testRunCommandMissingMethod()
     {
-        $shell = $this->getMock('Cake\Console\Shell', ['startup', 'getOptionParser', 'out'], [], '', false);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['startup', 'getOptionParser', 'out', 'hr'])
+            ->disableOriginalConstructor()
+            ->getMock();
         $shell->io($this->getMock('Cake\Console\ConsoleIo'));
         $parser = $this->getMock('Cake\Console\ConsoleOptionParser', [], [], '', false);
 

+ 1 - 0
tests/TestCase/Controller/Component/AuthComponentTest.php

@@ -1450,6 +1450,7 @@ class AuthComponentTest extends TestCase
      */
     public function testStatelessFollowedByStatefulAuth()
     {
+        $this->Auth->response = $this->getMock('Cake\Network\Response', ['stop', 'statusCode', 'send']);
         $event = new Event('Controller.startup', $this->Controller);
         $this->Auth->authenticate = ['Basic', 'Form'];
         $this->Controller->request['action'] = 'add';

+ 6 - 18
tests/TestCase/Controller/ControllerTest.php

@@ -522,29 +522,17 @@ class ControllerTest extends TestCase
         $this->assertEquals(302, $response->statusCode());
     }
 
-    /**
-     * test that beforeRedirect callback returning false in controller
-     *
-     * @return void
-     */
-    public function testRedirectBeforeRedirectListenerReturnFalse()
+    public function testRedirectBeforeRedirectListenerReturnResponse()
     {
-        $Response = $this->getMock('Cake\Network\Response', ['stop', 'header']);
+        $Response = $this->getMock('Cake\Network\Response', ['stop', 'header', 'statusCode']);
         $Controller = new Controller(null, $Response);
 
-        $Controller->eventManager()->attach(function ($event, $url, $response) {
-            return false;
-        }, 'Controller.beforeRedirect');
-
-        $Controller->response->expects($this->never())
-            ->method('stop');
-        $Controller->response->expects($this->never())
-            ->method('header');
-        $Controller->response->expects($this->never())
-            ->method('statusCode');
+        $Controller->eventManager()->on('Controller.beforeRedirect', function ($event, $url, $response) {
+            return new Response;
+        });
 
         $result = $Controller->redirect('http://cakephp.org');
-        $this->assertNull($result);
+        $this->assertInstanceOf(Response::class, $result);
     }
 
     /**

+ 30 - 13
tests/TestCase/Database/QueryTest.php

@@ -1352,6 +1352,7 @@ class QueryTest extends TestCase
 
         $second = $result->fetch('assoc');
         $this->assertEquals(5, $second['id']);
+        $result->closeCursor();
     }
 
     /**
@@ -1372,6 +1373,7 @@ class QueryTest extends TestCase
             ->execute();
         $this->assertCount(1, $result);
         $this->assertEquals(['id' => 2], $result->fetch('assoc'));
+        $result->closeCursor();
 
         $query = new Query($this->connection);
         $result = $query
@@ -1383,6 +1385,7 @@ class QueryTest extends TestCase
             })
             ->execute();
         $this->assertCount(0, $result);
+        $result->closeCursor();
 
         $query = new Query($this->connection);
         $result = $query
@@ -1397,6 +1400,7 @@ class QueryTest extends TestCase
             ->execute();
         $this->assertCount(1, $result);
         $this->assertEquals(['id' => 1], $result->fetch('assoc'));
+        $result->closeCursor();
 
         $query = new Query($this->connection);
         $result = $query
@@ -1411,6 +1415,7 @@ class QueryTest extends TestCase
         $this->assertCount(2, $result);
         $this->assertEquals(['id' => 1], $result->fetch('assoc'));
         $this->assertEquals(['id' => 3], $result->fetch('assoc'));
+        $result->closeCursor();
 
         $query = new Query($this->connection);
         $result = $query
@@ -1426,6 +1431,7 @@ class QueryTest extends TestCase
         $this->assertCount(2, $result);
         $this->assertEquals(['id' => 1], $result->fetch('assoc'));
         $this->assertEquals(['id' => 2], $result->fetch('assoc'));
+        $result->closeCursor();
     }
 
     /**
@@ -1449,6 +1455,7 @@ class QueryTest extends TestCase
         $this->assertCount(5, $result);
         $this->assertEquals(['id' => 1], $result->fetch('assoc'));
         $this->assertEquals(['id' => 3], $result->fetch('assoc'));
+        $result->closeCursor();
 
         $query = new Query($this->connection);
         $result = $query
@@ -1461,6 +1468,7 @@ class QueryTest extends TestCase
             })
             ->execute();
         $this->assertCount(6, $result);
+        $result->closeCursor();
 
         $query = new Query($this->connection);
         $result = $query
@@ -1473,6 +1481,7 @@ class QueryTest extends TestCase
         $this->assertCount(2, $result);
         $this->assertEquals(['id' => 1], $result->fetch('assoc'));
         $this->assertEquals(['id' => 2], $result->fetch('assoc'));
+        $result->closeCursor();
     }
 
     /**
@@ -1485,42 +1494,48 @@ class QueryTest extends TestCase
         $query = new Query($this->connection);
         $result = $query
             ->select(['id'])
-            ->from('articles')
+            ->from('comments')
             ->order(['id' => 'desc'])
             ->execute();
-        $this->assertEquals(['id' => 3], $result->fetch('assoc'));
-        $this->assertEquals(['id' => 2], $result->fetch('assoc'));
-        $this->assertEquals(['id' => 1], $result->fetch('assoc'));
+        $this->assertEquals(['id' => 6], $result->fetch('assoc'));
+        $this->assertEquals(['id' => 5], $result->fetch('assoc'));
+        $this->assertEquals(['id' => 4], $result->fetch('assoc'));
+        $result->closeCursor();
 
         $result = $query->order(['id' => 'asc'])->execute();
         $this->assertEquals(['id' => 1], $result->fetch('assoc'));
         $this->assertEquals(['id' => 2], $result->fetch('assoc'));
         $this->assertEquals(['id' => 3], $result->fetch('assoc'));
+        $result->closeCursor();
 
-        $result = $query->order(['title' => 'asc'])->execute();
+        $result = $query->order(['comment' => 'asc'])->execute();
         $this->assertEquals(['id' => 1], $result->fetch('assoc'));
         $this->assertEquals(['id' => 2], $result->fetch('assoc'));
         $this->assertEquals(['id' => 3], $result->fetch('assoc'));
+        $result->closeCursor();
 
-        $result = $query->order(['title' => 'asc'], true)->execute();
+        $result = $query->order(['comment' => 'asc'], true)->execute();
         $this->assertEquals(['id' => 1], $result->fetch('assoc'));
-        $this->assertEquals(['id' => 2], $result->fetch('assoc'));
-        $this->assertEquals(['id' => 3], $result->fetch('assoc'));
+        $this->assertEquals(['id' => 5], $result->fetch('assoc'));
+        $this->assertEquals(['id' => 4], $result->fetch('assoc'));
+        $result->closeCursor();
 
-        $result = $query->order(['title' => 'asc', 'published' => 'asc'], true)
+        $result = $query->order(['user_id' => 'asc', 'created' => 'desc'], true)
             ->execute();
-        $this->assertEquals(['id' => 1], $result->fetch('assoc'));
-        $this->assertEquals(['id' => 2], $result->fetch('assoc'));
+        $this->assertEquals(['id' => 5], $result->fetch('assoc'));
+        $this->assertEquals(['id' => 4], $result->fetch('assoc'));
         $this->assertEquals(['id' => 3], $result->fetch('assoc'));
+        $result->closeCursor();
 
         $expression = $query->newExpr(['(id + :offset) % 2']);
         $result = $query
             ->order([$expression, 'id' => 'desc'], true)
             ->bind(':offset', 1, null)
             ->execute();
+        $this->assertEquals(['id' => 5], $result->fetch('assoc'));
         $this->assertEquals(['id' => 3], $result->fetch('assoc'));
         $this->assertEquals(['id' => 1], $result->fetch('assoc'));
-        $this->assertEquals(['id' => 2], $result->fetch('assoc'));
+        $result->closeCursor();
 
         $result = $query
             ->order($expression, true)
@@ -1529,7 +1544,8 @@ class QueryTest extends TestCase
             ->execute();
         $this->assertEquals(['id' => 1], $result->fetch('assoc'));
         $this->assertEquals(['id' => 3], $result->fetch('assoc'));
-        $this->assertEquals(['id' => 2], $result->fetch('assoc'));
+        $this->assertEquals(['id' => 5], $result->fetch('assoc'));
+        $result->closeCursor();
     }
 
     /**
@@ -1547,6 +1563,7 @@ class QueryTest extends TestCase
         $this->assertEquals(['id' => 1], $result->fetch('assoc'));
         $this->assertEquals(['id' => 2], $result->fetch('assoc'));
         $this->assertEquals(['id' => 3], $result->fetch('assoc'));
+        $result->closeCursor();
     }
 
     /**

+ 1 - 1
tests/TestCase/ORM/Association/BelongsToTest.php

@@ -287,7 +287,7 @@ class BelongsToTest extends TestCase
      */
     public function testSaveAssociatedOnlyEntities()
     {
-        $mock = $this->getMock('Cake\ORM\Table', [], [], '', false);
+        $mock = $this->getMock('Cake\ORM\Table', ['saveAssociated'], [], '', false);
         $config = [
             'sourceTable' => $this->client,
             'targetTable' => $mock,

+ 1 - 1
tests/TestCase/ORM/Association/HasManyTest.php

@@ -485,7 +485,7 @@ class HasManyTest extends TestCase
      */
     public function testSaveAssociatedOnlyEntities()
     {
-        $mock = $this->getMock('Cake\ORM\Table', [], [], '', false);
+        $mock = $this->getMock('Cake\ORM\Table', ['saveAssociated'], [], '', false);
         $config = [
             'sourceTable' => $this->author,
             'targetTable' => $mock,

+ 1 - 1
tests/TestCase/ORM/Association/HasOneTest.php

@@ -221,7 +221,7 @@ class HasOneTest extends TestCase
      */
     public function testSaveAssociatedOnlyEntities()
     {
-        $mock = $this->getMock('Cake\ORM\Table', [], [], '', false);
+        $mock = $this->getMock('Cake\ORM\Table', ['saveAssociated'], [], '', false);
         $config = [
             'sourceTable' => $this->user,
             'targetTable' => $mock,

+ 1 - 1
tests/TestCase/ORM/EntityTest.php

@@ -818,7 +818,7 @@ class EntityTest extends TestCase
     public function testConstructorWithMarkNew()
     {
         $entity = $this->getMockBuilder('\Cake\ORM\Entity')
-            ->setMethods(['isNew'])
+            ->setMethods(['isNew', 'clean'])
             ->disableOriginalConstructor()
             ->getMock();
         $entity->expects($this->never())->method('clean');

+ 1 - 1
tests/TestCase/Routing/Filter/AssetFilterTest.php

@@ -76,7 +76,7 @@ class AssetFilterTest extends TestCase
         $this->assertEquals(200, $response->statusCode());
         $this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified());
 
-        $response = $this->getMock('Cake\Network\Response', ['_sendHeader', 'checkNotModified']);
+        $response = $this->getMock('Cake\Network\Response', ['_sendHeader', 'checkNotModified', 'send']);
         $request = new Request('test_theme/img/cake.power.gif');
 
         $response->expects($this->once())->method('checkNotModified')