Skip to content

Commit

Permalink
Calling the Include::path() method will no longer create the directory
Browse files Browse the repository at this point in the history
It feels weird that this creates the directory, and it violates the principle of least astonishment as it's surprising that this creates a directory when you just request the path. Fixes #1706
  • Loading branch information
caendesilva committed Apr 30, 2024
1 parent a954901 commit 8dc4a52
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ This serves two purposes:
- The `hasFeature` method on the Hyde facade and HydeKernel now only accepts a Feature enum value instead of a string for its parameter.
- Changed how the documentation search is generated, to be an `InMemoryPage` instead of a post-build task.
- Media asset files are now copied using the new build task instead of the deprecated `BuildService::transferMediaAssets()` method.
- Calling the `Include::path()` method will no longer create the includes directory in https://github.com/hydephp/develop/pull/1707


### Deprecated
- for soon-to-be removed features.
Expand Down
5 changes: 0 additions & 5 deletions packages/framework/src/Support/Includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Hyde\Hyde;
use Hyde\Markdown\Models\Markdown;
use Illuminate\Support\Facades\Blade;
use Hyde\Framework\Concerns\InteractsWithDirectories;

use function basename;
use function file_exists;
Expand All @@ -20,8 +19,6 @@
*/
class Includes
{
use InteractsWithDirectories;

/**
* @var string The directory where includes are stored.
*/
Expand All @@ -35,8 +32,6 @@ class Includes
*/
public static function path(?string $filename = null): string
{
static::needsDirectory(static::$includesDirectory);

return $filename === null
? Hyde::path(static::$includesDirectory)
: Hyde::path(static::$includesDirectory.'/'.$filename);
Expand Down
22 changes: 14 additions & 8 deletions packages/framework/tests/Feature/IncludesFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
*/
class IncludesFacadeTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

File::makeDirectory(Includes::path(), recursive: true);
}

public function tearDown(): void
{
File::deleteDirectory(Includes::path());

parent::tearDown();
}

public function testPathReturnsTheIncludesDirectory()
{
$this->assertSame(
Expand All @@ -31,14 +45,6 @@ public function testPathReturnsAPartialWithinTheIncludesDirectory()
);
}

public function testPathCreatesDirectoryIfItDoesNotExist()
{
$path = Includes::path();
File::deleteDirectory($path);
$this->assertFalse(File::exists($path));
$this->assertTrue(File::exists(Includes::path()));
}

public function testGetReturnsPartial()
{
$expected = 'foo bar';
Expand Down

0 comments on commit 8dc4a52

Please sign in to comment.