Skip to content

Commit

Permalink
Merge pull request #475 from hydephp/breaking-namespace-changes
Browse files Browse the repository at this point in the history
Breaking namespace changes
  • Loading branch information
caendesilva authored Sep 8, 2022
2 parents f2f8c0d + 9a49b86 commit 5c7f991
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 141 deletions.
5 changes: 4 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ In general, these changes should only affect those who have written custom code
- Moved class DocumentationSidebar into Navigation namespace
- Moved class NavigationMenu into Navigation namespace
- Moved class NavItem into Navigation namespace
- Moved class FindsContentLengthForImageObject into Constructors namespace
- Merged interface RouteFacadeContract into existing interface RouteContract

- Renamed HydeBuildStaticSiteCommand to HydeBuildSiteCommand
- Renamed legacy FileCacheService to ViewDiffService

### Deprecated
- for soon-to-be removed features.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Hyde\Framework\Actions;
namespace Hyde\Framework\Actions\Constructors;

use Hyde\Framework\Contracts\ActionContract;
use Hyde\Framework\Hyde;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @see \Hyde\Framework\Testing\Feature\StaticSiteServiceTest
*/
class HydeBuildStaticSiteCommand extends Command
class HydeBuildSiteCommand extends Command
{
/**
* The signature of the command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Hyde\Framework\Actions\PublishesHomepageView;
use Hyde\Framework\Concerns\Commands\AsksToRebuildSite;
use Hyde\Framework\Hyde;
use Hyde\Framework\Services\FileCacheService;
use Hyde\Framework\Services\ViewDiffService;
use LaravelZero\Framework\Commands\Command;

/**
Expand Down Expand Up @@ -88,7 +88,7 @@ protected function canExistingIndexFileBeOverwritten(): bool
return true;
}

return FileCacheService::checksumMatchesAny(FileCacheService::unixsumFile(
return ViewDiffService::checksumMatchesAny(ViewDiffService::unixsumFile(
Hyde::getBladePagePath('index.blade.php')
)) || $this->option('force');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/HydeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function registerHydeConsoleCommands(): void
Commands\HydeUpdateConfigsCommand::class,
Commands\HydePublishViewsCommand::class,
Commands\HydeRebuildStaticSiteCommand::class,
Commands\HydeBuildStaticSiteCommand::class,
Commands\HydeBuildSiteCommand::class,
Commands\HydeBuildSitemapCommand::class,
Commands\HydeBuildRssFeedCommand::class,
Commands\HydeBuildSearchCommand::class,
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Hyde\Framework\Models;

use Hyde\Framework\Actions\FindsContentLengthForImageObject;
use Hyde\Framework\Actions\Constructors\FindsContentLengthForImageObject;
use Hyde\Framework\Hyde;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
/**
* Helper methods to interact with the filecache.
*
* @see \Hyde\Framework\Testing\Feature\Services\FileCacheServiceTest
* @see \Hyde\Framework\Testing\Unit\FileCacheServiceUnixsumMethodTest
* @see \Hyde\Framework\Testing\Feature\Services\ViewDiffServiceTest
*/
class FileCacheService
class ViewDiffService
{
public static function getFilecache(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Support\Facades\Http;

/**
* @covers \Hyde\Framework\Actions\FindsContentLengthForImageObject
* @covers \Hyde\Framework\Actions\Constructors\FindsContentLengthForImageObject
*/
class FindsContentLengthForImageObjectTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class BuildTaskServiceTest extends TestCase
{
/**
* @covers \Hyde\Framework\Commands\HydeBuildStaticSiteCommand::runPostBuildActions
* @covers \Hyde\Framework\Commands\HydeBuildSiteCommand::runPostBuildActions
*/
public function test_build_command_can_run_post_build_tasks()
{
Expand Down
51 changes: 0 additions & 51 deletions packages/framework/tests/Feature/Services/FileCacheServiceTest.php

This file was deleted.

122 changes: 122 additions & 0 deletions packages/framework/tests/Feature/Services/ViewDiffServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

namespace Hyde\Framework\Testing\Feature\Services;

use Hyde\Framework\Hyde;
use Hyde\Framework\Services\ViewDiffService;
use Hyde\Testing\TestCase;

/**
* @covers \Hyde\Framework\Services\ViewDiffService
*/
class ViewDiffServiceTest extends TestCase
{
public function test_get_filecache()
{
$fileCacheService = new ViewDiffService();
$fileCache = $fileCacheService->getFilecache();

$this->assertIsArray($fileCache);
$this->assertArrayHasKey('/resources/views/layouts/app.blade.php', $fileCache);
$this->assertArrayHasKey('unixsum', $fileCache['/resources/views/layouts/app.blade.php']);
$this->assertEquals(32, strlen($fileCache['/resources/views/layouts/app.blade.php']['unixsum']));
}

public function test_get_checksums()
{
$fileCacheService = new ViewDiffService();
$checksums = $fileCacheService->getChecksums();

$this->assertIsArray($checksums);
$this->assertEquals(32, strlen($checksums[0]));
}

public function test_checksum_matches_any()
{
$fileCacheService = new ViewDiffService();

$this->assertTrue($fileCacheService->checksumMatchesAny(ViewDiffService::unixsumFile(
Hyde::vendorPath('resources/views/layouts/app.blade.php'))
));
}

public function test_checksum_matches_any_false()
{
$fileCacheService = new ViewDiffService();

$this->assertFalse($fileCacheService->checksumMatchesAny(ViewDiffService::unixsum(
'foo'
)));
}

public function test_method_returns_string()
{
$this->assertIsString(ViewDiffService::unixsum('foo'));
}

public function test_method_returns_string_with_length_of_32()
{
$this->assertEquals(32, strlen(ViewDiffService::unixsum('foo')));
}

public function test_method_returns_string_matching_expected_format()
{
$this->assertMatchesRegularExpression('/^[a-f0-9]{32}$/', ViewDiffService::unixsum('foo'));
}

public function test_method_returns_same_value_for_same_string_using_normal_method()
{
$this->assertEquals(md5('foo'), ViewDiffService::unixsum('foo'));
}

public function test_method_returns_different_value_for_different_string()
{
$this->assertNotEquals(ViewDiffService::unixsum('foo'), ViewDiffService::unixsum('bar'));
}

public function test_function_is_case_sensitive()
{
$this->assertNotEquals(ViewDiffService::unixsum('foo'), ViewDiffService::unixsum('FOO'));
}

public function test_function_is_space_sensitive()
{
$this->assertNotEquals(ViewDiffService::unixsum(' foo '), ViewDiffService::unixsum('foo'));
}

public function test_method_returns_same_value_regardless_of_end_of_line_sequence()
{
$this->assertEquals(ViewDiffService::unixsum('foo'), ViewDiffService::unixsum('foo'));
$this->assertEquals(ViewDiffService::unixsum("foo\n"), ViewDiffService::unixsum("foo\n"));
$this->assertEquals(ViewDiffService::unixsum("foo\n"), ViewDiffService::unixsum("foo\r"));
$this->assertEquals(ViewDiffService::unixsum("foo\n"), ViewDiffService::unixsum("foo\r\n"));
}

public function test_method_returns_same_value_for_string_with_mixed_end_of_line_sequences()
{
$this->assertEquals(ViewDiffService::unixsum("foo\nbar\r\nbaz\r\n"),
ViewDiffService::unixsum("foo\nbar\nbaz\n"));
}

public function test_method_returns_same_value_when_loaded_from_file()
{
$string = "foo\nbar\r\nbaz\r\n";
$file = tempnam(sys_get_temp_dir(), 'foo');
file_put_contents($file, $string);

$this->assertEquals(ViewDiffService::unixsum($string), ViewDiffService::unixsum(file_get_contents($file)));

unlink($file);
}

public function test_method_returns_same_value_when_loaded_from_file_using_shorthand()
{
$string = "foo\nbar\r\nbaz\r\n";
$file = tempnam(sys_get_temp_dir(), 'foo');
file_put_contents($file, $string);

$this->assertEquals(ViewDiffService::unixsum($string), ViewDiffService::unixsumFile($file));

unlink($file);
}
}
2 changes: 1 addition & 1 deletion packages/framework/tests/Feature/StaticSiteServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Support\Facades\File;

/**
* @covers \Hyde\Framework\Commands\HydeBuildStaticSiteCommand
* @covers \Hyde\Framework\Commands\HydeBuildSiteCommand
* @covers \Hyde\Framework\Services\BuildService
*/
class StaticSiteServiceTest extends TestCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,3 @@
<?php

namespace Hyde\Framework\Testing\Unit;

use Hyde\Framework\Services\FileCacheService as Service;
use Hyde\Testing\TestCase;

class FileCacheServiceUnixsumMethodTest extends TestCase
{
public function test_method_returns_string()
{
$this->assertIsString(Service::unixsum('foo'));
}

public function test_method_returns_string_with_length_of_32()
{
$this->assertEquals(32, strlen(Service::unixsum('foo')));
}

public function test_method_returns_string_matching_expected_format()
{
$this->assertMatchesRegularExpression('/^[a-f0-9]{32}$/', Service::unixsum('foo'));
}

public function test_method_returns_same_value_for_same_string_using_normal_method()
{
$this->assertEquals(md5('foo'), Service::unixsum('foo'));
}

public function test_method_returns_different_value_for_different_string()
{
$this->assertNotEquals(Service::unixsum('foo'), Service::unixsum('bar'));
}

public function test_function_is_case_sensitive()
{
$this->assertNotEquals(Service::unixsum('foo'), Service::unixsum('FOO'));
}

public function test_function_is_space_sensitive()
{
$this->assertNotEquals(Service::unixsum(' foo '), Service::unixsum('foo'));
}

public function test_method_returns_same_value_regardless_of_end_of_line_sequence()
{
$this->assertEquals(Service::unixsum('foo'), Service::unixsum('foo'));
$this->assertEquals(Service::unixsum("foo\n"), Service::unixsum("foo\n"));
$this->assertEquals(Service::unixsum("foo\n"), Service::unixsum("foo\r"));
$this->assertEquals(Service::unixsum("foo\n"), Service::unixsum("foo\r\n"));
}

public function test_method_returns_same_value_for_string_with_mixed_end_of_line_sequences()
{
$this->assertEquals(Service::unixsum("foo\nbar\r\nbaz\r\n"),
Service::unixsum("foo\nbar\nbaz\n"));
}

public function test_method_returns_same_value_when_loaded_from_file()
{
$string = "foo\nbar\r\nbaz\r\n";
$file = tempnam(sys_get_temp_dir(), 'foo');
file_put_contents($file, $string);

$this->assertEquals(Service::unixsum($string), Service::unixsum(file_get_contents($file)));

unlink($file);
}

public function test_method_returns_same_value_when_loaded_from_file_using_shorthand()
{
$string = "foo\nbar\r\nbaz\r\n";
$file = tempnam(sys_get_temp_dir(), 'foo');
file_put_contents($file, $string);

$this->assertEquals(Service::unixsum($string), Service::unixsumFile($file));

unlink($file);
}
}

0 comments on commit 5c7f991

Please sign in to comment.