Verified Commit 78399e08 authored by Dave Long's avatar Dave Long
Browse files

task: #3549629 Fix LongLineDeclaration in Tests/Component

By: quietone
By: mstrelan
By: longwave
(cherry picked from commit bdf59040)
parent dc40b4e7
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@
    <include-pattern>core/modules/*/tests/modules/*</include-pattern>
    <include-pattern>core/modules/*/Plugin/*</include-pattern>
    <include-pattern>core/modules/*/Form/*</include-pattern>
    <include-pattern>core/tests/Drupal/Tests/Component/*</include-pattern>
  </rule>
  <rule ref="Drupal.Classes.ClassCreateInstance"/>
  <rule ref="Drupal.Classes.ClassDeclaration"/>
+192 −22
Original line number Diff line number Diff line
@@ -420,15 +420,45 @@ public static function providerTestInvalidDates(): array {
    return [
      // Test for invalid month names when we are using a short version
      // of the month.
      ['23 abc 2012', NULL, 'd M Y', "23 abc 2012 contains an invalid month name and did not produce errors.", \InvalidArgumentException::class],
      [
        '23 abc 2012',
        NULL,
        'd M Y',
        "23 abc 2012 contains an invalid month name and did not produce errors.",
        \InvalidArgumentException::class,
      ],
      // Test for invalid hour.
      ['0000-00-00T45:30:00', NULL, 'Y-m-d\TH:i:s', "0000-00-00T45:30:00 contains an invalid hour and did not produce errors.", \UnexpectedValueException::class],
      [
        '0000-00-00T45:30:00',
        NULL,
        'Y-m-d\TH:i:s',
        "0000-00-00T45:30:00 contains an invalid hour and did not produce errors.",
        \UnexpectedValueException::class,
      ],
      // Test for invalid day.
      ['0000-00-99T05:30:00', NULL, 'Y-m-d\TH:i:s', "0000-00-99T05:30:00 contains an invalid day and did not produce errors.", \UnexpectedValueException::class],
      [
        '0000-00-99T05:30:00',
        NULL,
        'Y-m-d\TH:i:s',
        "0000-00-99T05:30:00 contains an invalid day and did not produce errors.",
        \UnexpectedValueException::class,
      ],
      // Test for invalid month.
      ['0000-75-00T15:30:00', NULL, 'Y-m-d\TH:i:s', "0000-75-00T15:30:00 contains an invalid month and did not produce errors.", \UnexpectedValueException::class],
      [
        '0000-75-00T15:30:00',
        NULL,
        'Y-m-d\TH:i:s',
        "0000-75-00T15:30:00 contains an invalid month and did not produce errors.",
        \UnexpectedValueException::class,
      ],
      // Test for invalid year.
      ['11-08-01T15:30:00', NULL, 'Y-m-d\TH:i:s', "11-08-01T15:30:00 contains an invalid year and did not produce errors.", \UnexpectedValueException::class],
      [
        '11-08-01T15:30:00',
        NULL,
        'Y-m-d\TH:i:s',
        "11-08-01T15:30:00 contains an invalid year and did not produce errors.",
        \UnexpectedValueException::class,
      ],

    ];
  }
@@ -446,17 +476,76 @@ public static function providerTestInvalidDates(): array {
  public static function providerTestInvalidDateArrays(): array {
    return [
      // One year larger than the documented upper limit of checkdate().
      [['year' => 32768, 'month' => 1, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0], 'America/Chicago', \InvalidArgumentException::class],
      [
        [
          'year' => 32768,
          'month' => 1,
          'day' => 8,
          'hour' => 8,
          'minute' => 0,
          'second' => 0,
        ],
        'America/Chicago',
        \InvalidArgumentException::class,
      ],
      // One year smaller than the documented lower limit of checkdate().
      [['year' => 0, 'month' => 1, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0], 'America/Chicago', \InvalidArgumentException::class],
      [
        [
          'year' => 0,
          'month' => 1,
          'day' => 8,
          'hour' => 8,
          'minute' => 0,
          'second' => 0,
        ],
        'America/Chicago',
        \InvalidArgumentException::class,
      ],
      // Test for invalid month from date array.
      [['year' => 2010, 'month' => 27, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0], 'America/Chicago', \InvalidArgumentException::class],
      [
        [
          'year' => 2010,
          'month' => 27,
          'day' => 8,
          'hour' => 8,
          'minute' => 0,
          'second' => 0,
        ],
        'America/Chicago',
        \InvalidArgumentException::class,
      ],
      // Test for invalid hour from date array.
      [['year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 80, 'minute' => 0, 'second' => 0], 'America/Chicago', \InvalidArgumentException::class],
      [
        [
          'year' => 2010,
          'month' => 2,
          'day' => 28,
          'hour' => 80,
          'minute' => 0,
          'second' => 0,
        ],
        'America/Chicago',
        \InvalidArgumentException::class,
      ],
      // Test for invalid minute from date array.
      [['year' => 2010, 'month' => 7, 'day' => 8, 'hour' => 8, 'minute' => 88, 'second' => 0], 'America/Chicago', \InvalidArgumentException::class],
      [
        [
          'year' => 2010,
          'month' => 7,
          'day' => 8,
          'hour' => 8,
          'minute' => 88,
          'second' => 0,
        ],
        'America/Chicago',
        \InvalidArgumentException::class,
      ],
      // Regression test for https://www.drupal.org/node/2084455.
      [['hour' => 59, 'minute' => 1, 'second' => 1], 'America/Chicago', \InvalidArgumentException::class],
      [
        ['hour' => 59, 'minute' => 1, 'second' => 1],
        'America/Chicago',
        \InvalidArgumentException::class,
      ],
    ];
  }

@@ -472,13 +561,74 @@ public static function providerTestInvalidDateArrays(): array {
   */
  public static function providerTestCheckArray(): array {
    return [
      'Date array, date only' => [['year' => 2010, 'month' => 2, 'day' => 28], TRUE],
      'Date array with hour' => [['year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10], TRUE],
      'One year larger than the documented upper limit of checkdate()' => [['year' => 32768, 'month' => 1, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0], FALSE],
      'One year smaller than the documented lower limit of checkdate()' => [['year' => 0, 'month' => 1, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0], FALSE],
      'Invalid month from date array' => [['year' => 2010, 'month' => 27, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0], FALSE],
      'Invalid hour from date array' => [['year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 80, 'minute' => 0, 'second' => 0], FALSE],
      'Invalid minute from date array.' => [['year' => 2010, 'month' => 7, 'day' => 8, 'hour' => 8, 'minute' => 88, 'second' => 0], FALSE],
      'Date array, date only' => [
        ['year' => 2010, 'month' => 2, 'day' => 28],
        TRUE,
      ],
      'Date array with hour' => [
        [
          'year' => 2010,
          'month' => 2,
          'day' => 28,
          'hour' => 10,
        ],
        TRUE,
      ],
      'One year larger than the documented upper limit of checkdate()' => [
        [
          'year' => 32768,
          'month' => 1,
          'day' => 8,
          'hour' => 8,
          'minute' => 0,
          'second' => 0,
        ],
        FALSE,
      ],
      'One year smaller than the documented lower limit of checkdate()' => [
        [
          'year' => 0,
          'month' => 1,
          'day' => 8,
          'hour' => 8,
          'minute' => 0,
          'second' => 0,
        ],
        FALSE,
      ],
      'Invalid month from date array' => [
        [
          'year' => 2010,
          'month' => 27,
          'day' => 8,
          'hour' => 8,
          'minute' => 0,
          'second' => 0,
        ],
        FALSE,
      ],
      'Invalid hour from date array' => [
        [
          'year' => 2010,
          'month' => 2,
          'day' => 28,
          'hour' => 80,
          'minute' => 0,
          'second' => 0,
        ],
        FALSE,
      ],
      'Invalid minute from date array.' => [
        [
          'year' => 2010,
          'month' => 7,
          'day' => 8,
          'hour' => 8,
          'minute' => 88,
          'second' => 0,
        ],
        FALSE,
      ],
      'Missing day' => [['year' => 2059, 'month' => 1, 'second' => 1], FALSE],
      'Zero day' => [['year' => 2059, 'month' => 1, 'day' => 0], FALSE],
    ];
@@ -507,13 +657,33 @@ public static function providerTestDateTimezone(): array {
    return [
      // Create a date object with an unspecified timezone, which should
      // end up using the system timezone.
      [$date_string, NULL, $system_timezone, 'DateTimePlus uses the system timezone when there is no site timezone.'],
      [
        $date_string,
        NULL,
        $system_timezone,
        'DateTimePlus uses the system timezone when there is no site timezone.',
      ],
      // Create a date object with a specified timezone name.
      [$date_string, 'America/Yellowknife', 'America/Yellowknife', 'DateTimePlus uses the specified timezone if provided.'],
      [
        $date_string,
        'America/Yellowknife',
        'America/Yellowknife',
        'DateTimePlus uses the specified timezone if provided.',
      ],
      // Create a date object with a timezone object.
      [$date_string, new \DateTimeZone('Australia/Canberra'), 'Australia/Canberra', 'DateTimePlus uses the specified timezone if provided.'],
      [
        $date_string,
        new \DateTimeZone('Australia/Canberra'),
        'Australia/Canberra',
        'DateTimePlus uses the specified timezone if provided.',
      ],
      // Create a date object with another date object.
      [new DateTimePlus('now', 'Pacific/Midway'), NULL, 'Pacific/Midway', 'DateTimePlus uses the specified timezone if provided.'],
      [
        new DateTimePlus('now', 'Pacific/Midway'),
        NULL,
        'Pacific/Midway',
        'DateTimePlus uses the specified timezone if provided.',
      ],
    ];
  }

+4 −1
Original line number Diff line number Diff line
@@ -129,7 +129,10 @@ public function testDiffInfiniteLoop(): void {
    $this->assertCount(4, $diffOps);
    $this->assertEquals($diffOps[0], new DiffOpAdd(['    - image.style.max_325x325']));
    $this->assertEquals($diffOps[1], new DiffOpCopy(['    - image.style.max_650x650']));
    $this->assertEquals($diffOps[2], new DiffOpChange(['    - image.style.max_325x325'], ['_core:', '  default_config_hash: random_hash_string_here']));
    $this->assertEquals($diffOps[2], new DiffOpChange(
      ['    - image.style.max_325x325'],
      ['_core:', '  default_config_hash: random_hash_string_here'],
    ));
    $this->assertEquals($diffOps[3], new DiffOpCopy(['fallback_image_style: max_325x325', '']));
  }

+56 −7
Original line number Diff line number Diff line
@@ -84,18 +84,60 @@ public function testDiscovery(): void {

    // The file path is dependent on the operating system, so we adjust the
    // directory separator.
    $this->assertSame(['id' => 'item1', 'name' => 'test1 item 1', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/subdir1' . DIRECTORY_SEPARATOR . 'item_1.test.yml'], $data['test_1']['item1']);
    $this->assertSame(['id' => 'item2', 'name' => 'test1 item 2', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/subdir2' . DIRECTORY_SEPARATOR . 'item_2.test.yml'], $data['test_1']['item2']);
    $this->assertSame(
      [
        'id' => 'item1',
        'name' => 'test1 item 1',
        YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/subdir1' . DIRECTORY_SEPARATOR . 'item_1.test.yml',
      ],
      $data['test_1']['item1'],
    );
    $this->assertSame(
      [
        'id' => 'item2',
        'name' => 'test1 item 2',
        YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/subdir2' . DIRECTORY_SEPARATOR . 'item_2.test.yml',
      ],
      $data['test_1']['item2'],
    );
    $this->assertCount(2, $data['test_1']);

    $this->assertSame(['id' => 'item3', 'name' => 'test2 item 3', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_2/subdir1' . DIRECTORY_SEPARATOR . 'item_3.test.yml'], $data['test_2']['item3']);
    $this->assertSame(
      [
        'id' => 'item3',
        'name' => 'test2 item 3',
        YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_2/subdir1' . DIRECTORY_SEPARATOR . 'item_3.test.yml',
      ],
      $data['test_2']['item3'],
    );
    $this->assertCount(1, $data['test_2']);

    $this->assertArrayNotHasKey('test_3', $data, 'test_3 provides 0 items');

    $this->assertSame(['id' => 'item4', 'name' => 'test4 item 4', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1' . DIRECTORY_SEPARATOR . 'item_4.test.yml'], $data['test_4']['item4']);
    $this->assertSame(['id' => 'item5', 'name' => 'test4 item 5', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1' . DIRECTORY_SEPARATOR . 'item_5.test.yml'], $data['test_4']['item5']);
    $this->assertSame(['id' => 'item6', 'name' => 'test4 item 6', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1' . DIRECTORY_SEPARATOR . 'item_6.test.yml'], $data['test_4']['item6']);
    $this->assertSame(
      [
        'id' => 'item4',
        'name' => 'test4 item 4',
        YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1' . DIRECTORY_SEPARATOR . 'item_4.test.yml',
      ],
      $data['test_4']['item4'],
    );
    $this->assertSame(
      [
        'id' => 'item5',
        'name' => 'test4 item 5',
        YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1' . DIRECTORY_SEPARATOR . 'item_5.test.yml',
      ],
      $data['test_4']['item5'],
    );
    $this->assertSame(
      [
        'id' => 'item6',
        'name' => 'test4 item 6',
        YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1' . DIRECTORY_SEPARATOR . 'item_6.test.yml',
      ],
      $data['test_4']['item6'],
    );
    $this->assertCount(3, $data['test_4']);
  }

@@ -117,7 +159,14 @@ public function testDiscoveryAlternateId(): void {
    $discovery = new YamlDirectoryDiscovery($directories, 'test', 'alt_id');
    $data = $discovery->findAll();

    $this->assertSame(['alt_id' => 'item1', 'id' => 'ignored', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1' . DIRECTORY_SEPARATOR . 'item_1.test.yml'], $data['test_1']['item1']);
    $this->assertSame(
      [
        'alt_id' => 'item1',
        'id' => 'ignored',
        YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1' . DIRECTORY_SEPARATOR . 'item_1.test.yml',
      ],
      $data['test_1']['item1'],
    );
    $this->assertCount(1, $data['test_1']);
  }

+4 −1
Original line number Diff line number Diff line
@@ -136,7 +136,10 @@ public function testGetDefinitionsMissingTrait(): void {
      $this->assertNull($file_cache->get($non_discoverable_file_path));
    }

    $discovery = new AttributeClassDiscovery(['com\example' => [$discovery_path], 'Drupal\a_module_that_does_not_exist' => [$discovery_path]]);
    $discovery = new AttributeClassDiscovery([
      'com\example' => [$discovery_path],
      'Drupal\a_module_that_does_not_exist' => [$discovery_path],
    ]);
    $this->assertEquals([
      'discovery_test_1' => [
        'id' => 'discovery_test_1',
Loading