Browse Source

Merge branch 'master' into 3.next

ADmad 7 years ago
parent
commit
071bc7f5eb

+ 17 - 6
.travis.yml

@@ -17,6 +17,7 @@ env:
   global:
     - DEFAULT=1
     - CODECOVERAGE=0
+    - PHPCS=0
 
 services:
   - memcached
@@ -57,19 +58,29 @@ before_install:
   - if [ $DB = 'pgsql' ]; then psql -c 'CREATE SCHEMA test2;' -U postgres -d cakephp_test; fi
   - if [ $DB = 'pgsql' ]; then psql -c 'CREATE SCHEMA test3;' -U postgres -d cakephp_test; fi
 
-  - if [[ $DEFAULT = 1 || $PHPSTAN = 1 ]] ; then pecl channel-update pecl.php.net; fi;
+  - if [[ $PHPCS = 0 ]] ; then pecl channel-update pecl.php.net; fi;
   - |
       if [[ ${TRAVIS_PHP_VERSION} != "7.3" && ${TRAVIS_PHP_VERSION} != "5.6" && ($DEFAULT = 1 || $PHPSTAN = 1) ]]; then
         echo 'extension = memcached.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini;
       fi
-  - if [[ $DEFAULT = 1 || $PHPSTAN = 1 ]] ; then echo 'extension = redis.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
-  - if [[ $DEFAULT = 1 || $PHPSTAN = 1 ]] ; then echo 'extension = apcu.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
-  - if [[ $DEFAULT = 1 || $PHPSTAN = 1 ]] ; then echo 'apc.enable_cli = 1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
+  - if [[ $PHPCS = 0 ]] ; then echo 'extension = redis.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
+  - if [[ $PHPCS = 0 ]] ; then echo 'extension = apcu.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
+  - if [[ $PHPCS = 0 ]] ; then echo 'apc.enable_cli = 1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
 
   - if [[ ${TRAVIS_PHP_VERSION:0:1} == "7" ]] ; then echo "yes" | pecl install channel://pecl.php.net/apcu-5.1.5 || true; fi
   - if [[ ${TRAVIS_PHP_VERSION:0:1} == "5" ]] ; then echo "yes" | pecl install apcu-4.0.11 || true; fi
-  - if [[ ${TRAVIS_PHP_VERSION:0:1} == "5" && $DB = 'mysql' ]] ; then wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz; tar xf xcache-3.2.0.tar.gz; pushd xcache-3.2.0; phpize; ./configure; make; NO_INTERACTION=1 make test; make install; popd;printf "extension=xcache.so\nxcache.size=64M\nxcache.var_size=16M\nxcache.test=On" > ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
-
+  - |
+      if [[ ${TRAVIS_PHP_VERSION:0:1} == "5" && $DB = 'mysql' ]]; then
+        wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
+        tar xf xcache-3.2.0.tar.gz
+        pushd xcache-3.2.0
+        phpize; ./configure
+        make
+        NO_INTERACTION=1 make test
+        make install
+        popd
+        printf "extension=xcache.so\nxcache.size=64M\nxcache.var_size=16M\nxcache.test=On" > ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
+      fi
   - sudo locale-gen da_DK
 
 before_script:

+ 3 - 4
src/Cache/Engine/MemcachedEngine.php

@@ -23,10 +23,9 @@ use Memcached;
  * control you have over expire times far in the future. See MemcachedEngine::write() for
  * more information.
  *
- * Main advantage of this Memcached engine over the memcached engine is
- * support of binary protocol, and igbinary serialization
- * (if memcached extension compiled with --enable-igbinary)
- * Compressed keys can also be incremented/decremented
+ * Memcached engine supports binary protocol and igbinary
+ * serialization (if memcached extension is compiled with --enable-igbinary).
+ * Compressed keys can also be incremented/decremented.
  */
 class MemcachedEngine extends CacheEngine
 {

+ 5 - 4
src/ORM/Association.php

@@ -179,8 +179,9 @@ abstract class Association
 
     /**
      * The default finder name to use for fetching rows from the target table
+     * With array value, finder name and default options are allowed.
      *
-     * @var string
+     * @var string|array
      */
     protected $_finder = 'all';
 
@@ -898,7 +899,7 @@ abstract class Association
     /**
      * Gets the default finder to use for fetching rows from the target table.
      *
-     * @return string
+     * @return string|array
      */
     public function getFinder()
     {
@@ -908,7 +909,7 @@ abstract class Association
     /**
      * Sets the default finder to use for fetching rows from the target table.
      *
-     * @param string $finder the finder name to use
+     * @param string|array $finder the finder name to use or array of finder name and option.
      * @return $this
      */
     public function setFinder($finder)
@@ -925,7 +926,7 @@ abstract class Association
      *
      * @deprecated 3.4.0 Use setFinder()/getFinder() instead.
      * @param string|null $finder the finder name to use
-     * @return string
+     * @return string|array
      */
     public function finder($finder = null)
     {

+ 7 - 0
src/ORM/ResultSet.php

@@ -528,6 +528,13 @@ class ResultSet implements ResultSetInterface
             $presentAliases[$table] = true;
         }
 
+        // If the default table is not in the results, set
+        // it to an empty array so that any contained
+        // associations hydrate correctly.
+        if (!isset($results[$defaultAlias])) {
+            $results[$defaultAlias] = [];
+        }
+
         unset($presentAliases[$defaultAlias]);
 
         foreach ($this->_containMap as $assoc) {

+ 2 - 2
src/TestSuite/Constraint/Response/CookieSet.php

@@ -29,9 +29,9 @@ class CookieSet extends ResponseBase
      */
     public function matches($other)
     {
-        $value = $this->response->getCookie($other);
+        $cookie = $this->response->getCookie($other);
 
-        return $value !== null;
+        return $cookie !== null && $cookie['value'] !== '';
     }
 
     /**

+ 1 - 0
src/View/Cell.php

@@ -198,6 +198,7 @@ abstract class Cell
             if (!$builder->getTemplatePath()) {
                 $builder->setTemplatePath('Cell' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $name));
             }
+            $template = $builder->getTemplate();
 
             $this->View = $this->createView();
             try {

+ 2 - 2
src/View/Helper.php

@@ -180,7 +180,7 @@ class Helper implements EventListenerInterface
         if (isset($removed[$name])) {
             $method = $removed[$name];
             deprecationWarning(sprintf(
-                'Helper::$%s is removed. Use $view->%s() instead.',
+                'Helper::$%s is deprecated. Use $view->%s() instead.',
                 $name,
                 $method
             ));
@@ -191,7 +191,7 @@ class Helper implements EventListenerInterface
 
         if ($name === 'request') {
             deprecationWarning(
-                'Helper::$%s is removed. Use $view->%s() instead. Use $helper->getView()->setRequest() instead.'
+                'Helper::$request is deprecated. Use $helper->getView()->setRequest() instead.'
             );
 
             $this->_View->setRequest($value);

+ 22 - 0
tests/TestCase/ORM/Association/BelongsToTest.php

@@ -434,4 +434,26 @@ class BelongsToTest extends TestCase
             return $q->applyOptions(['something' => 'more']);
         }]);
     }
+
+    /**
+     * Test that failing to add the foreignKey to the list of fields will throw an
+     * exception
+     *
+     * @return void
+     */
+    public function testAttachToNoFieldsSelected()
+    {
+        $articles = $this->getTableLocator()->get('Articles');
+        $association = $articles->belongsTo('Authors');
+
+        $query = $articles->find()
+            ->select(['Authors.name'])
+            ->where(['Articles.id' => 1])
+            ->contain('Authors');
+        $result = $query->firstOrFail();
+
+        $this->assertNotEmpty($result->author);
+        $this->assertSame('mariano', $result->author->name);
+        $this->assertSame(['author'], array_keys($result->toArray()), 'No other properties included.');
+    }
 }

+ 26 - 0
tests/TestCase/ORM/QueryRegressionTest.php

@@ -879,6 +879,32 @@ class QueryRegressionTest extends TestCase
     }
 
     /**
+     * Test selecting with aliased aggregates and identifier quoting
+     * does not emit notice errors.
+     *
+     * @see https://github.com/cakephp/cakephp/issues/12766
+     * @return void
+     */
+    public function testAliasedAggregateFieldTypeConversionSafe()
+    {
+        $this->loadFixtures('Articles');
+        $articles = $this->getTableLocator()->get('Articles');
+
+        $driver = $articles->getConnection()->getDriver();
+        $restore = $driver->isAutoQuotingEnabled();
+
+        $driver->enableAutoQuoting(true);
+        $query = $articles->find();
+        $query->select([
+            'sumUsers' => $articles->find()->func()->sum('author_id')
+        ]);
+        $driver->enableAutoQuoting($restore);
+
+        $result = $query->execute()->fetchAll('assoc');
+        $this->assertArrayHasKey('sumUsers', $result[0]);
+    }
+
+    /**
      * Tests that calling first on the query results will not remove all other results
      * from the set.
      *

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

@@ -2471,7 +2471,7 @@ class QueryTest extends TestCase
             ->contain(['Authors'])
             ->order(['Authors.id' => 'asc'])
             ->select(['Authors.id']);
-        $results = $query->extract('Authors.id')->toList();
+        $results = $query->extract('author.id')->toList();
         $expected = [1, 1, 3];
         $this->assertEquals($expected, $results);
     }

+ 12 - 0
tests/TestCase/TestSuite/IntegrationTestTraitTest.php

@@ -704,6 +704,18 @@ class IntegrationTestTraitTest extends IntegrationTestCase
     }
 
     /**
+     * Tests assertCookieNotSet assertion
+     *
+     * @return void
+     */
+    public function testAssertCookieNotSet()
+    {
+        $this->cookie('test', 'value');
+        $this->get('/cookie_component_test/remove_cookie/test');
+        $this->assertCookieNotSet('test');
+    }
+
+    /**
      * Tests the failure message for assertCookieNotSet
      *
      * @return void

+ 5 - 0
tests/test_app/TestApp/Controller/CookieComponentTestController.php

@@ -57,4 +57,9 @@ class CookieComponentTestController extends Controller
         }
         $this->Cookie->write('NameOfCookie', 'abc');
     }
+
+    public function remove_cookie($key)
+    {
+        $this->Cookie->delete($key);
+    }
 }