Skip to content

Commit

Permalink
Improved tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
danbettles committed Dec 19, 2022
1 parent 40d0044 commit 351c39f
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 69 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

No unreleased changes.

## [2.3.2] - 2022-12-19

### Changed

- Improved tests.

## [2.3.1] - 2022-12-03

### Fixed
Expand Down Expand Up @@ -58,7 +64,8 @@ No unreleased changes.

First stable release.

[unreleased]: https://github.com/danbettles/marigold/compare/v2.3.1...HEAD
[unreleased]: https://github.com/danbettles/marigold/compare/v2.3.2...HEAD
[2.3.2]: https://github.com/danbettles/marigold/compare/v2.3.1...v2.3.2
[2.3.1]: https://github.com/danbettles/marigold/compare/v2.3.0...v2.3.1
[2.3.0]: https://github.com/danbettles/marigold/compare/v2.2.1...v2.3.0
[2.2.1]: https://github.com/danbettles/marigold/compare/v2.2.0...v2.2.1
Expand Down
10 changes: 5 additions & 5 deletions tests/src/CssMinifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class CssMinifierTest extends AbstractTestCase
{
/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesCssWithCommentsRemoved(): array
{
return [
Expand Down Expand Up @@ -50,7 +50,7 @@ public function testRemovecommentsfilterRemovesComments(
$this->assertSame($expected, $minified);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesCssWithSuperfluousWhitespaceRemoved(): array
{
return [
Expand Down Expand Up @@ -111,7 +111,7 @@ public function testRemovesuperfluouswhitespacefilterRemovesSuperfluousWhitespac
$this->assertSame($expected, $minified);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesCssContainingZeroesWithUnitsRemoved(): array
{
return [
Expand Down Expand Up @@ -140,7 +140,7 @@ public function testRemoveunitsfromzeroesfilterRemovesUnitsFromZeroes(
$this->assertSame($expected, $minified);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesCssContainingHexColoursThatHaveBeenCondensed(): array
{
return [
Expand Down Expand Up @@ -169,7 +169,7 @@ public function testCondensehexcoloursfilterCondensesHexColours(
$this->assertSame($expected, $minified);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesCssThatHasBeenMinified(): array
{
return [
Expand Down
7 changes: 3 additions & 4 deletions tests/src/Exception/FileNotFoundExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ public function testIsARuntimeexception(): void
$this->assertTrue($this->getTestedClass()->isSubclassOf(RuntimeException::class));
}

public function testCanBeThrown(): void
public function testGetmessageReturnsAHelpfulMessage(): void
{
$pathname = $this->createFixturePathname('non_existent.file');

$this->expectException(FileNotFoundException::class);
$this->expectExceptionMessage("File `{$pathname}` does not exist.");
$ex = new FileNotFoundException($pathname);

throw new FileNotFoundException($pathname);
$this->assertSame("File `{$pathname}` does not exist.", $ex->getMessage());
}
}
39 changes: 26 additions & 13 deletions tests/src/Exception/HttpExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,42 @@ public function testIsARuntimeexception(): void
$this->assertTrue($this->getTestedClass()->isSubclassOf(RuntimeException::class));
}

public function testCanBeThrown(): void
/** @return array<mixed[]> */
public function providesArguments(): array
{
$this->expectException(HttpException::class);
$this->expectExceptionMessage('404 Not Found');

throw new HttpException(404);
return [
[
'404 Not Found',
[404],
],
[
'404 Not Found: Article #123',
[404, 'Article #123'],
],
];
}

public function testCanBeThrownWithASpecifier(): void
{
$this->expectException(HttpException::class);
$this->expectExceptionMessage('404 Not Found: Article #123');

throw new HttpException(404, 'Article #123');
/**
* @dataProvider providesArguments
* @param array{0:int,1?:string} $arguments
*/
public function testGetmessageReturnsAHelpfulMessage(
string $expectedMessage,
array $arguments
): void {
$ex = new HttpException(...$arguments);

$this->assertSame($expectedMessage, $ex->getMessage());
}

public function testTheHttpStatusCodeIsAccessible(): void
{
$expectedStatusCode = 500;

$httpException = new HttpException($expectedStatusCode);

$this->assertSame($expectedStatusCode, $httpException->getCode());
$this->assertSame($httpException->getCode(), $httpException->getStatusCode());
$this->assertSame($expectedStatusCode, $httpException->getStatusCode());
$this->assertSame($httpException->getStatusCode(), $httpException->getCode());
}

public function testGetstatustextReturnsTheStatusText(): void
Expand Down
34 changes: 23 additions & 11 deletions tests/src/Exception/InternalServerErrorHttpExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,31 @@ public function testIsAnHttpexception(): void
$this->assertTrue($this->getTestedClass()->isSubclassOf(HttpException::class));
}

public function testCanBeThrown(): void
/** @return array<mixed[]> */
public function providesArguments(): array
{
$this->expectException(InternalServerErrorHttpException::class);
$this->expectExceptionMessage('500 Internal Server Error');

throw new InternalServerErrorHttpException();
return [
[
'500 Internal Server Error',
[],
],
[
'500 Internal Server Error: Failed to do something.',
['Failed to do something.'],
],
];
}

public function testCanBeThrownWithASpecifier(): void
{
$this->expectException(InternalServerErrorHttpException::class);
$this->expectExceptionMessage('500 Internal Server Error: Failed to do something.');

throw new InternalServerErrorHttpException('Failed to do something.');
/**
* @dataProvider providesArguments
* @param array{0?:string} $arguments
*/
public function testGetmessageReturnsAHelpfulMessage(
string $expectedMessage,
array $arguments
): void {
$ex = new InternalServerErrorHttpException(...$arguments);

$this->assertSame($expectedMessage, $ex->getMessage());
}
}
34 changes: 23 additions & 11 deletions tests/src/Exception/NotFoundHttpExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,31 @@ public function testIsAnHttpexception(): void
$this->assertTrue($this->getTestedClass()->isSubclassOf(HttpException::class));
}

public function testCanBeThrown(): void
/** @return array<mixed[]> */
public function providesArguments(): array
{
$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('404 Not Found');

throw new NotFoundHttpException();
return [
[
'404 Not Found',
[],
],
[
'404 Not Found: Article #123',
['Article #123'],
],
];
}

public function testCanBeThrownWithASpecifier(): void
{
$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('404 Not Found: Article #123');

throw new NotFoundHttpException('Article #123');
/**
* @dataProvider providesArguments
* @param array{0?:string} $arguments
*/
public function testGetmessageReturnsAHelpfulMessage(
string $expectedMessage,
array $arguments
): void {
$ex = new NotFoundHttpException(...$arguments);

$this->assertSame($expectedMessage, $ex->getMessage());
}
}
2 changes: 1 addition & 1 deletion tests/src/FileInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testIsASplfileinfo(): void
$this->assertTrue($this->getTestedClass()->isSubclassOf(SplFileInfo::class));
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesExistentFileMetadata(): array
{
return [
Expand Down
6 changes: 3 additions & 3 deletions tests/src/OutputHelper/Html5OutputHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testIsAXmloutputhelper(): void
$this->assertTrue($this->getTestedClass()->isSubclassOf(XmlOutputHelper::class));
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesAttributesStrings(): array
{
return [
Expand Down Expand Up @@ -76,7 +76,7 @@ public function testCreateattributesCanCreateBooleanAttributes(
$this->assertSame($expected, $helper->createAttributes($input));
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesBooleanAttributesWithInvalidNames(): array
{
return [
Expand Down Expand Up @@ -129,7 +129,7 @@ public function testCreateattributesThrowsAnExceptionIfABooleanAttributeNameIsIn
(new Html5OutputHelper())->createAttributes($attrsWithInvalidNames);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesArgsForVoidElements(): array
{
return [
Expand Down
10 changes: 5 additions & 5 deletions tests/src/OutputHelper/XmlOutputHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testGetencodingReturnsTheEncodingSetUsingSetencoding(): void
$this->assertSame($helper, $something);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesEscapedStrings(): array
{
return [
Expand Down Expand Up @@ -82,7 +82,7 @@ public function testEscapeUsesTheEncoding(): void
$this->assertNotSame($sourceUtf8Str, $helperMock->escape($sourceUtf8Str));
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesAttributesStrings(): array
{
return [
Expand Down Expand Up @@ -157,7 +157,7 @@ public function testCreateattributesUsesEscape(): void
$this->assertSame('foo="bar" baz="qux"', $attributesStr);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesAttributesWithInvalidNames(): array
{
return [
Expand Down Expand Up @@ -210,7 +210,7 @@ public function testCreateattributesThrowsAnExceptionIfAnAttributeNameIsInvalid(
(new XmlOutputHelper())->createAttributes($attributesWithInvalidNames);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesAttributesWithInvalidValues(): array
{
return [
Expand Down Expand Up @@ -309,7 +309,7 @@ public function testCreateelUsesCreateattributes(): void
);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesInvalidContent(): array
{
return [
Expand Down
10 changes: 5 additions & 5 deletions tests/src/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testIsInstantiable(): void
$this->assertSame([], $registry->getElements());
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesElements(): array
{
return [
Expand Down Expand Up @@ -82,7 +82,7 @@ public function doNothing(): void
{
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesFactories(): array
{
return [
Expand Down Expand Up @@ -144,7 +144,7 @@ public function testMultipleFactoriesCanBeAddedByCallingAddfactoryRepeatedly():
], $registry->getFactories());
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesLoadedRegistries(): array
{
return [
Expand Down Expand Up @@ -181,7 +181,7 @@ public function testAddfactoryThrowsAnExceptionIfTheIdAlreadyExists(Registry $re
});
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesInvalidFactories(): array
{
return [
Expand Down Expand Up @@ -231,7 +231,7 @@ public function testGetReturnsTheValueOfTheElementWithTheSpecifiedId(): void
$this->assertSame($expected, $registry->get('foo'));
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesRegistriesContainingFactories(): array
{
return [
Expand Down
10 changes: 5 additions & 5 deletions tests/src/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testThrowsAnExceptionIfThereAreNoRoutes(): void
new Router([]);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesRoutesContainingInvalid(): array
{
return [
Expand Down Expand Up @@ -116,7 +116,7 @@ public function testThrowsAnExceptionIfARouteIsInvalid(
new Router($routesContainingInvalid);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesMatchableRoutes(): array
{
return [
Expand Down Expand Up @@ -293,7 +293,7 @@ public function testMatchAttemptsToFindAMatchingRoute(
$this->assertSame($expectedRoute, $route);
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesUnmatchableRoutes(): array
{
return [
Expand Down Expand Up @@ -356,7 +356,7 @@ public function testMatchThrowsAnExceptionIfTheRequestDoesNotContainTheRequestUr
;
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesInvalidRequestUris(): array
{
return [
Expand Down Expand Up @@ -425,7 +425,7 @@ public function testGeneratepathThrowsAnExceptionIfThePathDoesNotExist(): void
;
}

/** @return array<int,array<int,mixed>> */
/** @return array<mixed[]> */
public function providesIncompleteArgsForGeneratepath(): array
{
return [
Expand Down
Loading

0 comments on commit 351c39f

Please sign in to comment.