‪TYPO3CMS  ‪main
CorrelationIdTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪CorrelationIdTest extends UnitTestCase
26 {
27  public static function ‪canBeParsedDataProvider(): array
28  {
29  return [
30  [
31  '0400$subject',
32  ['scope' => null, 'subject' => 'subject', 'aspects' => []],
33  ],
34  [
35  '0400$scope:subject',
36  ['scope' => 'scope', 'subject' => 'subject', 'aspects' => []],
37  ],
38  [
39  '0400$scope:subject/aspect-a',
40  ['scope' => 'scope', 'subject' => 'subject', 'aspects' => ['aspect-a']],
41  ],
42  [
43  '0400$scope:subject/aspect-a/aspect-b',
44  ['scope' => 'scope', 'subject' => 'subject', 'aspects' => ['aspect-a', 'aspect-b']],
45  ],
46  ];
47  }
48 
49  #[DataProvider('canBeParsedDataProvider')]
50  #[Test]
51  public function ‪canBeParsed(string $string, array $expectations): void
52  {
53  $correlationId = ‪CorrelationId::fromString($string);
54  foreach ($expectations as $propertyName => $propertyValue) {
55  self::assertSame(
56  $propertyValue,
57  $correlationId->{'get' . ucfirst($propertyName)}()
58  );
59  }
60  }
61 
62  #[Test]
63  public function ‪subjectIsConsidered(): void
64  {
65  $correlationId = ‪CorrelationId::forSubject('subject')
66  ->withAspects('aspect-a');
67  self::assertSame('0400$subject/aspect-a', (string)$correlationId);
68  }
69 
70  #[Test]
71  public function ‪scopeIsConsidered(): void
72  {
73  $correlationId = ‪CorrelationId::forScope('scope')
74  ->withSubject('subject')
75  ->withAspects('aspect-a');
76  self::assertSame('0400$scope:subject/aspect-a', (string)$correlationId);
77  }
78 
79  #[Test]
80  public function ‪doesNotVary(): void
81  {
82  $correlationId = '0400$scope:subject/aspect-a/aspect-b';
83  self::assertSame(
84  $correlationId,
85  (string)‪CorrelationId::fromString($correlationId)
86  );
87  }
88 }
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Model
Definition: CorrelationIdTest.php:18
‪TYPO3\CMS\Core\DataHandling\Model\CorrelationId\forScope
‪static forScope(string $scope)
Definition: CorrelationId.php:42
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Model\CorrelationIdTest\scopeIsConsidered
‪scopeIsConsidered()
Definition: CorrelationIdTest.php:71
‪TYPO3\CMS\Core\DataHandling\Model\CorrelationId\fromString
‪static fromString(string $correlationId)
Definition: CorrelationId.php:56
‪TYPO3\CMS\Core\DataHandling\Model\CorrelationId
Definition: CorrelationId.php:29
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Model\CorrelationIdTest\subjectIsConsidered
‪subjectIsConsidered()
Definition: CorrelationIdTest.php:63
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Model\CorrelationIdTest
Definition: CorrelationIdTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Model\CorrelationIdTest\canBeParsedDataProvider
‪static canBeParsedDataProvider()
Definition: CorrelationIdTest.php:27
‪TYPO3\CMS\Core\DataHandling\Model\CorrelationId\forSubject
‪static forSubject(string $subject, string ... $aspects)
Definition: CorrelationId.php:49
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Model\CorrelationIdTest\canBeParsed
‪canBeParsed(string $string, array $expectations)
Definition: CorrelationIdTest.php:51
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\Model\CorrelationIdTest\doesNotVary
‪doesNotVary()
Definition: CorrelationIdTest.php:80