Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Use actual test in expectations #42

Merged
merged 1 commit into from
Jan 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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