Browse Source

Merge branch '4.x' into 4.next

Mark Story 3 years ago
parent
commit
4eb9aed702

+ 3 - 0
.editorconfig

@@ -16,6 +16,9 @@ end_of_line = crlf
 [*.yml]
 indent_size = 2
 
+[*.xml]
+indent_size = 2
+
 [Makefile]
 indent_style = tab
 

+ 1 - 1
.github/CONTRIBUTING.md

@@ -76,7 +76,7 @@ Check the [cakephp-codesniffer](https://github.com/cakephp/cakephp-codesniffer)
 repository to set up the CakePHP standard. The [README](https://github.com/cakephp/cakephp-codesniffer/blob/master/README.md) contains installation info
 for the sniff and phpcs.
 
-To run static analysis tools [PHPStan](https://github.com/phpstan/phpstan) and [Psalm](https://github.com/vimeo/psalm) you first have to install the additional packages via:
+To run static analysis tools [PHPStan](https://github.com/phpstan/phpstan) and [Psalm](https://github.com/vimeo/psalm) you first have to install the additional packages via [phive](https://phar.io).
 
     composer stan-setup
 

+ 13 - 7
.github/workflows/ci.yml

@@ -220,15 +220,17 @@ jobs:
     runs-on: ubuntu-22.04
 
     steps:
-    - uses: actions/checkout@v2
+    - uses: actions/checkout@v3
 
     - name: Setup PHP
       uses: shivammathur/setup-php@v2
       with:
         php-version: '7.4'
         extensions: mbstring, intl, apcu, memcached, redis
-        tools: cs2pr
         coverage: none
+        tools: phive, cs2pr
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
     - name: Get composer cache directory
       id: composer-cache
@@ -245,22 +247,26 @@ jobs:
         key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
 
     - name: Composer install
-      run: composer stan-setup
+      run: composer update
 
-    - name: Run PHP CodeSniffer
+    - name: Install PHP tools with phive.
+      run: phive install --trust-gpg-keys 'CF1A108D0E7AE720,12CE0F1D262429A5'
+
+    - name: Run phpcs
+      if: always()
       run: vendor/bin/phpcs --report=checkstyle src/ tests/ | cs2pr
 
     - name: Run psalm
       if: always()
-      run: vendor/bin/psalm.phar --output-format=github
+      run: tools/psalm --output-format=github
 
     - name: Run phpstan
       if: always()
-      run: vendor/bin/phpstan.phar analyse --error-format=github
+      run: tools/phpstan analyse --error-format=github
 
     - name: Run phpstan for tests
       if: always()
-      run: vendor/bin/phpstan.phar analyse -c tests/phpstan.neon --error-format=github
+      run: tools/phpstan analyse -c tests/phpstan.neon --error-format=github
 
     - name: Run class deprecation aliasing validaton script
       if: always()

+ 1 - 0
.gitignore

@@ -6,6 +6,7 @@
 /composer.lock
 /phpunit.xml
 /phpstan.neon
+/tools
 /vendor
 /vendors
 /composer.phar

+ 5 - 0
.phive/phars.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phive xmlns="https://phar.io/phive">
+  <phar name="phpstan" version="1.9.12" installed="1.9.12" location="./tools/phpstan" copy="false"/>
+  <phar name="psalm" version="4.30.0" installed="4.30.0" location="./tools/psalm" copy="false"/>
+</phive>

+ 3 - 3
composer.json

@@ -107,15 +107,15 @@
         ],
         "cs-check": "phpcs --colors --parallel=16 -p src/ tests/",
         "cs-fix": "phpcbf --colors --parallel=16 -p src/ tests/",
-        "phpstan": "phpstan.phar analyse",
-        "psalm": "psalm.phar --show-info=false",
+        "phpstan": "tools/phpstan analyse",
+        "psalm": "tools/psalm --show-info=false",
         "stan": [
             "@phpstan",
             "@psalm"
         ],
         "stan-tests": "phpstan.phar analyze -c tests/phpstan.neon",
         "stan-baseline": "phpstan.phar --generate-baseline",
-        "stan-setup": "cp composer.json composer.backup && composer require --dev symfony/polyfill-php81 phpstan/phpstan:~1.9.0 psalm/phar:~4.30.0 && mv composer.backup composer.json",
+        "stan-setup": "phive install",
         "lowest": "validate-prefer-lowest",
         "lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json",
         "test": "phpunit",

+ 1 - 1
src/Controller/ControllerFactory.php

@@ -346,7 +346,7 @@ class ControllerFactory implements ControllerFactoryInterface, RequestHandlerInt
     protected function missingController(ServerRequest $request)
     {
         return new MissingControllerException([
-            'class' => $request->getParam('controller'),
+            'controller' => $request->getParam('controller'),
             'plugin' => $request->getParam('plugin'),
             'prefix' => $request->getParam('prefix'),
             '_ext' => $request->getParam('_ext'),

+ 8 - 2
src/Database/Log/LoggingStatement.php

@@ -75,8 +75,14 @@ class LoggingStatement extends StatementDecorator
             $result = parent::execute($params);
             $this->loggedQuery->took = (int)round((microtime(true) - $this->startTime) * 1000, 0);
         } catch (Exception $e) {
-            /** @psalm-suppress UndefinedPropertyAssignment */
-            $e->queryString = $this->queryString;
+            if (version_compare(PHP_VERSION, '8.2.0', '<')) {
+                deprecationWarning(
+                    '4.4.12 - Having queryString set on exceptions is deprecated.' .
+                    'If you are not using this attribute there is no action to take.'
+                );
+                /** @psalm-suppress UndefinedPropertyAssignment */
+                $e->queryString = $this->queryString;
+            }
             $this->loggedQuery->error = $e;
             $this->_log();
             throw $e;

+ 12 - 6
tests/TestCase/Database/Log/LoggingStatementTest.php

@@ -149,6 +149,10 @@ class LoggingStatementTest extends TestCase
      */
     public function testExecuteWithError(): void
     {
+        $this->skipIf(
+            version_compare(PHP_VERSION, '8.2.0', '>='),
+            'Setting queryString on exceptions does not work on 8.2+'
+        );
         $exception = new MyPDOException('This is bad');
         $inner = $this->getMockBuilder(StatementInterface::class)->getMock();
         $inner->expects($this->once())
@@ -167,12 +171,14 @@ class LoggingStatementTest extends TestCase
             ->method('__get')
             ->willReturn('SELECT bar FROM foo');
         $st->setLogger(new QueryLogger(['connection' => 'test']));
-        try {
-            $st->execute();
-        } catch (MyPDOException $e) {
-            $this->assertSame('This is bad', $e->getMessage());
-            $this->assertSame($st->queryString, $e->queryString);
-        }
+        $this->deprecated(function () use ($st) {
+            try {
+                $st->execute();
+            } catch (MyPDOException $e) {
+                $this->assertSame('This is bad', $e->getMessage());
+                $this->assertSame($st->queryString, $e->queryString);
+            }
+        });
 
         $messages = Log::engine('queries')->read();
         $this->assertCount(1, $messages);

+ 20 - 1
tests/TestCase/Database/Log/QueryLoggerTest.php

@@ -56,13 +56,32 @@ class QueryLoggerTest extends TestCase
             'className' => 'Array',
             'scopes' => ['foo'],
         ]);
-        $logger->log(LogLevel::DEBUG, (string)$query, compact('query'));
+        $logger->log(LogLevel::DEBUG, $query, compact('query'));
 
         $this->assertCount(1, Log::engine('queryLoggerTest')->read());
         $this->assertCount(0, Log::engine('queryLoggerTest2')->read());
     }
 
     /**
+     * Tests that passed Stringable also work.
+     */
+    public function testLogFunctionStringable(): void
+    {
+        $this->skipIf(version_compare(PHP_VERSION, '8.0', '<'), 'Stringable exists since 8.0');
+
+        $logger = new QueryLogger(['connection' => '']);
+        $stringable = new class implements \Stringable
+        {
+            public function __toString(): string
+            {
+                return 'FooBar';
+            }
+        };
+
+        $logger->log(LogLevel::DEBUG, $stringable, ['query' => null]);
+    }
+
+    /**
      * Tests that the connection name is logged with the query.
      */
     public function testLogConnection(): void