generated from ergebnis/php-cs-fixer-config-template
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cdb7ec
commit e1a1fc4
Showing
7 changed files
with
297 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\License; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class File | ||
{ | ||
private $years; | ||
|
||
private $holder; | ||
|
||
private $template; | ||
|
||
private function __construct(Copyright\Years $years, Copyright\Holder $holder, Template $template) | ||
{ | ||
$this->years = $years; | ||
$this->holder = $holder; | ||
$this->template = $template; | ||
} | ||
|
||
public static function create(Copyright\Years $years, Copyright\Holder $holder, Template $template): self | ||
{ | ||
return new self( | ||
$years, | ||
$holder, | ||
$template | ||
); | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return $this->template->toString([ | ||
'<copyright-years>' => $this->years->toString(), | ||
'<copyright-holder>' => $this->holder->toString(), | ||
]); | ||
} | ||
|
||
public function saveAs(string $filename): void | ||
{ | ||
\file_put_contents( | ||
$filename, | ||
$this->toString() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\License; | ||
|
||
final class Template | ||
{ | ||
private $value; | ||
|
||
private function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public static function fromString(string $value): self | ||
{ | ||
return new self($value); | ||
} | ||
|
||
public function toString(array $replacements): string | ||
{ | ||
return \str_replace( | ||
\array_keys($replacements), | ||
$replacements, | ||
$this->value | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\Test\Unit\License; | ||
|
||
use Ergebnis\PhpCsFixer\Config\License\Copyright\Holder; | ||
use Ergebnis\PhpCsFixer\Config\License\Copyright\Year; | ||
use Ergebnis\PhpCsFixer\Config\License\Copyright\Years; | ||
use Ergebnis\PhpCsFixer\Config\License\File; | ||
use Ergebnis\PhpCsFixer\Config\License\Template; | ||
use Ergebnis\Test\Util\Helper; | ||
use PHPUnit\Framework; | ||
use Symfony\Component\Filesystem; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \Ergebnis\PhpCsFixer\Config\License\File | ||
* | ||
* @uses \Ergebnis\PhpCsFixer\Config\License\Copyright\Holder | ||
* @uses \Ergebnis\PhpCsFixer\Config\License\Copyright\Year | ||
* @uses \Ergebnis\PhpCsFixer\Config\License\Copyright\Years | ||
* @uses \Ergebnis\PhpCsFixer\Config\License\Template | ||
*/ | ||
final class FileTest extends Framework\TestCase | ||
{ | ||
use Helper; | ||
|
||
protected function setUp(): void | ||
{ | ||
$filesystem = new Filesystem\Filesystem(); | ||
|
||
$filesystem->mkdir(self::directory()); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
$filesystem = new Filesystem\Filesystem(); | ||
|
||
$filesystem->remove(self::directory()); | ||
} | ||
|
||
public function testCreateReturnsFile(): void | ||
{ | ||
$faker = self::faker(); | ||
|
||
$years = Years::fromYear(Year::fromString($faker->dateTime->format('Y'))); | ||
$holder = Holder::fromString($faker->name); | ||
|
||
$template = Template::fromString( | ||
<<<'EOF' | ||
Ah! | ||
This was done in <copyright-years> by <copyright-holder>. | ||
Who would have thought? | ||
|
||
EOF | ||
); | ||
|
||
$file = File::create( | ||
$years, | ||
$holder, | ||
$template | ||
); | ||
|
||
$expected = <<<EOF | ||
Ah! | ||
This was done in {$years->toString()} by {$holder->toString()}. | ||
Who would have thought? | ||
EOF; | ||
|
||
self::assertSame($expected, $file->toString()); | ||
|
||
$filename = \sprintf( | ||
'%s/%s', | ||
self::directory(), | ||
'example.txt' | ||
); | ||
|
||
$file->saveAs($filename); | ||
|
||
self::assertFileExists($filename); | ||
self::assertSame($expected, \file_get_contents($filename)); | ||
} | ||
|
||
private static function directory(): string | ||
{ | ||
return __DIR__ . '/../../../.build/test'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\Test\Unit\License; | ||
|
||
use Ergebnis\PhpCsFixer\Config\License\Template; | ||
use Ergebnis\Test\Util\Helper; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \Ergebnis\PhpCsFixer\Config\License\Template | ||
*/ | ||
final class TemplateTest extends Framework\TestCase | ||
{ | ||
use Helper; | ||
|
||
public function testCreateReturnsTemplate(): void | ||
{ | ||
$faker = self::faker(); | ||
|
||
$when = $faker->dateTime->format('Y'); | ||
$who = $faker->name; | ||
|
||
$template = Template::fromString( | ||
<<<'EOF' | ||
Ah! | ||
This was done in <when> by <who>. | ||
Who would have thought? | ||
|
||
EOF | ||
); | ||
|
||
$expected = <<<EOF | ||
Ah! | ||
This was done in {$when} by {$who}. | ||
Who would have thought? | ||
EOF; | ||
|
||
self::assertSame($expected, $template->toString([ | ||
'<when>' => $when, | ||
'<who>' => $who, | ||
])); | ||
} | ||
} |