diff mbox series

[bug#67902,v4,73/98] gnu: Add php-symfony-phpunit-bridge.

Message ID 20241007214530.4420-73-ngraves@ngraves.fr
State New
Headers show
Series [bug#67902,v4,01/98] gnu: Add abnfgen. | expand

Commit Message

Nicolas Graves Oct. 7, 2024, 9:44 p.m. UTC
* gnu/packages/php-xyz.scm  (php-symfony-phpunit-bridge): New variable.
* gnu/packages/patches/php-symfony-phpunit-bridge-getVendors-fix.patch:
New file.

Change-Id: Ie72bd332a6fb7aaf96a59ce24e6008e6aa599f59
---
 ...ymfony-phpunit-bridge-getVendors-fix.patch | 46 +++++++++++
 gnu/packages/php-xyz.scm                      | 77 +++++++++++++++++++
 2 files changed, 123 insertions(+)
 create mode 100644 gnu/packages/patches/php-symfony-phpunit-bridge-getVendors-fix.patch
diff mbox series

Patch

diff --git a/gnu/packages/patches/php-symfony-phpunit-bridge-getVendors-fix.patch b/gnu/packages/patches/php-symfony-phpunit-bridge-getVendors-fix.patch
new file mode 100644
index 0000000000..fd48e2ce6c
--- /dev/null
+++ b/gnu/packages/patches/php-symfony-phpunit-bridge-getVendors-fix.patch
@@ -0,0 +1,46 @@ 
+From 4b7c29c3e98aa55ea7567a3d496595e539f30cdb Mon Sep 17 00:00:00 2001
+From: Nicolas Graves <ngraves@ngraves.fr>
+Date: Sun, 22 Oct 2023 16:31:40 +0200
+Subject: [PATCH] Deprecation.php: Do not check for composer in getVendors.
+
+---
+ DeprecationErrorHandler/Deprecation.php | 23 ++---------------------
+ 1 file changed, 2 insertions(+), 21 deletions(-)
+
+diff --git a/DeprecationErrorHandler/Deprecation.php b/DeprecationErrorHandler/Deprecation.php
+index 79cfa0c..b7074f7 100644
+--- a/DeprecationErrorHandler/Deprecation.php
++++ b/DeprecationErrorHandler/Deprecation.php
+@@ -365,27 +365,8 @@ class Deprecation
+             if (class_exists(DebugClassLoader::class, false)) {
+                 self::$vendors[] = \dirname((new \ReflectionClass(DebugClassLoader::class))->getFileName());
+             }
+-            foreach (get_declared_classes() as $class) {
+-                if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
+-                    $r = new \ReflectionClass($class);
+-                    $v = \dirname($r->getFileName(), 2);
+-                    if (file_exists($v.'/composer/installed.json')) {
+-                        self::$vendors[] = $v;
+-                        $loader = require $v.'/autoload.php';
+-                        $paths = self::addSourcePathsFromPrefixes(
+-                            array_merge($loader->getPrefixes(), $loader->getPrefixesPsr4()),
+-                            $paths
+-                        );
+-                    }
+-                }
+-            }
+-            foreach ($paths as $path) {
+-                foreach (self::$vendors as $vendor) {
+-                    if (0 !== strpos($path, $vendor)) {
+-                        self::$internalPaths[] = $path;
+-                    }
+-                }
+-            }
++            self::$vendors[] = $v;
++            self::$internalPaths[] = $paths;
+         }
+ 
+         return self::$vendors;
+-- 
+2.41.0
+
diff --git a/gnu/packages/php-xyz.scm b/gnu/packages/php-xyz.scm
index e9a6a0e0d3..9bdd943f63 100644
--- a/gnu/packages/php-xyz.scm
+++ b/gnu/packages/php-xyz.scm
@@ -1946,3 +1946,80 @@  (define-public php-symfony-mime
     (home-page "https://symfony.com")
     (license license:expat)))
 
+(define-public php-symfony-phpunit-bridge
+  (package
+    (name "php-symfony-phpunit-bridge")
+    (version "6.3.6")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/symfony/phpunit-bridge")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "1v5zdjb0d7282wq0ghwzn9x005wqlzjmx2msi9vhp1c4l513fxgf"))
+       (patches
+        (search-patches "php-symfony-phpunit-bridge-getVendors-fix.patch"))))
+    (build-system composer-build-system)
+    (arguments
+     (list
+      #:test-flags  ; Some tests are useless but get reported as risky.
+      ''("--bootstrap" "vendor/autoload.php" "--dont-report-useless-tests")
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'deactivate-bootstrap.php
+            (lambda _
+              (substitute* "composer.json"
+                ((".*\"files\".*")
+                 ""))))
+          (add-before 'check 'pre-check
+            (lambda* (#:key inputs #:allow-other-keys)
+              ;; Adapt some PHP test code to Guix context.
+              (mkdir-p
+               (string-append (getcwd) "/vendor/myfakevendor/myfakepackage1"))
+              (substitute* "Tests/DeprecationErrorHandler/DeprecationTest.php"
+                (("(.*)self::\\$vendorDir = \\$vendorDir;" all blank)
+                 (string-append
+                  blank "$vendorDir = '" (getcwd) "/vendor/';\n"
+                  all)))
+              (substitute* "DeprecationErrorHandler/Deprecation.php"
+                (("(self::\\$vendors\\[\\] = )\\$v;" all eq)
+                 (string-append eq "'" (getcwd) "/vendor';"))
+                (("(self::\\$internalPaths)\\[\\] = \\$paths;" all def)
+                 (string-append
+                  def " = ["
+                  "'" (getcwd) "/Tests/DeprecationErrorHandler/Deprecation.php',"
+                  "'" (getcwd) "/Tests/DeprecationErrorHandler/DeprecationTest.php',"
+                  "'" (getcwd) "/Tests/DeprecationErrorHandler.php',"
+                  "];")))
+              ;; Remove failing tests. All but two are probably failing
+              ;; because of some version mismatch of php-symfony-error-handler.
+              (for-each
+               (lambda (f)
+                 (delete-file
+                  (string-append "Tests/DeprecationErrorHandler/" f)))
+               '("partially_quiet.phpt"
+                 "partially_quiet2.phpt"
+                 "trigger_deprecation_types.phpt"
+                 "trigger_error_types.phpt"
+                 "weak_vendors_on_vendor.phpt"))
+              (delete-file "Tests/CoverageListenerTest.php")
+              ;; For most simple cases, handle php-symfony-error-handler
+              ;; discrepancies.
+              (substitute* (find-files "Tests" "\\.phpt")
+                (("Remaining indirect deprecation notices")
+                 "Other deprecation notices")
+                (("Remaining direct deprecation notices")
+                 "Other deprecation notices")))))))
+    (native-inputs
+     (list php-phpunit-phpunit
+           php-symfony-deprecation-contracts
+           php-symfony-error-handler))
+    (synopsis "Utilities for PHPUnit")
+    (description
+     "This package provides utilities for PHPUnit, especially user deprecation
+notices management.")
+    (home-page "https://symfony.com")
+    (license license:expat)))
+