Skip to content

Commit

Permalink
v3
Browse files Browse the repository at this point in the history
  • Loading branch information
fenric committed Nov 1, 2024
1 parent d9a10f0 commit 7bf685f
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 41 deletions.
8 changes: 4 additions & 4 deletions src/Helper/ClassFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
final class ClassFinder
{
/**
* @return Generator<int, ReflectionClass<object>>
* @return Generator<class-string, ReflectionClass<object>>
*
* @throws InvalidArgumentException
* @throws ReflectionException
Expand Down Expand Up @@ -63,13 +63,13 @@ public static function getDirClasses(string $dirname): Generator
foreach (get_declared_classes() as $className) {
$classReflection = new ReflectionClass($className);
if (isset($filenames[$classReflection->getFileName()])) {
yield $classReflection;
yield $className => $classReflection;
}
}
}

/**
* @return Generator<int, ReflectionClass<object>>
* @return Generator<class-string, ReflectionClass<object>>
*
* @throws InvalidArgumentException
* @throws ReflectionException
Expand All @@ -91,7 +91,7 @@ public static function getFileClasses(string $filename): Generator
foreach (get_declared_classes() as $className) {
$classReflection = new ReflectionClass($className);
if ($classReflection->getFileName() === $filename) {
yield $classReflection;
yield $className => $classReflection;
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions tests/Entity/Language/ClientLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ final class ClientLanguageTest extends TestCase
{
public function testConstructor(): void
{
$language = new ClientLanguage('sr', 'sr-RS', ['q' => '1.0']);

$this->assertSame('sr', $language->getCode());
$this->assertSame('sr-RS', $language->getIdentifier());
$this->assertSame(['q' => '1.0'], $language->getParameters());
$clientLanguage = new ClientLanguage('sr', 'sr-RS', ['q' => '1.0']);
$this->assertSame('sr', $clientLanguage->getCode());
$this->assertSame('sr-RS', $clientLanguage->getIdentifier());
$this->assertSame(['q' => '1.0'], $clientLanguage->getParameters());
}
}
5 changes: 2 additions & 3 deletions tests/Entity/Language/ServerLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ final class ServerLanguageTest extends TestCase
{
public function testConstructor(): void
{
$language = new ServerLanguage('sr');

$this->assertSame('sr', $language->getCode());
$serverLanguage = new ServerLanguage('sr');
$this->assertSame('sr', $serverLanguage->getCode());
}
}
14 changes: 6 additions & 8 deletions tests/Entity/MediaType/ClientMediaTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ final class ClientMediaTypeTest extends TestCase
{
public function testConstructor(): void
{
$mediaType = new ClientMediaType('application', 'json', ['q' => '1.0']);

$this->assertSame('application', $mediaType->getType());
$this->assertSame('json', $mediaType->getSubtype());
$this->assertSame(['q' => '1.0'], $mediaType->getParameters());
$clientMediaType = new ClientMediaType('application', 'json', ['q' => '1.0']);
$this->assertSame('application', $clientMediaType->getType());
$this->assertSame('json', $clientMediaType->getSubtype());
$this->assertSame(['q' => '1.0'], $clientMediaType->getParameters());
}

public function testToString(): void
{
$mediaType = new ClientMediaType('application', 'json', ['q' => '1.0']);

$this->assertSame('application/json', (string) $mediaType);
$clientMediaType = new ClientMediaType('application', 'json', ['q' => '1.0']);
$this->assertSame('application/json', (string) $clientMediaType);
}
}
12 changes: 5 additions & 7 deletions tests/Entity/MediaType/ServerMediaTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ final class ServerMediaTypeTest extends TestCase
{
public function testConstructor(): void
{
$mediaType = new ServerMediaType('application', 'json');

$this->assertSame('application', $mediaType->getType());
$this->assertSame('json', $mediaType->getSubtype());
$serverMediaType = new ServerMediaType('application', 'json');
$this->assertSame('application', $serverMediaType->getType());
$this->assertSame('json', $serverMediaType->getSubtype());
}

public function testToString(): void
{
$mediaType = new ServerMediaType('application', 'json');

$this->assertSame('application/json', (string) $mediaType);
$serverMediaType = new ServerMediaType('application', 'json');
$this->assertSame('application/json', (string) $serverMediaType);
}
}
7 changes: 1 addition & 6 deletions tests/Event/RoutePostRunEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ protected function setUp(): void
public function testConstructor(): void
{
$event = new RoutePostRunEvent($this->routeMock, $this->serverRequestMock, $this->responseMock);

$this->assertSame($this->routeMock, $event->getRoute());
$this->assertSame($this->serverRequestMock, $event->getRequest());
$this->assertSame($this->responseMock, $event->getResponse());
Expand All @@ -36,11 +35,7 @@ public function testConstructor(): void
public function testSetResponse(): void
{
$event = new RoutePostRunEvent($this->routeMock, $this->serverRequestMock, $this->responseMock);

$newResponse = clone $this->responseMock;
$this->assertNotSame($this->responseMock, $newResponse);

$event->setResponse($newResponse);
$event->setResponse($newResponse = clone $this->responseMock);
$this->assertSame($newResponse, $event->getResponse());
}
}
7 changes: 1 addition & 6 deletions tests/Event/RoutePreRunEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ protected function setUp(): void
public function testConstructor(): void
{
$event = new RoutePreRunEvent($this->routeMock, $this->serverRequestMock);

$this->assertSame($this->routeMock, $event->getRoute());
$this->assertSame($this->serverRequestMock, $event->getRequest());
}

public function testSetRequest(): void
{
$event = new RoutePreRunEvent($this->routeMock, $this->serverRequestMock);

$newServerRequest = clone $this->serverRequestMock;
$this->assertNotSame($this->serverRequestMock, $newServerRequest);

$event->setRequest($newServerRequest);
$event->setRequest($newServerRequest = clone $this->serverRequestMock);
$this->assertSame($newServerRequest, $event->getRequest());
}
}
Loading

0 comments on commit 7bf685f

Please sign in to comment.