generated from ergebnis/php-cs-fixer-config-template
/
FileTest.php
104 lines (79 loc) 路 2.37 KB
/
FileTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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';
}
}