Skip to content

Commit

Permalink
Update tags saver to use Yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jan 16, 2023
1 parent d2fbfad commit 970b681
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/publications/src/Models/PublicationTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function addTagsToGroup(string $name, array|string $values): self
*/
public function save(): self
{
Filesystem::putContents('tags.yml', json_encode($this->tags, JSON_PRETTY_PRINT));
Filesystem::putContents('tags.yml', Yaml::dump($this->tags->toArray()));

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ public function testCanCreateNewPublicationTag()

$this->assertFileExists(Hyde::path('tags.yml'));
$this->assertSame(
json_encode(['foo' => ['foo', 'bar', 'baz']], 128),
<<<'YAML'
foo:
- foo
- bar
- baz

YAML,
file_get_contents(Hyde::path('tags.yml'))
);
}
Expand All @@ -55,7 +61,13 @@ public function testCanCreateNewPublicationTagWithTagNameArgument()

$this->assertFileExists(Hyde::path('tags.yml'));
$this->assertSame(
json_encode(['foo' => ['foo', 'bar', 'baz']], 128),
<<<'YAML'
foo:
- foo
- bar
- baz

YAML,
file_get_contents(Hyde::path('tags.yml'))
);
}
Expand Down
14 changes: 6 additions & 8 deletions packages/publications/tests/Feature/PublicationTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,12 @@ public function testCanSaveTagsToDisk()
$tags->save();

$this->assertSame(
<<<'JSON'
{
"test": [
"test1",
"test2"
]
}
JSON, file_get_contents(Hyde::path('tags.yml'))
<<<'YAML'
test:
- test1
- test2

YAML, file_get_contents(Hyde::path('tags.yml'))
);

unlink(Hyde::path('tags.yml'));
Expand Down

0 comments on commit 970b681

Please sign in to comment.