Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / validator / Tests / ConstraintViolationListTest.php
index 6f4518cab39e45373c37d9b3ac4a5ac5605fa119..f0e6afe20da3f67eccd2a2601902fe7a47ee8be1 100644 (file)
@@ -89,16 +89,16 @@ class ConstraintViolationListTest extends TestCase
         $this->list[] = $violation;
 
         $this->assertSame($violation, $this->list[0]);
-        $this->assertTrue(isset($this->list[0]));
+        $this->assertArrayHasKey(0, $this->list);
 
         unset($this->list[0]);
 
-        $this->assertFalse(isset($this->list[0]));
+        $this->assertArrayNotHasKey(0, $this->list);
 
         $this->list[10] = $violation;
 
         $this->assertSame($violation, $this->list[10]);
-        $this->assertTrue(isset($this->list[10]));
+        $this->assertArrayHasKey(10, $this->list);
     }
 
     public function testToString()
@@ -128,8 +128,35 @@ EOF;
         $this->assertEquals($expected, (string) $this->list);
     }
 
-    protected function getViolation($message, $root = null, $propertyPath = null)
+    /**
+     * @dataProvider findByCodesProvider
+     */
+    public function testFindByCodes($code, $violationsCount)
     {
-        return new ConstraintViolation($message, $message, array(), $root, $propertyPath, null);
+        $violations = array(
+            $this->getViolation('Error', null, null, 'code1'),
+            $this->getViolation('Error', null, null, 'code1'),
+            $this->getViolation('Error', null, null, 'code2'),
+        );
+        $list = new ConstraintViolationList($violations);
+
+        $specificErrors = $list->findByCodes($code);
+
+        $this->assertInstanceOf(ConstraintViolationList::class, $specificErrors);
+        $this->assertCount($violationsCount, $specificErrors);
+    }
+
+    public function findByCodesProvider()
+    {
+        return array(
+            array('code1', 2),
+            array(array('code1', 'code2'), 3),
+            array('code3', 0),
+        );
+    }
+
+    protected function getViolation($message, $root = null, $propertyPath = null, $code = null)
+    {
+        return new ConstraintViolation($message, $message, array(), $root, $propertyPath, null, null, $code);
     }
 }