Skip to content

Commit

Permalink
Fix: Use actual test in expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Jan 19, 2020
1 parent 8dc4927 commit c9a8fc3
Showing 1 changed file with 69 additions and 26 deletions.
95 changes: 69 additions & 26 deletions test/Unit/Type/MITTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use Ergebnis\License\Holder;
use Ergebnis\License\Range;
use Ergebnis\License\Template;
use Ergebnis\License\Type\MIT;
use Ergebnis\License\Url;
use Ergebnis\License\Year;
Expand Down Expand Up @@ -58,10 +57,14 @@ public function testHeaderReturnsHeaderForMarkdownLicense(): void
{
$faker = self::faker();

$baseName = \sprintf(
'%s.txt',
$faker->slug
);
$name = \sprintf(
'%s/%s.txt',
'%s/%s',
self::workspaceDirectory(),
$faker->slug
$baseName
);
$range = Range::since(
Year::fromString($faker->year),
Expand All @@ -77,12 +80,15 @@ public function testHeaderReturnsHeaderForMarkdownLicense(): void
$url
);

$expected = Template::fromFile(__DIR__ . '/../../../resource/header.txt')->toString([
'<file>' => \basename($name),
'<holder>' => $holder->toString(),
'<range>' => $range->toString(),
'<url>' => $url->toString(),
]);
$expected = <<<TXT
Copyright (c) {$range->toString()} {$holder->toString()}
For the full copyright and license information, please view
the {$baseName} file that was distributed with this source code.
@see {$url->toString()}
TXT;

self::assertSame($expected, $license->header());
}
Expand All @@ -92,10 +98,14 @@ public function testHeaderReturnsHeaderForTextLicense(): void
$faker = self::faker();

$name = \sprintf(
'%s/%s.txt',
self::workspaceDirectory(),
'%s.txt',
$faker->slug
);
$baseName = \sprintf(
'%s/%s',
self::workspaceDirectory(),
$name
);
$range = Range::since(
Year::fromString($faker->year),
new \DateTimeZone($faker->timezone)
Expand All @@ -104,18 +114,21 @@ public function testHeaderReturnsHeaderForTextLicense(): void
$url = Url::fromString($faker->url);

$license = MIT::text(
$name,
$baseName,
$range,
$holder,
$url
);

$expected = Template::fromFile(__DIR__ . '/../../../resource/header.txt')->toString([
'<file>' => \basename($name),
'<holder>' => $holder->toString(),
'<range>' => $range->toString(),
'<url>' => $url->toString(),
]);
$expected = <<<TXT
Copyright (c) {$range->toString()} {$holder->toString()}
For the full copyright and license information, please view
the {$name} file that was distributed with this source code.
@see {$url->toString()}
TXT;

self::assertSame($expected, $license->header());
}
Expand Down Expand Up @@ -147,10 +160,25 @@ public function testSaveSavesMarkdownToFileForMarkdownLicense(): void

self::assertFileExists($name);

$expected = Template::fromFile(__DIR__ . '/../../../resource/license/MIT.md')->toString([
'<holder>' => $holder->toString(),
'<range>' => $range->toString(),
]);
$expected = <<<TXT
# The MIT License (MIT)
Copyright (c) {$range->toString()} {$holder->toString()}
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the _Software_), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED **AS IS**, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
TXT;

self::assertSame($expected, \file_get_contents($name));
}
Expand Down Expand Up @@ -182,10 +210,25 @@ public function testSaveSavesTextToFileForTextLicense(): void

self::assertFileExists($name);

$expected = Template::fromFile(__DIR__ . '/../../../resource/license/MIT.txt')->toString([
'<holder>' => $holder->toString(),
'<range>' => $range->toString(),
]);
$expected = <<<TXT
The MIT License (MIT)
Copyright (c) {$range->toString()} {$holder->toString()}
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
TXT;

self::assertSame($expected, \file_get_contents($name));
}
Expand Down

0 comments on commit c9a8fc3

Please sign in to comment.