diff vendor/nikic/php-parser/test/PhpParser/Node/NameTest.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
line wrap: on
line diff
--- a/vendor/nikic/php-parser/test/PhpParser/Node/NameTest.php	Fri Feb 23 15:52:07 2018 +0000
+++ b/vendor/nikic/php-parser/test/PhpParser/Node/NameTest.php	Mon Apr 23 09:33:26 2018 +0100
@@ -1,18 +1,20 @@
-<?php
+<?php declare(strict_types=1);
 
 namespace PhpParser\Node;
 
-class NameTest extends \PHPUnit_Framework_TestCase
+use PHPUnit\Framework\TestCase;
+
+class NameTest extends TestCase
 {
     public function testConstruct() {
-        $name = new Name(array('foo', 'bar'));
-        $this->assertSame(array('foo', 'bar'), $name->parts);
+        $name = new Name(['foo', 'bar']);
+        $this->assertSame(['foo', 'bar'], $name->parts);
 
         $name = new Name('foo\bar');
-        $this->assertSame(array('foo', 'bar'), $name->parts);
+        $this->assertSame(['foo', 'bar'], $name->parts);
 
         $name = new Name($name);
-        $this->assertSame(array('foo', 'bar'), $name->parts);
+        $this->assertSame(['foo', 'bar'], $name->parts);
     }
 
     public function testGet() {
@@ -26,10 +28,11 @@
     }
 
     public function testToString() {
-        $name = new Name('foo\bar');
+        $name = new Name('Foo\Bar');
 
-        $this->assertSame('foo\bar', (string) $name);
-        $this->assertSame('foo\bar', $name->toString());
+        $this->assertSame('Foo\Bar', (string) $name);
+        $this->assertSame('Foo\Bar', $name->toString());
+        $this->assertSame('foo\bar', $name->toLowerString());
     }
 
     public function testSlice() {
@@ -98,37 +101,73 @@
         $this->assertNull(Name::concat(null, null));
     }
 
-    public function testIs() {
+    public function testNameTypes() {
         $name = new Name('foo');
-        $this->assertTrue ($name->isUnqualified());
+        $this->assertTrue($name->isUnqualified());
         $this->assertFalse($name->isQualified());
         $this->assertFalse($name->isFullyQualified());
         $this->assertFalse($name->isRelative());
+        $this->assertSame('foo', $name->toCodeString());
 
         $name = new Name('foo\bar');
         $this->assertFalse($name->isUnqualified());
-        $this->assertTrue ($name->isQualified());
+        $this->assertTrue($name->isQualified());
         $this->assertFalse($name->isFullyQualified());
         $this->assertFalse($name->isRelative());
+        $this->assertSame('foo\bar', $name->toCodeString());
 
         $name = new Name\FullyQualified('foo');
         $this->assertFalse($name->isUnqualified());
         $this->assertFalse($name->isQualified());
-        $this->assertTrue ($name->isFullyQualified());
+        $this->assertTrue($name->isFullyQualified());
         $this->assertFalse($name->isRelative());
+        $this->assertSame('\foo', $name->toCodeString());
 
         $name = new Name\Relative('foo');
         $this->assertFalse($name->isUnqualified());
         $this->assertFalse($name->isQualified());
         $this->assertFalse($name->isFullyQualified());
-        $this->assertTrue ($name->isRelative());
+        $this->assertTrue($name->isRelative());
+        $this->assertSame('namespace\foo', $name->toCodeString());
     }
 
     /**
-     * @expectedException        \InvalidArgumentException
+     * @expectedException \InvalidArgumentException
      * @expectedExceptionMessage Expected string, array of parts or Name instance
      */
     public function testInvalidArg() {
         Name::concat('foo', new \stdClass);
     }
-}
\ No newline at end of file
+
+    /**
+     * @expectedException \InvalidArgumentException
+     * @expectedExceptionMessage Name cannot be empty
+     */
+    public function testInvalidEmptyString() {
+        new Name('');
+    }
+
+    /**
+     * @expectedException \InvalidArgumentException
+     * @expectedExceptionMessage Name cannot be empty
+     */
+    public function testInvalidEmptyArray() {
+        new Name([]);
+    }
+
+    /** @dataProvider provideTestIsSpecialClassName */
+    public function testIsSpecialClassName($name, $expected) {
+        $name = new Name($name);
+        $this->assertSame($expected, $name->isSpecialClassName());
+    }
+
+    public function provideTestIsSpecialClassName() {
+        return [
+            ['self', true],
+            ['PARENT', true],
+            ['Static', true],
+            ['self\not', false],
+            ['not\self', false],
+        ];
+    }
+}