Skip to content

Commit 6fda33c

Browse files
author
Andrey Helldar
committed
Added the ability to specify custom templates
1 parent ebf3601 commit 6fda33c

5 files changed

Lines changed: 69 additions & 3 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"php": "^7.2.5|^8.0",
1919
"ext-dom": "*",
2020
"ext-mbstring": "*",
21-
"andrey-helldar/support": "^2.0|^3.0"
21+
"andrey-helldar/support": "^3.4"
2222
},
2323
"require-dev": {
2424
"phpunit/phpunit": "^8.0|^9.0"

src/Services/File.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public function loadRaw(string $filename)
4242
return file_get_contents($filename);
4343
}
4444

45-
public function store(string $path): void
45+
public function store(string $path, string $stub = StubTool::PHP_ARRAY): void
4646
{
47-
$content = Stub::replace(StubTool::PHP_ARRAY, [
47+
$content = Stub::replace($stub, [
4848
'{{slot}}' => $this->content,
4949
]);
5050

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Helldar\PrettyArray\Services\File;
6+
7+
class FormatterStoringCustomStubText extends TestCase
8+
{
9+
public function testStoring()
10+
{
11+
$service = $this->service();
12+
13+
$service->setKeyAsString();
14+
$service->setEqualsAlign();
15+
16+
$array = $this->requireSource();
17+
$formatted = $service->raw($array);
18+
19+
$src_file = $this->path('custom-array.txt');
20+
$dst_file = $this->path('stored.php');
21+
22+
$stub = __DIR__ . '/stubs/custom.txt';
23+
24+
File::make($formatted)
25+
->store($dst_file, $stub);
26+
27+
$this->assertFileExists($dst_file);
28+
$this->assertFileEquals($src_file, $dst_file);
29+
}
30+
}

tests/stubs/custom-array.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
// Foo
4+
// Bar
5+
6+
/*
7+
* Foo Bar
8+
*/
9+
10+
return [
11+
'foo' => 1,
12+
'bar' => 2,
13+
'baz' => 3,
14+
'qwe rty' => 'qaz',
15+
'baq' => [
16+
'0' => 'qwe',
17+
'1' => 'rty',
18+
'asd' => 'zxc',
19+
],
20+
'asd fgh' => [
21+
'foo bar baz' => 'qwe',
22+
'2' => 'rty',
23+
'qaw sed' => 'zxc',
24+
],
25+
'2' => 'iop',
26+
];

tests/stubs/custom.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// Foo
4+
// Bar
5+
6+
/*
7+
* Foo Bar
8+
*/
9+
10+
return {{slot}};

0 commit comments

Comments
 (0)