From 780de166dac40f51f01d82ee761ea805728d93de Mon Sep 17 00:00:00 2001
From: mmorris <mmorris@tombras.com>
Date: Fri, 2 Oct 2015 09:50:56 -0400
Subject: [PATCH] Added a shorthand method to check if an individual argument
 is "stringable"

---
 core/lib/Drupal/Component/Assertion/Inspector.php | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/core/lib/Drupal/Component/Assertion/Inspector.php b/core/lib/Drupal/Component/Assertion/Inspector.php
index cb17632..01cdaf2 100644
--- a/core/lib/Drupal/Component/Assertion/Inspector.php
+++ b/core/lib/Drupal/Component/Assertion/Inspector.php
@@ -71,6 +71,9 @@ public static function assertAll(callable $callable, $traversable) {
   /**
    * Asserts that all members are strings.
    *
+   * Use this only if it is vital that the members not be objects, otherwise
+   * test with ::assertAllStringable().
+   *
    * @param mixed $traversable
    *   Variable to be examined.
    *
@@ -94,7 +97,7 @@ public static function assertAllStrings($traversable) {
   public static function assertAllStringable($traversable) {
     if (static::assertTraversable($traversable)) {
       foreach ($traversable as $member) {
-        if (!(is_string($member) || (is_object($member) && method_exists($member, '__toString')))) {
+        if (!static::assertStringable($member)) {
           return FALSE;
         }
       }
@@ -104,6 +107,22 @@ public static function assertAllStringable($traversable) {
   }
 
   /**
+   * Asserts argument is a string or an object castable to a string.
+   *
+   * Use this only if the argument being in object in any way would cause a
+   * problem.
+   *
+   * @param mixed string
+   *   Variable to be examined
+   *
+   * @return bool
+   *   TRUE if $string is a string or an object castable to a string.
+   */
+  public function assertStringable($string) {
+    return is_string($string) || (is_object($string) && method_exists($string, '__toString'));
+  }
+
+  /**
    * Asserts that all members are arrays.
    *
    * @param mixed $traversable
-- 
1.8.4.2

